-
Notifications
You must be signed in to change notification settings - Fork 11
/
installermanager.pas
executable file
·2553 lines (2314 loc) · 82.6 KB
/
installermanager.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit installerManager;
{ Installer state machine
Copyright (C) 2012-2014 Ludo Brands, Reinier Olislagers
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
m_crossinstaller,
installerCore,
installerFpc,
{$ifndef FPCONLY}
installerLazarus,
{$endif}
installerHelp, installerUniversal,
fpcuputil
{$ifdef UNIX}
,dynlibs,Unix
{$endif UNIX}
;
// These sequences determine standard installation/uninstallation order/content:
// Note that a single os/cpu/sequence combination will only be executed once (the state machine checks for this)
Const
Sequences=
//default sequence. Using declare makes this show up in the module list given by fpcup --help
// If you don't want that, use DeclareHidden
_DECLARE+_DEFAULT+_SEP+ //keyword Declare gives a name to a sequence of commands
{$ifndef FPCONLY}
// CheckDevLibs has stubs for anything except Linux, where it does check development library presence
_EXECUTE+_CHECKDEVLIBS+_SEP+ //keyword Exec executes a function/procedure; must be defined in TSequencer.DoExec
{$endif}
_DO+_FPC+_SEP+ //keyword Do means run the specified declared sequence
{$ifndef FPCONLY}
_DO+_LAZARUS+_SEP+
_DO+_LCLCROSS+_SEP+
{$endif}
_END+ //keyword End specifies the end of the sequence
{$ifdef mswindows}
{$ifdef win32}
//default sequences for win32
_DECLARE+_DEFAULT+'win32'+_SEP+
{$endif win32}
{$ifdef win64}
_DECLARE+_DEFAULT+'win64'+_SEP+
{$endif win64}
_DO+_FPC+_SEP+
_DO+_FPC+_CROSSWIN+_SEP+
{$ifndef FPCONLY}
_DO+_LAZARUS+_SEP+
_DO+_LCLCROSS+_SEP+
_DO+_LAZARUS+_CROSSWIN+_SEP+
{$endif FPCONLY}
_END+
{$endif mswindows}
//default simple sequence: some packages give errors and memory is limited, so keep it simple
_DECLARE+_DEFAULTSIMPLE+_SEP+
{$ifndef FPCONLY}
_EXECUTE+_CHECKDEVLIBS+_SEP+
{$endif}
_DO+_FPC+_SEP+
{$ifndef FPCONLY}
_DO+_LAZARUSSIMPLE+_SEP+
{$endif}
_END+
//default clean sequence
_DECLARE+_DEFAULT+_CLEAN+_SEP+
_DO+_FPC+_CLEAN+_SEP+
{$ifndef FPCONLY}
_DO+_LAZARUS+_CLEAN+_SEP+
_DO+_HELPLAZARUS+_CLEAN+_SEP+
//_CLEANMODULE+'DOCEDITOR'+_SEP+
_DO+_UNIVERSALDEFAULT+_CLEAN+_SEP+
{$endif}
_END+
//default uninstall sequence
_DECLARE+_DEFAULT+_UNINSTALL+_SEP+
_DO+_FPC+_UNINSTALL+_SEP+
{$ifndef FPCONLY}
_DO+_LAZARUS+_UNINSTALL+_SEP+
_DO+_HELP+_UNINSTALL+_SEP+
//'UninstallModule DOCEDITOR'+_SEP+
_DO+_UNIVERSALDEFAULT+_UNINSTALL+_SEP+
{$endif}
_END+
//default uninstall sequence for win32
_DECLARE+_DEFAULT+'win32'+_UNINSTALL+_SEP+
_DO+_DEFAULT+_UNINSTALL+_SEP+
_END+
//default uninstall sequence for win64
_DECLARE+_DEFAULT+'win64'+_UNINSTALL+_SEP+
_DO+_DEFAULT+_UNINSTALL+_SEP+
_END+
//default install sequence for docker
_DECLARE+_DOCKER+_SEP+
_CLEANMODULE+_FPC+_SEP+
_CHECKMODULE+_FPC+_SEP+
_GETMODULE+_FPC+_SEP+
_BUILDMODULE+_FPC+_SEP+
{$ifndef FPCONLY}
_DO+_LAZBUILD+_ONLY+_SEP +
{$endif}
_END+
//default check sequence
_DECLARE+_DEFAULT+_CHECK+_SEP+
_CHECKMODULE+_FPC+_SEP+
{$ifndef FPCONLY}
_CHECKMODULE+_LAZARUS+_SEP+
{$endif}
_END+
_DECLARE+_CREATESCRIPT+_SEP+
_EXECUTE+_CREATEFPCUPSCRIPT+_SEP+
{$ifndef FPCONLY}
_EXECUTE+_CREATELAZARUSSCRIPT+_SEP+
{$endif}
_ENDFINAL;
type
TSequencer=class; //forward
TResultCodes=(rMissingCrossLibs,rMissingCrossBins);
TResultSet = Set of TResultCodes;
{ TFPCupManager }
TFPCupManager=class(TObject)
private
FHTTPProxyHost: string;
FHTTPProxyPassword: string;
FHTTPProxyPort: integer;
FHTTPProxyUser: string;
FPersistentOptions: string;
FBaseDirectory: string;
FCompilerOverride: string;
FBootstrapCompiler: string;
FBootstrapCompilerDirectory: string;
FClean: boolean;
FConfigFile: string;
{$ifndef FPCONLY}
FLCL_Platform: string; //really LCL widgetset
{$endif}
FCrossOPT: string;
FCrossCPU_Target: TCPU;
FCrossOS_Target: TOS;
FCrossOS_SubArch: TSUBARCH;
FFPCDesiredRevision: string;
FFPCSourceDirectory: string;
FFPCInstallDirectory: string;
FFPCOPT: string;
FFPCURL: string;
FFPCBranch: string;
FFPCTAG: string;
FIncludeModules: string;
FKeepLocalDiffs: boolean;
FUseSystemFPC: boolean;
{$ifndef FPCONLY}
FLazarusDesiredRevision: string;
FLazarusSourceDirectory: string;
FLazarusInstallDirectory: string;
FLazarusOPT: string;
FLazarusPrimaryConfigPath: string;
FLazarusURL: string;
FLazarusBranch: string;
FLazarusTAG: string;
{$endif}
FCrossToolsDirectory: string;
FCrossLibraryDirectory: string;
FMakeDirectory: string;
FOnlyModules: string;
FPatchCmd: string;
FReApplyLocalChanges: boolean;
{$ifndef FPCONLY}
FShortCutNameLazarus: string;
FContext: boolean;
{$endif}
FShortCutNameFpcup: string;
FSkipModules: string;
FFPCPatches:string;
FFPCPreInstallScriptPath:string;
FFPCPostInstallScriptPath:string;
{$ifndef FPCONLY}
FLazarusPatches:string;
FLazarusPreInstallScriptPath:string;
FLazarusPostInstallScriptPath:string;
{$endif}
FUninstall:boolean;
FVerbose: boolean;
FUseWget: boolean;
FExportOnly:boolean;
FNoJobs:boolean;
FSoftFloat:boolean;
FOnlinePatching:boolean;
FUseGitClient:boolean;
FSwitchURL:boolean;
FNativeFPCBootstrapCompiler:boolean;
FForceLocalRepoClient:boolean;
FSequencer: TSequencer;
FSolarisOI:boolean;
FMUSL:boolean;
FAutoTools:boolean;
FRunInfo:string;
procedure SetURL(ATarget,AValue: string);
procedure SetTAG(ATarget,AValue: string);
procedure SetBranch(ATarget,AValue: string);
function GetCrossCombo_Target:string;
{$ifndef FPCONLY}
function GetLazarusPrimaryConfigPath: string;
procedure SetLazarusSourceDirectory(AValue: string);
procedure SetLazarusInstallDirectory(AValue: string);
procedure SetLazarusURL(AValue: string);
procedure SetLazarusTAG(AValue: string);
procedure SetLazarusBranch(AValue: string);
{$endif}
function GetLogFileName: string;
procedure SetBaseDirectory(AValue: string);
procedure SetBootstrapCompilerDirectory(AValue: string);
procedure SetFPCSourceDirectory(AValue: string);
procedure SetFPCInstallDirectory(AValue: string);
procedure SetFPCURL(AValue: string);
procedure SetFPCTAG(AValue: string);
procedure SetFPCBranch(AValue: string);
procedure SetCrossToolsDirectory(AValue: string);
procedure SetCrossLibraryDirectory(AValue: string);
procedure SetLogFileName(AValue: string);
procedure SetMakeDirectory(AValue: string);
function GetTempDirectory:string;
function GetRunInfo:string;
procedure SetRunInfo(aValue:string);
procedure SetNoJobs(aValue:boolean);
protected
FShortcutCreated:boolean;
FLog:TLogger;
FModuleList:TStringList;
FModuleEnabledList:TStringList;
FModulePublishedList:TStringList;
// Write msg to log with line ending. Can also write to console
procedure WritelnLog(msg:string;ToConsole:boolean=true);overload;
procedure WritelnLog(EventType: TEventType;msg:string;ToConsole:boolean=true);overload;
public
property ShortcutCreated:boolean read FShortcutCreated;
property Sequencer: TSequencer read FSequencer;
{$ifndef FPCONLY}
property ShortCutNameLazarus: string read FShortCutNameLazarus write FShortCutNameLazarus; //Name of the shortcut that points to the fpcup-installed Lazarus
property Context: boolean read FContext write FContext; //Name of the shortcut that points to the fpcup-installed Lazarus
{$endif}
property ShortCutNameFpcup:string read FShortCutNameFpcup write FShortCutNameFpcup; //Name of the shortcut that points to fpcup
// Options that are to be saved in shortcuts/batch file/shell scripts.
// Excludes temporary options like --verbose
property PersistentOptions: string read FPersistentOptions write FPersistentOptions;
// Full path to bootstrap compiler
property BootstrapCompiler: string read FBootstrapCompiler write FBootstrapCompiler;
property BaseDirectory: string read FBaseDirectory write SetBaseDirectory;
// Directory where bootstrap compiler is installed/downloaded
property BootstrapCompilerDirectory: string read FBootstrapCompilerDirectory write SetBootstrapCompilerDirectory;
property TempDirectory: string read GetTempDirectory;
// Compiler override
property CompilerOverride: string read FCompilerOverride write FCompilerOverride;
property Clean: boolean read FClean write FClean;
property ConfigFile: string read FConfigFile write FConfigFile;
property CrossCPU_Target:TCPU read FCrossCPU_Target write FCrossCPU_Target;
property CrossOS_Target:TOS read FCrossOS_Target write FCrossOS_Target;
property CrossOS_SubArch:TSUBARCH read FCrossOS_SubArch write FCrossOS_SubArch;
property CrossCombo_Target:string read GetCrossCombo_Target;
// Widgetset for which the user wants to compile the LCL (not the IDE).
// Empty if default LCL widgetset used for current platform
{$ifndef FPCONLY}
property LCL_Platform:string read FLCL_Platform write FLCL_Platform;
{$endif}
property CrossOPT:string read FCrossOPT write FCrossOPT;
property CrossToolsDirectory:string read FCrossToolsDirectory write SetCrossToolsDirectory;
property CrossLibraryDirectory:string read FCrossLibraryDirectory write SetCrossLibraryDirectory;
property FPCSourceDirectory: string read FFPCSourceDirectory write SetFPCSourceDirectory;
property FPCInstallDirectory: string read FFPCInstallDirectory write SetFPCInstallDirectory;
property FPCURL: string read FFPCURL write SetFPCURL;
property FPCBranch: string read FFPCBranch write SetFPCBranch;
property FPCTAG: string read FFPCTAG write SetFPCTAG;
property FPCOPT: string read FFPCOPT write FFPCOPT;
property FPCDesiredRevision: string read FFPCDesiredRevision write FFPCDesiredRevision;
property HTTPProxyHost: string read FHTTPProxyHost write FHTTPProxyHost;
property HTTPProxyPassword: string read FHTTPProxyPassword write FHTTPProxyPassword;
property HTTPProxyPort: integer read FHTTPProxyPort write FHTTPProxyPort;
property HTTPProxyUser: string read FHTTPProxyUser write FHTTPProxyUser;
property KeepLocalChanges: boolean read FKeepLocalDiffs write FKeepLocalDiffs;
property UseSystemFPC:boolean read FUseSystemFPC write FUseSystemFPC;
{$ifndef FPCONLY}
property LazarusSourceDirectory: string read FLazarusSourceDirectory write SetLazarusSourceDirectory;
property LazarusInstallDirectory: string read FLazarusInstallDirectory write SetLazarusInstallDirectory;
property LazarusPrimaryConfigPath: string read GetLazarusPrimaryConfigPath write FLazarusPrimaryConfigPath ;
property LazarusURL: string read FLazarusURL write SetLazarusURL;
property LazarusBranch:string read FLazarusBranch write SetLazarusBranch;
property LazarusTAG: string read FLazarusTAG write SetLazarusTAG;
property LazarusOPT:string read FLazarusOPT write FLazarusOPT;
property LazarusDesiredRevision:string read FLazarusDesiredRevision write FLazarusDesiredRevision;
{$endif}
// Location where fpcup log will be written to.
property LogFileName: string read GetLogFileName write SetLogFileName;
// Directory where make is. Can be empty.
// On Windows, also a directory where the binutils can be found.
property MakeDirectory: string read FMakeDirectory write SetMakeDirectory;
// List of all default enabled sequences available
property ModuleEnabledList: TStringList read FModuleEnabledList;
// List of all publicly visible sequences
property ModulePublishedList: TStringList read FModulePublishedList;
// List of modules that must be processed in addition to the default ones
property IncludeModules:string read FIncludeModules write FIncludeModules;
// Patch utility to use. Defaults to '(g)patch'
property PatchCmd:string read FPatchCmd write FPatchCmd;
// Whether or not to back up locale changes to .diff and reapply them before compiling
property ReApplyLocalChanges: boolean read FReApplyLocalChanges write FReApplyLocalChanges;
// List of modules that must not be processed
property SkipModules:string read FSkipModules write FSkipModules;
property FPCPatches:string read FFPCPatches write FFPCPatches;
property FPCPreInstallScriptPath:string read FFPCPreInstallScriptPath write FFPCPreInstallScriptPath;
property FPCPostInstallScriptPath:string read FFPCPostInstallScriptPath write FFPCPostInstallScriptPath;
{$ifndef FPCONLY}
property LazarusPatches:string read FLazarusPatches write FLazarusPatches;
property LazarusPreInstallScriptPath:string read FLazarusPreInstallScriptPath write FLazarusPreInstallScriptPath;
property LazarusPostInstallScriptPath:string read FLazarusPostInstallScriptPath write FLazarusPostInstallScriptPath;
{$endif}
// Exhaustive/exclusive list of modules that must be processed; no other
// modules may be processed.
property OnlyModules:string read FOnlyModules write FOnlyModules;
property Uninstall: boolean read FUninstall write FUninstall;
property Verbose:boolean read FVerbose write FVerbose;
property UseWget:boolean read FUseWget write FUseWget;
property ExportOnly:boolean read FExportOnly write FExportOnly;
property NoJobs:boolean read FNoJobs write SetNoJobs;
property SoftFloat:boolean read FSoftFloat write FSoftFloat;
property OnlinePatching:boolean read FOnlinePatching write FOnlinePatching;
property UseGitClient:boolean read FUseGitClient write FUseGitClient;
property SwitchURL:boolean read FSwitchURL write FSwitchURL;
property NativeFPCBootstrapCompiler:boolean read FNativeFPCBootstrapCompiler write FNativeFPCBootstrapCompiler;
property ForceLocalRepoClient:boolean read FForceLocalRepoClient write FForceLocalRepoClient;
property SolarisOI:boolean read FSolarisOI write FSolarisOI;
property MUSL:boolean read FMUSL write FMUSL;
property AutoTools:boolean read FAutoTools write FAutoTools;
property RunInfo:string read GetRunInfo write SetRunInfo;
// Fill in ModulePublishedList and ModuleEnabledList and load other config elements
function LoadFPCUPConfig:boolean;
function CheckValidCPUOS(aCPU:TCPU=TCPU.cpuNone;aOS:TOS=TOS.osNone): boolean;
function ParseSubArchsFromSource: TStringList;
procedure GetCrossToolsFileName(out BinsFileName,LibsFileName:string);
procedure GetCrossToolsPath(out BinPath,LibPath:string);
function GetCrossBinsURL(out BaseBinsURL:string; var BinsFileName:string):boolean;
function GetCrossLibsURL(out BaseLibsURL:string; var LibsFileName:string):boolean;
// Stop talking. Do it! Returns success status
function Run: boolean;
constructor Create;
destructor Destroy; override;
end;
// Was this sequence already executed before? Which result?
TExecState=(ESNever,ESFailed,ESSucceeded);
TSequenceAttributes=record
EntryPoint:integer; //instead of rescanning the sequence table everytime, we can as well store the index in the table
Executed:TExecState; // Reset to ESNever at sequencer start up
end;
PSequenceAttributes=^TSequenceAttributes;
TKeyword=(SMdeclare, SMdeclareHidden, SMdo, SMrequire, SMexec, SMend, SMcleanmodule, SMgetmodule, SMbuildmodule,
SMcheckmodule, SMuninstallmodule, SMconfigmodule{$ifndef FPCONLY}, SMResetLCL{$endif}, SMSetOS, SMSetCPU, SMInvalid);
TState=record
instr:TKeyword;
param:string;
end;
{ TSequencer }
TSequencer=class(TObject)
private
FParent:TFPCupManager;
FInstaller:TInstaller; //current installer
property Installer:TInstaller read FInstaller;
protected
FCurrentModule:String;
FSkipList:TStringList;
FStateMachine:array of TState;
procedure AddToModuleList(ModuleName:string;EntryPoint:integer);
function DoCheckModule(ModuleName:string):boolean;
function DoBuildModule(ModuleName:string):boolean;
function DoCleanModule(ModuleName:string):boolean;
function DoConfigModule(ModuleName:string):boolean;
function DoExec(FunctionName:string):boolean;
function DoGetModule(ModuleName:string):boolean;
function DoSetCPU(aCPU:string):boolean;
function DoSetOS(aOS:string):boolean;
// Resets memory of executed steps so LCL widgetset can be rebuild
// e.g. using different platform
{$ifndef FPCONLY}
function DoResetLCL:boolean;
{$endif}
function DoUnInstallModule(ModuleName:string):boolean;
function GetInstaller(ModuleName:string):boolean;
function GetText:string;
function IsSkipped(ModuleName:string):boolean;
// Reset memory of executed steps, allowing sequences with e.g. new OS to be rerun
public
// set Executed to ESNever for all sequences
procedure ResetAllExecuted(SkipFPC:boolean=false);
// Text representation of sequence; for diagnostic purposes
property Text:String read GetText;
// parse a sequence source code and append to the FStateMachine
function AddSequence(Sequence:string):boolean;
// Add the "only" sequence from the FStateMachine based on the --only list
function CreateOnly(OnlyModules:string):boolean;
// deletes the "only" sequence from the FStateMachine
function DeleteOnly:boolean;
// run the FStateMachine starting at SequenceName
function Run(SequenceName:string):boolean;
// Force quit
function Kill: boolean;
constructor Create(aParent:TFPCupManager);
destructor Destroy; override;
end;
implementation
uses
{$IFNDEF FPCONLY}
{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION > 30000)}
InterfaceBase,
{$ENDIF}
{$ENDIF}
StrUtils,
fpjson,
processutils;
{ TFPCupManager }
{$ifndef FPCONLY}
function TFPCupManager.GetLazarusPrimaryConfigPath: string;
const
// This should be a last resort as FLazarusPrimaryConfigPath should be used really
DefaultPCPSubdir='lazarusdevsettings'; //Include the name lazarus for easy searching Caution: shouldn't be the same name as Lazarus dir itself.
begin
if FLazarusPrimaryConfigPath='' then
begin
{$IFDEF MSWINDOWS}
// Somewhere in local appdata special folder
FLazarusPrimaryConfigPath:=IncludeTrailingPathDelimiter(GetWindowsAppDataFolder)+DefaultPCPSubdir;
{$ELSE}
// Note: normal GetAppConfigDir gets ~/.config/fpcup/.lazarusdev or something
// XdgConfigHome normally resolves to something like ~/.config
// which is a reasonable default if we have no Lazarus primary config path set
FLazarusPrimaryConfigPath:=ExcludeTrailingPathDelimiter(XdgConfigHome)+DefaultPCPSubdir;
{$ENDIF MSWINDOWS}
end;
result:=FLazarusPrimaryConfigPath;
end;
{$endif}
function TFPCupManager.GetLogFileName: string;
begin
result:=FLog.LogFile;
end;
procedure TFPCupManager.SetBaseDirectory(AValue: string);
begin
FBaseDirectory:=SafeExpandFileName(AValue);
ForceDirectoriesSafe(FBaseDirectory);
end;
procedure TFPCupManager.SetBootstrapCompilerDirectory(AValue: string);
begin
FBootstrapCompilerDirectory:=ExcludeTrailingPathDelimiter(SafeExpandFileName(AValue));
end;
procedure TFPCupManager.SetFPCSourceDirectory(AValue: string);
begin
FFPCSourceDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.SetFPCInstallDirectory(AValue: string);
begin
FFPCInstallDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.SetURL(ATarget,AValue: string);
var
LocalURL:string;
URLLookupMagic:string;
begin
if ((ATarget<>_FPC) {$ifndef FPCONLY}AND (ATarget<>_LAZARUS){$endif}) then
begin
WritelnLog(etError,'Gitlab alias lookup of '+ATarget+' tag/branch/url error.');
exit;
end;
if (ATarget=_FPC) then
begin
LocalURL:=FFPCURL;
URLLookupMagic:=FPCURLLOOKUPMAGIC;
end;
{$ifndef FPCONLY}
if (ATarget=_LAZARUS) then
begin
LocalURL:=FLazarusURL;
URLLookupMagic:=LAZARUSURLLOOKUPMAGIC;
end;
{$endif}
if LocalURL=AValue then exit;
if (Pos('://',AValue)>0) then
LocalURL:=AValue
else
LocalURL:=installerUniversal.GetAlias(URLLookupMagic,AValue);
if (ATarget=_FPC) then FFPCURL:=LocalURL;
{$ifndef FPCONLY}
if (ATarget=_LAZARUS) then FLazarusURL:=LocalURL;
{$endif}
if ( (Length(LocalURL)=0) AND (Length(AValue)>0) ) then
begin
if (NOT AnsiEndsText(GITLABEXTENSION,AValue)) then
SetTAG(ATarget,AValue+GITLABEXTENSION)
else
SetTAG(ATarget,AValue);
end;
end;
procedure TFPCupManager.SetTAG(ATarget,AValue: string);
var
s:string;
LocalURL,LocalTag,LocalBranch:string;
RemoteURL,BranchLookupMagic,TagLookupMagic:string;
begin
if ((ATarget<>_FPC) {$ifndef FPCONLY}AND (ATarget<>_LAZARUS){$endif}) then
begin
WritelnLog(etError,'Gitlab alias lookup of '+ATarget+' tag/branch/url error.');
exit;
end;
if (ATarget=_FPC) then
begin
LocalTag:=FFPCTAG;
LocalBranch:=FFPCBranch;
LocalURL:=FFPCURL;
RemoteURL:=FPCGITLABREPO;
BranchLookupMagic:=FPCBRANCHLOOKUPMAGIC;
TagLookupMagic:=FPCTAGLOOKUPMAGIC;
end;
{$ifndef FPCONLY}
if (ATarget=_LAZARUS) then
begin
LocalTag:=FLazarusTAG;
LocalBranch:=FLazarusBranch;
LocalURL:=FLazarusURL;
RemoteURL:=LAZARUSGITLABREPO;
BranchLookupMagic:=LAZARUSBRANCHLOOKUPMAGIC;
TagLookupMagic:=LAZARUSTAGLOOKUPMAGIC;
end;
{$endif}
if AnsiEndsText(GITLABEXTENSION,AValue) then
begin
LocalURL:='';
s:=installerUniversal.GetAlias(TagLookupMagic,AValue);
if (Length(s)>0) then
begin
LocalTag:=s;
LocalBranch:='';
end
else
begin
s:=installerUniversal.GetAlias(BranchLookupMagic,AValue);
if (Length(s)>0) then
begin
LocalTag:='';
if AnsiContainsText(s,'gitlab.com/') then
begin
LocalURL:=s;
LocalBranch:='';
end
else
LocalBranch:=s;
end;
end;
if (Length(s)>0) then
begin
if (Length(LocalURL)=0) then
LocalURL:=RemoteURL;
end
else
WritelnLog(etError,'Gitlab alias lookup of '+ATarget+' tag/branch/url failed. Expect errors.');
end
else
begin
LocalTag:=aValue;
LocalBranch:='';
end;
if (ATarget=_FPC) then
begin
FFPCTAG:=LocalTag;
FFPCBranch:=LocalBranch;
FFPCURL:=LocalURL;
end;
{$ifndef FPCONLY}
if (ATarget=_LAZARUS) then
begin
FLazarusTAG:=LocalTag;
FLazarusBranch:=LocalBranch;
FLazarusURL:=LocalURL;
end;
{$endif}
end;
procedure TFPCupManager.SetBranch(ATarget,AValue: string);
var
s:string;
LocalURL,LocalTag,LocalBranch:string;
RemoteURL,BranchLookupMagic:string;
begin
if ((ATarget<>_FPC) {$ifndef FPCONLY}AND (ATarget<>_LAZARUS){$endif}) then
begin
WritelnLog(etError,'Gitlab alias lookup of '+ATarget+' tag/branch/url error.');
exit;
end;
if (ATarget=_FPC) then
begin
LocalTag:=FFPCTAG;
LocalBranch:=FFPCBranch;
LocalURL:=FFPCURL;
RemoteURL:=FPCGITLABREPO;
BranchLookupMagic:=FPCBRANCHLOOKUPMAGIC;
end;
{$ifndef FPCONLY}
if (ATarget=_LAZARUS) then
begin
LocalTag:=FLazarusTAG;
LocalBranch:=FLazarusBranch;
LocalURL:=FLazarusURL;
RemoteURL:=LAZARUSGITLABREPO;
BranchLookupMagic:=LAZARUSBRANCHLOOKUPMAGIC;
end;
{$endif}
if AnsiEndsText(GITLABEXTENSION,AValue) then
begin
s:=installerUniversal.GetAlias(BranchLookupMagic,AValue);
if (Length(s)>0) then
begin
LocalTag:='';
LocalBranch:=s;
LocalURL:=RemoteURL;
end
else
begin
WritelnLog(etError,'Gitlab alias lookup of '+ATarget+' branch failed. Expect errors.');
end;
end
else
begin
LocalBranch:=aValue;
LocalTag:='';
end;
if (ATarget=_FPC) then
begin
FFPCTAG:=LocalTag;
FFPCBranch:=LocalBranch;
FFPCURL:=LocalURL;
end;
{$ifndef FPCONLY}
if (ATarget=_LAZARUS) then
begin
FLazarusTAG:=LocalTag;
FLazarusBranch:=LocalBranch;
FLazarusURL:=LocalURL;
end;
{$endif}
end;
procedure TFPCupManager.SetFPCURL(AValue: string);
begin
SetURL(_FPC,AValue);
end;
procedure TFPCupManager.SetFPCTAG(AValue: string);
begin
SetTAG(_FPC,AValue);
end;
procedure TFPCupManager.SetFPCBranch(AValue: string);
begin
SetBranch(_FPC,AValue);
end;
procedure TFPCupManager.SetCrossToolsDirectory(AValue: string);
begin
//FCrossToolsDirectory:=SafeExpandFileName(AValue);
FCrossToolsDirectory:=AValue;
end;
procedure TFPCupManager.SetCrossLibraryDirectory(AValue: string);
begin
//FCrossLibraryDirectory:=SafeExpandFileName(AValue);
FCrossLibraryDirectory:=AValue;
end;
{$ifndef FPCONLY}
procedure TFPCupManager.SetLazarusSourceDirectory(AValue: string);
begin
FLazarusSourceDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.SetLazarusInstallDirectory(AValue: string);
begin
FLazarusInstallDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.SetLazarusURL(AValue: string);
begin
SetURL(_LAZARUS,AValue);
end;
procedure TFPCupManager.SetLazarusTAG(AValue: string);
begin
SetTAG(_LAZARUS,AValue);
end;
procedure TFPCupManager.SetLazarusBranch(AValue: string);
begin
SetBranch(_LAZARUS,AValue);
end;
{$endif}
procedure TFPCupManager.SetLogFileName(AValue: string);
begin
// Don't change existing log file
if (AValue<>'') and (FLog.LogFile=AValue) then Exit;
// Defaults if empty value specified
if AValue='' then
begin
{$IFDEF MSWINDOWS}
FLog.LogFile:=SafeGetApplicationPath+'fpcup.log'; //exe directory
{$ELSE}
FLog.LogFile:=SafeExpandFileName('~')+DirectorySeparator+'fpcup.log'; //home directory
{$ENDIF MSWINDOWS}
end
else
begin
FLog.LogFile:=AValue;
end;
end;
procedure TFPCupManager.SetMakeDirectory(AValue: string);
begin
FMakeDirectory:=SafeExpandFileName(AValue);
end;
function TFPCupManager.GetTempDirectory:string;
begin
if DirectoryExists(FBaseDirectory) then
begin
result:=ConcatPaths([FBaseDirectory,'tmp']);
ForceDirectoriesSafe(result);
end;
end;
procedure TFPCupManager.WritelnLog(msg: string; ToConsole: boolean);
begin
// Set up log if it doesn't exist yet
FLog.WriteLog(msg);
if ToConsole then
begin
if Assigned(Sequencer.Installer) then
Sequencer.Installer.Infoln(msg)
else
ThreadLog(msg);
end;
end;
procedure TFPCupManager.WritelnLog(EventType: TEventType; msg: string; ToConsole: boolean);
begin
// Set up log if it doesn't exist yet
FLog.WriteLog(EventType,msg);
if ToConsole then
begin
if Assigned(Sequencer.Installer) then
Sequencer.Installer.Infoln(msg,EventType)
else
ThreadLog(msg,EventType);
end;
end;
function TFPCupManager.LoadFPCUPConfig: boolean;
begin
installerUniversal.SetConfigFile(FConfigFile);
FSequencer.AddSequence(Sequences);
FSequencer.AddSequence(installerFPC.Sequences);
{$ifndef FPCONLY}
FSequencer.AddSequence(installerLazarus.Sequences);
{$endif}
FSequencer.AddSequence(installerHelp.Sequences);
FSequencer.AddSequence(installerUniversal.Sequences);
// append universal modules to the lists
FSequencer.AddSequence(installerUniversal.GetModuleList);
result:=installerUniversal.GetModuleEnabledList(FModuleEnabledList);
end;
function TFPCupManager.CheckValidCPUOS(aCPU:TCPU;aOS:TOS): boolean;
var
s : string;
x : integer;
sl : TStringList;
aLocalCPU : TCPU;
aLocalOS : TOS;
begin
result:=false;
aLocalCPU:=aCPU;
if aLocalCPU=TCPU.cpuNone then aLocalCPU:=CrossCPU_Target;
aLocalOS:=aOS;
if aLocalOS=TOS.osNone then aLocalOS:=CrossOS_Target;
if ((aLocalCPU=TCPU.cpuNone) OR (aLocalOS=TOS.osNone)) then exit;
//parsing systems.inc or .pas for valid CPU / OS system
s:=ConcatPaths([FPCSourceDirectory,'compiler'])+DirectorySeparator+'systems.inc';
if (NOT FileExists(s)) then s:=ConcatPaths([FPCSourceDirectory,'compiler'])+DirectorySeparator+'systems.pas';
if FileExists(s) then
begin
sl:=TStringList.Create;
try
sl.LoadFromFile(s);
s:='system_'+GetCPU(aLocalCPU)+'_'+GetOS(aLocalOS);
x:=StringListContains(sl,s);
if (x<>-1) then
begin
s:=sl[x];
if (Pos('obsolete_',s)=0) then result:=true;
end;
finally
sl.Free;
end;
end;
end;
function TFPCupManager.ParseSubArchsFromSource: TStringList;
const
REQ1='ifeq ($(ARCH),';
REQ2='ifeq ($(SUBARCH),';
var
TxtFile:Text;
s,arch,subarch:string;
x:integer;
begin
Result := TStringList.Create;
Result.Sorted := True;
Result.Duplicates := dupIgnore;
s:=IncludeTrailingPathDelimiter(FPCSourceDirectory)+'rtl'+DirectorySeparator+GetOS(CrossOS_Target)+DirectorySeparator+FPCMAKEFILENAME;
if FileExists(s) then
begin
AssignFile(TxtFile,s);
Reset(TxtFile);
while NOT EOF (TxtFile) do
begin
Readln(TxtFile,s);
x:=Pos(REQ1,s);
if x=1 then
begin
arch:=s;
Delete(arch,1,x+Length(REQ1)-1);
x:=Pos(')',arch);
if x>0 then
begin
Delete(arch,x,MaxInt);
end;
end;
if Length(arch)>0 then
begin
x:=Pos(REQ2,s);
if x=1 then
begin
subarch:=s;
Delete(subarch,1,x+Length(REQ2)-1);
x:=Pos(')',subarch);
if x>0 then
begin
Delete(subarch,x,MaxInt);
if Length(subarch)>0 then with Result {%H-}do Add(Concat(arch, NameValueSeparator, subarch));
end;
end;
end;
end;
CloseFile(TxtFile);
end;
end;
procedure TFPCupManager.GetCrossToolsFileName(out BinsFileName,LibsFileName:string);
var
s:string;
begin
// Setting the CPU part of the name[s] for the file to download
if CrossCPU_Target=TCPU.arm then s:='ARM' else
if CrossCPU_Target=TCPU.i386 then s:='i386' else
if CrossCPU_Target=TCPU.x86_64 then s:='x64' else
if CrossCPU_Target=TCPU.powerpc then s:='PowerPC' else
if CrossCPU_Target=TCPU.powerpc64 then s:='PowerPC64' else
if CrossCPU_Target=TCPU.avr then s:='AVR' else
if CrossCPU_Target=TCPU.m68k then s:='m68k' else
s:=UppercaseFirstChar(GetCPU(CrossCPU_Target));
BinsFileName:=s;
// Set special CPU names
if CrossOS_Target=TOS.darwin then
begin
// Darwin has some universal binaries and libs
if CrossCPU_Target=TCPU.i386 then BinsFileName:='All';
if CrossCPU_Target=TCPU.x86_64 then BinsFileName:='All';
if CrossCPU_Target=TCPU.aarch64 then BinsFileName:='All';
if CrossCPU_Target=TCPU.powerpc then BinsFileName:='PowerPC';
if CrossCPU_Target=TCPU.powerpc64 then BinsFileName:='PowerPC';
end;
if CrossOS_Target=TOS.ios then
begin
// iOS has some universal binaries and libs
if CrossCPU_Target=TCPU.arm then BinsFileName:='All';
if CrossCPU_Target=TCPU.aarch64 then BinsFileName:='All';
end;
if CrossOS_Target=TOS.aix then
begin
// AIX has some universal binaries
if CrossCPU_Target=TCPU.powerpc then BinsFileName:='PowerPC';
if CrossCPU_Target=TCPU.powerpc64 then BinsFileName:='PowerPC';
end;
// Set OS case
if CrossOS_Target=TOS.morphos then s:='MorphOS' else
if CrossOS_Target=TOS.freebsd then s:='FreeBSD' else
if CrossOS_Target=TOS.dragonfly then s:='DragonFlyBSD' else
if CrossOS_Target=TOS.openbsd then s:='OpenBSD' else
if CrossOS_Target=TOS.netbsd then s:='NetBSD' else
if CrossOS_Target=TOS.aix then s:='AIX' else
if CrossOS_Target=TOS.msdos then s:='MSDos' else
if CrossOS_Target=TOS.freertos then s:='FreeRTOS' else
if CrossOS_Target=TOS.win32 then s:='Windows' else
if CrossOS_Target=TOS.win64 then s:='Windows' else
if CrossOS_Target=TOS.ios then s:='IOS' else