-
Notifications
You must be signed in to change notification settings - Fork 4
/
installermanager.pas
executable file
·1271 lines (1178 loc) · 45.9 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+}
{Define NOCONSOLE e.g. if using Windows GUI {$APPTYPE GUI} or -WG
this will disable writeln calls
}
{not $DEFINE NOCONSOLE}
interface
uses
Classes, SysUtils,installerCore,installerFpc,installerLazarus,installerHelp,installerUniversal,fpcuputil,fileutil
{$ifdef linux}
,dynlibs
{$endif linux}
;
// Get revision from our source code repository:
// If you have a file not found error for revision.inc, please make sure you compile hgversion.pas before compiling this project.
{$i revision.inc}
//Contains RevisionStr and versiondate constants
// 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;'+ //keyword Declare gives a name to a sequence of commands
// CheckDevLibs has stubs for anything except Linux, where it does check development library presence
'Exec CheckDevLibs;'+ //keyword Exec executes a function/procedure; must be defined in TSequencer.DoExec
'Do fpc;'+ //keyword Do means run the specified declared sequence
// Lazbuild: make sure we can at least compile LCL programs
'Do lazbuild;'+
'Do helplazarus;'+
'Do LAZDATADESKTOP;'+
'Do DOCEDITOR;'+
//Get default external packages/universal modules
'Do UniversalDefault;'+
//Recompile user IDE so any packages selected by the
//universal installer are compiled into the IDE:
'Do USERIDE;'+
//Any cross compilation; must be at end because it resets state machine run memory
'Do LCLCross;'+
'End;'+ //keyword End specifies the end of the sequence
//default sequence for win32
'Declare defaultwin32;'+
'Exec CheckDevLibs;'+ //keyword Exec executes a function/procedure; must be defined in TSequencer.DoExec
'Do fpc;'+
// Lazbuild: make sure we can at least compile LCL programs
'Do lazbuild;'+
'Do helplazarus;'+
'Do LAZDATADESKTOP;'+
'Do DOCEDITOR;'+
// Get default external packages/universal modules
'Do UniversalDefault;'+
// Recompile user IDE so any packages selected by the
// universal installer are compiled into the IDE:
'Do USERIDE;'+
{$ifdef mswindows} //not really necessary as crosswin checks arechitecture anyway
'Do crosswin32-64;'+ //this has to be the last. All TExecState reset!
{$endif}
// Any further cross compilation; must be at end because it resets state machine run memory
'Do LCLCross;'+
'End;'+
//cross sequence for win32. Note: if changing this name,
//also change checks for this in skipmodules etc.
'Declare crosswin32-64;'+
'Do FPCCrossWin32-64;'+
'Do LazarusCrossWin32-64;'+
'End;'+
//default sequence for win64
{todo: win64 sequence currently not enabled; see
$elseif defined(win64)
below}
'Declare defaultwin64;'+
// CheckDevLibs has stubs for anything except Linux, where it does check development library presence
'Exec CheckDevLibs;'+
'Do fpc;'+
// Lazbuild: make sure we can at least compile LCL programs
'Do lazbuild;'+
'Do helplazarus;'+
'Do LAZDATADESKTOP;'+
'Do DOCEDITOR;'+
//Get default external packages/universal modules
'Do UniversalDefault;'+
//Recompile user IDE so any packages selected by the
//universal installer are compiled into the IDE:
'Do USERIDE;'+
'Do crosswin64-32;'+ //this has to be the last. All TExecState reset!
//Any cross compilation; must be at end because it resets state machine run memory
'Do LCLCross;'+
'End;'+
//cross sequence for win32. Note: if changing this name,
//also change checks for this in skipmodules etc.
'Declare crosswin64-32;'+
'SetCPU i386;'+
'SetOS win32;'+
//Getmodule has already been done
'Cleanmodule fpc;'+
'Buildmodule fpc;'+
//Getmodule has already been done
// Don't use cleanmodule; make distclean will remove lazbuild.exe etc
//'Cleanmodule LCL;'+
'Buildmodule LCL;'+
'End;'+
//default clean sequence
'Declare defaultclean;'+
'Do fpcclean;'+
'Do lazarusclean;'+
'Do helplazarusclean;'+
'CleanModule LAZDATADESKTOP;'+
'CleanModule DOCEDITOR;'+
'Do UniversalDefaultClean;'+
'End;'+
{
// Currently, make distclean LCL removes lazbuild.exe/lazarus.exe as well
// Then, universal installer won't work because of missing lazbuild, and of
// course Lazarus won't work either.
// Workaround: don't clean up.
//default clean sequence for win32
'Declare defaultwin32clean;'+
'Do fpcclean;'+
'Do lazarusclean;'+
'Do helplazarusclean;'+
'CleanModule LAZDATADESKTOP;'+
'CleanModule DOCEDITOR;'+
'Do UniversalDefaultClean;'+
'Do crosswin32-64Clean;'+ //this has to be the last. All TExecState reset!
'End;'+
//default cross clean sequence for win32
'Declare crosswin32-64Clean;'+
'SetCPU x86_64;'+
'SetOS win64;'+
'Cleanmodule fpc;'+
'Cleanmodule lazarus;'+
'End;'+
//default cross clean sequence for win64
'Declare crosswin64-32Clean;'+
'SetCPU i386;'+
'SetOS win32;'+
'Cleanmodule fpc;'+
'Cleanmodule lazarus;'+
'End;'+
}
//default uninstall sequence
'Declare defaultuninstall;'+
'Do fpcuninstall;'+
'Do lazarusuninstall;'+
'Do helpuninstall;'+
'UninstallModule LAZDATADESKTOP;'+
'UninstallModule DOCEDITOR;'+
'Do UniversalDefaultUnInstall;'+
'End;'+
//default uninstall sequence for win32
'Declare defaultwin32uninstall;'+
'Do defaultuninstall;'+
'End;'+
//default uninstall sequence for win64
'Declare defaultwin64uninstall;'+
'Do defaultuninstall;'+
'End;';
type
TSequencer=class; //forward
{ TFPCupManager }
TFPCupManager=class(Tobject)
private
FSVNExecutable: string;
FHTTPProxyHost: string;
FHTTPProxyPassword: string;
FHTTPProxyPort: integer;
FHTTPProxyUser: string;
FPersistentOptions: string;
FBootstrapCompiler: string;
FBootstrapCompilerDirectory: string;
FBootstrapCompilerURL: string;
FClean: boolean;
FCompilerName: string;
FConfigFile: string;
FCrossCPU_Target: string;
FCrossLCL_Platform: string; //really LCL widgetset
FCrossOPT: string;
FCrossOS_Target: string;
FFPCDesiredRevision: string;
FFPCDirectory: string;
FFPCOPT: string;
FFPCURL: string;
FIncludeModules: string;
FKeepLocalDiffs: boolean;
FLazarusDesiredRevision: string;
FLazarusDirectory: string;
FLazarusOPT: string;
FLazarusPrimaryConfigPath: string;
FLazarusURL: string;
FMakeDirectory: string;
FOnlyModules: string;
FPatchCmd: string;
FReApplyLocalChanges: boolean;
FShortCutNameLazarus: string;
FShortCutNameFpcup: string;
FSkipModules: string;
FUninstall:boolean;
FVerbose: boolean;
FSequencer: TSequencer;
function GetLazarusPrimaryConfigPath: string;
function GetLogFileName: string;
procedure SetBootstrapCompilerDirectory(AValue: string);
procedure SetFPCDirectory(AValue: string);
procedure SetFPCURL(AValue: string);
procedure SetLazarusDirectory(AValue: string);
procedure SetLazarusURL(AValue: string);
procedure SetLogFileName(AValue: string);
procedure SetMakeDirectory(AValue: string);
protected
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);
public
property ShortCutNameLazarus: string read FShortCutNameLazarus write FShortCutNameLazarus; //Name of the shortcut that points to the fpcup-installed Lazarus
property ShortCutNameFpcup:string read FShortCutNameFpcup write FShortCutNameFpcup; //Name of the shortcut that points to fpcup
// Full path+filename of SVN executable. Use empty to search for default locations.
property SVNExecutable: string read FSVNExecutable write FSVNExecutable;
property CompilerName: string read FCompilerName write FCompilerName;
// 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;
// Directory where bootstrap compiler is installed/downloaded
property BootstrapCompilerDirectory: string read FBootstrapCompilerDirectory write SetBootstrapCompilerDirectory;
// URL to download the bootstrap compiler from
property BootstrapCompilerURL: string read FBootstrapCompilerURL write FBootstrapCompilerURL;
property Clean: boolean read FClean write FClean;
property ConfigFile: string read FConfigFile write FConfigFile;
property CrossCPU_Target:string read FCrossCPU_Target write FCrossCPU_Target;
// Widgetset for which the user wants to compile the LCL (not the IDE).
// Empty if default LCL widgetset used for current platform
property CrossLCL_Platform:string read FCrossLCL_Platform write FCrossLCL_Platform;
property CrossOPT:string read FCrossOPT write FCrossOPT;
property CrossOS_Target:string read FCrossOS_Target write FCrossOS_Target;
property FPCDirectory: string read FFPCDirectory write SetFPCDirectory;
property FPCURL: string read FFPCURL write SetFPCURL;
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 LazarusDirectory: string read FLazarusDirectory write SetLazarusDirectory;
property LazarusPrimaryConfigPath: string read GetLazarusPrimaryConfigPath write FLazarusPrimaryConfigPath ;
property LazarusURL: string read FLazarusURL write SetLazarusURL;
property LazarusOPT:string read FLazarusOPT write FLazarusOPT;
property LazarusDesiredRevision:string read FLazarusDesiredRevision write FLazarusDesiredRevision;
// 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 'patch -p0 -i patchfile'
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;
// 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;
// Fill in ModulePublishedList and ModuleEnabledList and load other config elements
function LoadFPCUPConfig: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,
SMuninstallmodule, SMconfigmodule, SMResetLCL, SMSetOS, SMSetCPU, SMInvalid);
TState=record
instr:TKeyword;
param:string;
end;
{ TSequencer }
TSequencer=class(TObject)
protected
FParent:TFPCupManager;
FCurrentModule:String;
FInstaller:TInstaller; //current installer
FSkipList:TStringList;
FStateMachine:array of TState;
procedure AddToModuleList(ModuleName:string;EntryPoint:integer);
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(CPU:string):boolean;
function DoSetOS(OS:string):boolean;
// Resets memory of executed steps so LCL widgetset can be rebuild
// e.g. using different platform
function DoResetLCL:boolean;
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
procedure ResetAllExecuted(SkipFPC:boolean=false);
public
property Parent:TFPCupManager write Fparent;
// 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;
constructor Create;
destructor Destroy; override;
end;
implementation
{ TFPCupManager }
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:=ExcludeTrailingPathDelimiter(GetLocalAppDataPath())+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;
function TFPCupManager.GetLogFileName: string;
begin
result:=FLog.LogFile;
end;
procedure TFPCupManager.SetBootstrapCompilerDirectory(AValue: string);
begin
FBootstrapCompilerDirectory:=ExcludeTrailingPathDelimiter(SafeExpandFileName(AValue));
end;
procedure TFPCupManager.SetFPCDirectory(AValue: string);
begin
FFPCDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.SetFPCURL(AValue: string);
begin
if FFPCURL=AValue then Exit;
if pos('//',AValue)>0 then
FFPCURL:=AValue
else
FFPCURL:=installerUniversal.GetAlias(FConfigFile,'fpcURL',AValue);
end;
procedure TFPCupManager.SetLazarusDirectory(AValue: string);
begin
FLazarusDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.SetLazarusURL(AValue: string);
begin
if FLazarusURL=AValue then Exit;
if pos('//',AValue)>0 then
FLazarusURL:=AValue
else
FLazarusURL:=installerUniversal.GetAlias(FConfigFile,'lazURL',AValue);
end;
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:='fpcup.log'; //current directory
{$ELSE}
FLog.LogFile:=SafeExpandFileNameUTF8('~')+DirectorySeparator+'fpcup.log'; //In home directory
{$ENDIF MSWINDOWS}
end
else
begin
FLog.LogFile:=AValue;
end;
end;
procedure TFPCupManager.SetMakeDirectory(AValue: string);
begin
FMakeDirectory:=SafeExpandFileName(AValue);
end;
procedure TFPCupManager.WritelnLog(msg: string; ToConsole: boolean);
begin
// Set up log if it doesn't exist yet
FLog.WriteLog(msg,ToConsole);
end;
function TFPCupManager.LoadFPCUPConfig: boolean;
begin
FSequencer.AddSequence(Sequences);
FSequencer.AddSequence(installerFPC.Sequences);
FSequencer.AddSequence(installerLazarus.Sequences);
FSequencer.AddSequence(installerHelp.Sequences);
FSequencer.AddSequence(installerUniversal.Sequences);
// append universal modules to the lists
FSequencer.AddSequence(installerUniversal.GetModuleList(FConfigFile));
result:=installerUniversal.GetModuleEnabledList(FModuleEnabledList);
end;
function TFPCupManager.Run: boolean;
{$IFDEF MSWINDOWS}
var
Major:integer=0;
Minor:integer=0;
Build:integer=0;
{$ENDIF}
begin
result:=false;
try
WritelnLog(DateTimeToStr(now)+': fpcup '+RevisionStr+' ('+VersionDate+') started.',true);
except
// Writing to log failed, probably duplicate run. Inform user and get out.
{$IFNDEF NOCONSOLE}
writeln('***ERROR***');
writeln('Could not open log file '+FLog.LogFile+' for writing.');
writeln('Perhaps another fpcup is running?');
writeln('Aborting.');
{$ENDIF}
halt(2);
end;
infoln('InstallerManager: current sequence: '+LineEnding+
FSequencer.Text,etDebug);
// Some diagnostic info
{$IFDEF MSWINDOWS}
if Verbose then
if GetWin32Version(Major,Minor,Build) then
begin
infoln('Windows major version: '+inttostr(Major),etInfo);
infoln('Windows minor version: '+inttostr(Minor),etInfo);
infoln('Windows build number: '+inttostr(Build),etInfo);
end
else
infoln('Could not retrieve Windows version using GetWin32Version.',etWarning);
{$ENDIF}
if SkipModules<>'' then begin
FSequencer.FSkipList:=TStringList.Create;
FSequencer.FSkipList.Delimiter:=',';
FSequencer.FSkipList.DelimitedText:=SkipModules;
end;
if FOnlyModules<>'' then begin
FSequencer.CreateOnly(FOnlyModules);
result:=FSequencer.Run('Only');
FSequencer.DeleteOnly;
end
else begin
{$if defined(win32)}
// Run Windows specific cross compiler or regular version
if pos('CROSSWIN32-64',UpperCase(SkipModules))>0 then begin
infoln('InstallerManager: going to run sequencer for sequence: Default.',etDebug);
result:=FSequencer.Run('Default');
end
else begin
infoln('InstallerManager: going to run sequencer for sequence: DefaultWin32.',etDebug);
result:=FSequencer.Run('DefaultWin32');
end;
// We would like to have a win64=>win32 crosscompiler, but at least with current
// FPC trunk that won't work due to errors like
// fpcdefs.inc(216,2) Error: User defined: Cross-compiling from systems
// without support for an 80 bit extended floating point type to i386 is
// not yet supported at this time. If it is, uncomment until the else conditional:
//{$elseif defined(win64)}
{
if pos('CROSSWIN64-32',UpperCase(SkipModules))>0 then
result:=FSequencer.Run('Default')
else
result:=FSequencer.Run('DefaultWin64');
}
{$else}
// Linux, OSX
infoln('InstallerManager: going to run sequencer for sequence Default.',etDebug);
result:=FSequencer.Run('Default');
{$endif}
if (FIncludeModules<>'') and (result) then begin
// run specified additional modules using the only mechanism
infoln('InstallerManager: going to run sequencer for include modules '+FIncludeModules,etDebug);
FSequencer.CreateOnly(FIncludeModules);
result:=FSequencer.Run('Only');
FSequencer.DeleteOnly;
end;
end;
if assigned(FSequencer.FSkipList) then
FSequencer.FSkipList.Free;
end;
constructor TFPCupManager.Create;
begin
FModuleList:=TStringList.Create;
FModuleEnabledList:=TStringList.Create;
FModulePublishedList:=TStringList.Create;
FSequencer:=TSequencer.create;
FSequencer.Parent:=Self;
FLog:=TLogger.Create;
// Log filename will be set on first log write
end;
destructor TFPCupManager.Destroy;
var i:integer;
begin
for i:=0 to FModuleList.Count-1 do
Freemem(FModuleList.Objects[i]);
FModuleList.Free;
FModulePublishedList.Free;
FModuleEnabledList.Free;
FSequencer.free;
try
WritelnLog(DateTimeToStr(now)+': fpcup finished.',true);
WritelnLog('------------------------------------------------',false);
finally
//ignore logging errors
end;
FLog.Free;
inherited Destroy;
end;
{ TSequencer }
procedure TSequencer.AddToModuleList(ModuleName: string; EntryPoint: integer);
var
SeqAttr:PSequenceAttributes;
begin
getmem(SeqAttr,sizeof(TSequenceAttributes));
SeqAttr^.EntryPoint:=EntryPoint;
SeqAttr^.Executed:=ESNever;
FParent.FModuleList.AddObject(ModuleName,TObject(SeqAttr));
end;
function TSequencer.DoBuildModule(ModuleName: string): boolean;
begin
infoln('TSequencer: DoBuildModule for module '+ModuleName+' called.',etDebug);
result:= GetInstaller(ModuleName) and FInstaller.BuildModule(ModuleName);
end;
function TSequencer.DoCleanModule(ModuleName: string): boolean;
begin
infoln('TSequencer: DoCleanModule for module '+ModuleName+' called.',etDebug);
result:= GetInstaller(ModuleName) and FInstaller.CleanModule(ModuleName);
end;
function TSequencer.DoConfigModule(ModuleName: string): boolean;
begin
infoln('TSequencer: DoConfigModule for module '+ModuleName+' called.',etDebug);
result:= GetInstaller(ModuleName) and FInstaller.ConfigModule(ModuleName);
end;
function TSequencer.DoExec(FunctionName: string): boolean;
function CreateFpcupScript:boolean;
begin
result:=true;
// Link to fpcup itself, with all options as passed when invoking it:
if FParent.ShortCutNameFpcup<>EmptyStr then
begin
{$IFDEF MSWINDOWS}
CreateDesktopShortCut(paramstr(0),FParent.PersistentOptions,FParent.ShortCutNameFpcup);
{$ELSE}
FParent.PersistentOptions:=FParent.PersistentOptions+' $*';
CreateHomeStartLink('"'+paramstr(0)+'"',FParent.PersistentOptions,FParent.ShortCutNameFpcup);
{$ENDIF MSWINDOWS}
end;
end;
function CreateLazarusScript:boolean;
// Find out InstalledLazarus location, create desktop shortcuts etc
// Don't use this function when lazarus is not installed.
var
InstalledLazarus:string;
begin
result:=true;
if FParent.ShortCutNameLazarus<>EmptyStr then
begin
infoln('Lazarus: creating desktop shortcut:',etInfo);
try
// Create shortcut; we don't care very much if it fails=>don't mess with OperationSucceeded
InstalledLazarus:=IncludeTrailingPathDelimiter(FParent.LazarusDirectory)+'lazarus'+GetExeExt;
{$IFDEF MSWINDOWS}
CreateDesktopShortCut(InstalledLazarus,'--pcp="'+FParent.LazarusPrimaryConfigPath+'"',FParent.ShortCutNameLazarus);
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
{$IFDEF DARWIN}
CreateHomeStartLink(InstalledLazarus+'.app/Contents/MacOS/lazarus','--pcp="'+FParent.LazarusPrimaryConfigPath+'"',FParent.ShortcutNameLazarus);
{$ELSE}
CreateHomeStartLink(InstalledLazarus,'--pcp="'+FParent.LazarusPrimaryConfigPath+'"',FParent.ShortcutNameLazarus);
{$ENDIF DARWIN}
{$IF (defined(LINUX)) or (defined(BSD))}
// Desktop shortcut creation will not always work. As a fallback, create the link in the home directory:
CreateDesktopShortCut(InstalledLazarus,'--pcp="'+FParent.LazarusPrimaryConfigPath+'"',FParent.ShortCutNameLazarus);
CreateHomeStartLink(InstalledLazarus,'--pcp="'+FParent.LazarusPrimaryConfigPath+'"',FParent.ShortcutNameLazarus);
{$ENDIF (defined(LINUX)) or (defined(BSD))}
{$ENDIF UNIX}
except
// Ignore problems creating shortcut
infoln('CreateLazarusScript: Error creating shortcuts/links to Lazarus. Continuing.',etWarning);
end;
end;
end;
function DeleteLazarusScript:boolean;
begin
result:=true;
if FParent.ShortCutNameLazarus<>EmptyStr then
begin
infoln('Lazarus: deleting desktop shortcut:',etInfo);
try
//Delete shortcut; we don't care very much if it fails=>don't mess with OperationSucceeded
{$IFDEF MSWINDOWS}
DeleteDesktopShortCut(FParent.ShortCutNameLazarus);
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
DeleteFileUTF8(FParent.ShortcutNameLazarus);
{$ENDIF UNIX}
finally
//Ignore problems deleting shortcut
end;
end;
end;
{$ifdef linux}
function CheckDevLibs(LCLPlatform: string): boolean;
const
LIBSCNT=4;
type
TLibList=array[1..LIBSCNT] of string;
const
LCLLIBS:TLibList = ('libX11.so','libgdk_pixbuf-2.0.so','libpango-1.0.so','libgdk-x11-2.0.so');
QTLIBS:TLibList = ('libQt4Pas.so','','','');
var
i:integer;
pll:^TLibList;
function TestLib(LibName:string):boolean;
var
Lib : TLibHandle;
begin
result:=true;
if LibName<>'' then
begin
Lib:=LoadLibrary(LibName);
result:=Lib<>0;
if result then
UnloadLibrary(Lib);
end;
end;
begin
result:=true;
if (LCLPlatform='') or (Uppercase(LCLPlatform)='GTK2') then
pll:=@LCLLIBS
else if Uppercase(LCLPlatform)='QT' then
pll:=@QTLIBS;
for i:=1 to LIBSCNT do
begin
if not TestLib(pll^[i]) then
begin
FParent.WritelnLog('Required -dev packages are not installed for Lazarus: '+pll^[i], true);
result:=false;
end;
end;
end;
{$else} //stub for other platforms for now
function CheckDevLibs(LCLPlatform: string): boolean;
begin
result:=true;
end;
{$endif linux}
begin
infoln('TSequencer: DoExec for function '+FunctionName+' called.',etDebug);
if UpperCase(FunctionName)='CREATEFPCUPSCRIPT' then
result:=CreateFpcupScript
else if UpperCase(FunctionName)='CREATELAZARUSSCRIPT' then
result:=CreateLazarusScript
else if UpperCase(FunctionName)='DELETELAZARUSSCRIPT' then
result:=DeleteLazarusScript
else if UpperCase(FunctionName)='CHECKDEVLIBS' then
result:=CheckDevLibs(FParent.CrossLCL_Platform)
else
begin
result:=false;
FParent.WritelnLog('Error: Trying to execute a non existing function: ' + FunctionName);
end;
end;
function TSequencer.DoGetModule(ModuleName: string): boolean;
begin
infoln('TSequencer: DoGetModule for module '+ModuleName+' called.',etDebug);
result:= GetInstaller(ModuleName) and FInstaller.GetModule(ModuleName);
end;
function TSequencer.DoSetCPU(CPU: string): boolean;
begin
infoln('TSequencer: DoSetCPU for CPU '+CPU+' called.',etDebug);
FParent.CrossCPU_Target:=CPU;
ResetAllExecuted;
result:=true;
end;
function TSequencer.DoSetOS(OS: string): boolean;
begin
infoln('TSequencer: called DoSetOS for OS '+OS,etDebug);
FParent.CrossOS_Target:=OS;
ResetAllExecuted;
result:=true;
end;
function TSequencer.DoResetLCL: boolean;
begin
infoln('TSequencer: called DoReSetLCL',etDebug);
ResetAllExecuted(true);
result:=true;
end;
function TSequencer.DoUnInstallModule(ModuleName: string): boolean;
begin
infoln('TSequencer: DoUninstallModule for module '+ModuleName+' called.',etDebug);
result:= GetInstaller(ModuleName) and FInstaller.UnInstallModule(ModuleName);
end;
{GetInstaller gets a new installer for ModuleName and initialises parameters unless one exist already.}
function TSequencer.GetInstaller(ModuleName: string): boolean;
var
CrossCompiling:boolean;
begin
result:=true;
CrossCompiling:=(FParent.CrossCPU_Target<>'') or (FParent.CrossOS_Target<>'');
//check if this is a known module:
// FPC:
if uppercase(ModuleName)='FPC' then
begin
if assigned(FInstaller) then
begin
// Check for existing normal compiler, or exact same cross compiler
if (not crosscompiling and (FInstaller is TFPCNativeInstaller)) or
( crosscompiling and
(FInstaller is TFPCCrossInstaller) and
(FInstaller.CrossOS_Target=FParent.CrossOS_Target) and
(FInstaller.CrossCPU_Target=FParent.CrossCPU_Target)
) then
begin
exit; //all fine, continue with current FInstaller
end
else
FInstaller.free; // get rid of old FInstaller
end;
if CrossCompiling then
begin
FInstaller:=TFPCCrossInstaller.Create;
FInstaller.CrossCPU_Target:=FParent.CrossCPU_Target;
FInstaller.CrossOPT:=FParent.CrossOPT;
FInstaller.CrossOS_Target:=FParent.CrossOS_Target;
end
else
FInstaller:=TFPCNativeInstaller.Create;
FInstaller.BaseDirectory:=FParent.FPCDirectory;
(FInstaller as TFPCInstaller).BootstrapCompilerDirectory:=FParent.BootstrapCompilerDirectory;
(FInstaller as TFPCInstaller).BootstrapCompilerURL:=FParent.BootstrapCompilerURL;
FInstaller.Compiler:=''; //bootstrap used
FInstaller.CompilerOptions:=FParent.FPCOPT;
FInstaller.DesiredRevision:=FParent.FPCDesiredRevision;
FInstaller.URL:=FParent.FPCURL;
end
// Lazarus:
else if (uppercase(ModuleName)='LAZARUS') or (uppercase(ModuleName)='LAZBUILD') or (uppercase(ModuleName)='LCL') or
(uppercase(ModuleName)='USERIDE') then
begin
if assigned(FInstaller) then
begin
if (not crosscompiling and (FInstaller is TLazarusNativeInstaller)) or
(crosscompiling and (FInstaller is TLazarusCrossInstaller)) then
begin
exit; //all fine, continue with current FInstaller
end
else
FInstaller.free; // get rid of old FInstaller
end;
if CrossCompiling then
begin
FInstaller:=TLazarusCrossInstaller.Create;
FInstaller.CrossCPU_Target:=FParent.CrossCPU_Target;
FInstaller.CrossOPT:=FParent.CrossOPT;
FInstaller.CrossOS_Target:=FParent.CrossOS_Target;
end
else
FInstaller:=TLazarusNativeInstaller.Create;
FInstaller.BaseDirectory:=FParent.LazarusDirectory ;
if FParent.CompilerName='' then
FInstaller.Compiler:=FInstaller.GetCompilerInDir(FParent.FPCDirectory)
else
FInstaller.Compiler:=FParent.CompilerName;
FInstaller.CompilerOptions:=FParent.LazarusOPT;
FInstaller.DesiredRevision:=FParent.LazarusDesiredRevision;
// CrossLCL_Platform is only used when building LCL, but the Lazarus module
// will take care of that.
(FInstaller As TLazarusInstaller).CrossLCL_Platform:=FParent.CrossLCL_Platform;
(FInstaller As TLazarusInstaller).FPCDir:=FParent.FPCDirectory;
(FInstaller As TLazarusInstaller).PrimaryConfigPath:=FParent.LazarusPrimaryConfigPath;
FInstaller.URL:=FParent.LazarusURL;
end
//Convention: help modules start with HelpFPC
//or HelpLazarus
else if uppercase(ModuleName)='HELPFPC' then
begin
if assigned(FInstaller) then
begin
if (FInstaller is THelpFPCInstaller) then
begin
exit; //all fine, continue with current FInstaller
end
else
FInstaller.free; // get rid of old FInstaller
end;
FInstaller:=THelpFPCInstaller.Create;
FInstaller.BaseDirectory:=FParent.FPCDirectory;
if FParent.CompilerName='' then
FInstaller.Compiler:=FInstaller.GetCompilerInDir(FParent.FPCDirectory)
else
FInstaller.Compiler:=FParent.CompilerName;
end
else if uppercase(ModuleName)='HELPLAZARUS' then
begin
if assigned(FInstaller) then
begin
if (FInstaller is THelpLazarusInstaller) then
begin
exit; //all fine, continue with current FInstaller
end
else
FInstaller.free; // get rid of old FInstaller
end;
FInstaller:=THelpLazarusInstaller.Create;
FInstaller.BaseDirectory:=FParent.LazarusDirectory ;
if FParent.CompilerName='' then
FInstaller.Compiler:=FInstaller.GetCompilerInDir(FParent.FPCDirectory)
else
FInstaller.Compiler:=FParent.CompilerName;
(FInstaller as THelpLazarusInstaller).FPCDirectory:=FParent.FPCDirectory;
(FInstaller as THelpLazarusInstaller).LazarusPrimaryConfigPath:=FParent.LazarusPrimaryConfigPath;
end
else // this is a universal module
begin
if assigned(FInstaller) then
begin
if (FInstaller is TUniversalInstaller) and
(FCurrentModule= ModuleName) then
begin
exit; //all fine, continue with current FInstaller
end
else
FInstaller.free; // get rid of old FInstaller
end;
FInstaller:=TUniversalInstaller.Create;
FCurrentModule:=ModuleName;
//assign properties
(FInstaller as TUniversalInstaller).FPCDir:=FParent.FPCDirectory;
// Use compileroptions for chosen FPC compile options...
FInstaller.CompilerOptions:=FParent.FPCOPT;
// ... but more importantly, pass Lazarus compiler options needed for IDE rebuild
(FInstaller as TUniversalInstaller).LazarusCompilerOptions:=FParent.FLazarusOPT;
(FInstaller as TUniversalInstaller).LazarusDir:=FParent.FLazarusDirectory;
(FInstaller as TUniversalInstaller).LazarusPrimaryConfigPath:=FParent.LazarusPrimaryConfigPath;
if FParent.CompilerName='' then
FInstaller.Compiler:=FInstaller.GetCompilerInDir(FParent.FPCDirectory)
else
FInstaller.Compiler:=FParent.CompilerName;
end;
if Assigned(FInstaller.SVNClient) then
FInstaller.SVNClient.RepoExecutable := FParent.SVNExecutable;
FInstaller.HTTPProxyHost:=FParent.HTTPProxyHost;
FInstaller.HTTPProxyPort:=FParent.HTTPProxyPort;
FInstaller.HTTPProxyUser:=FParent.HTTPProxyUser;
FInstaller.HTTPProxyPassword:=FParent.HTTPProxyPassword;
FInstaller.KeepLocalChanges:=FParent.KeepLocalChanges;
FInstaller.ReApplyLocalChanges:=FParent.ReApplyLocalChanges;
FInstaller.PatchCmd:=FParent.PatchCmd;
FInstaller.Verbose:=FParent.Verbose;
FInstaller.Log:=FParent.FLog;
{$IFDEF MSWINDOWS}
FInstaller.MakeDirectory:=FParent.MakeDirectory;
{$ENDIF}
end;
function TSequencer.GetText: string;
var
i:integer;
begin
for i:=Low(FStateMachine) to High(FStateMachine) do
begin
// todo: add translation of instr
result:=result+
'Instruction number: '+inttostr(ord(FStateMachine[i].instr))+' '+
FStateMachine[i].param;
if i<High(FStateMachine) then
result:=result+LineEnding;
end;
end;
function TSequencer.IsSkipped(ModuleName: string): boolean;
begin
result:=assigned(FSkipList) and (FSkipList.IndexOf(Uppercase(ModuleName))>=0);