-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathinstallercore.pas
executable file
·4290 lines (3802 loc) · 150 KB
/
installercore.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 installerCore;
{
Core fpc(laz)up(deluxe) installer code
Copyright (C) 2012-2014 Ludo Brands, Reinier Olislagers
Copyright (C) 2015-2017 Alfred Glänzer
This file is part of fpc(laz)up(deluxe).
Fpc(laz)up(deluxe) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fpc(laz)up(deluxe) 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with fpc(laz)up(deluxe). If not, see <https://www.gnu.org/licenses/>
}
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
FileUtil,
fpcuputil,
repoclient, GitClient, HGClient, SvnClient,
processutils, m_crossinstaller;
{$i revision.inc}
const
DEFAULTFPCVERSION = '3.2.2';
FPCTRUNKVERSION = '3.3.1';
FPCTRUNKBOOTVERSION = '3.2.2';
LAZARUSTRUNKVERSION = '2.3.0';
DEFAULTFREEBSDVERSION = 12;
LAZBUILDNAME = 'lazbuild';
MAKEFILENAME = 'Makefile';
FPCMAKEFILENAME = MAKEFILENAME+'.fpc';
FPCMAKECONFIG = 'fpcmkcfg';
LIBQT5 = 'libQt5Pas.so';
FPCPKGFILENAME = 'fppkg';
FPCPKGCONFIGFILENAME = 'fppkg.cfg';
FPFILENAME = 'fp';
FPCONFIGFILENAME = 'fp.cfg';
FPINIFILENAME = 'fp.ini';
FPCPKGCOMPILERTEMPLATE= 'default'; // fppkg default compiler template
FPCCONFIGFILENAME = 'fpc.cfg';
GITLAB = 'https://gitlab.com/freepascal.org/';
FPCGITLAB = GITLAB + 'fpc';
FPCGITLABREPO = FPCGITLAB + '/source';
FPCGITLABBINARIES = FPCGITLAB + '/build';
FPCTRUNKBRANCH = 'main';
FPCBINARIES = FPCGITLABBINARIES + '/-/raw/'+FPCTRUNKBRANCH;
LAZARUSGITLAB = GITLAB + 'lazarus';
LAZARUSGITLABREPO = LAZARUSGITLAB + '/lazarus';
LAZARUSGITLABBINARIES = LAZARUSGITLAB + '/binaries';
LAZARUSTRUNKBRANCH = 'main';
LAZARUSBINARIES = LAZARUSGITLABBINARIES + '/-/raw/'+LAZARUSTRUNKBRANCH;
SVNBASEHTTP = 'https://svn.';
SVNBASESVN = 'svn://svn.';
FTPBASEHTTP = 'https://ftp.';
FTPBASEFTP = 'ftp://ftp.';
FPCBASESVNURL = SVNBASEHTTP+'freepascal.org';
FTPBASEURL = FTPBASEFTP+'freepascal.org';
FPCFTPURL = FTPBASEURL+'/pub/fpc/';
LAZARUSFTPURL = FTPBASEURL+'/pub/lazarus/';
FPCFTPSNAPSHOTURL = FPCFTPURL+'snapshot/';
LAZARUSFTPSNAPSHOTURL = LAZARUSFTPURL+'snapshot/';
PACKAGESLOCATION = 'packages.fppkg';
PACKAGESCONFIGDIR = 'fpcpkgconfig';
//PACKAGESCONFIGDIR = PACKAGESLOCATION+DirectorySeparator+'fpcpkgconfig';
REVINCFILENAME = 'revision.inc';
{$IFDEF WINDOWS}
PREBUILTBINUTILSURLWINCE = FPCBINARIES+'/install/crossbinwce';
{$ENDIF}
{$ifdef win64}
OPENSSL_URL_LATEST = LAZARUSBINARIES + '/x86_64-win64/openssl';
{$endif}
{$ifdef win32}
OPENSSL_URL_LATEST = LAZARUSBINARIES + '/i386-win32/openssl';
{$endif}
{$IFDEF DEBUG}
STANDARDCOMPILERVERBOSITYOPTIONS='-vewh';
//STANDARDCOMPILERVERBOSITYOPTIONS='-va';
{$ELSE}
//STANDARDCOMPILERVERBOSITYOPTIONS='-vw-n-h-i-l-d-u-t-p-c-x-';
STANDARDCOMPILERVERBOSITYOPTIONS='-vw-n-h-l-d-u-t-p-c-';
{$ENDIF}
//NASMWIN32URL='https://www.nasm.us/pub/nasm/releasebuilds/2.13/win32/nasm-2.13-win32.zip';
//NASMWIN64URL='https://www.nasm.us/pub/nasm/releasebuilds/2.13/win64/nasm-2.13-win64.zip';
NASMWIN32URL='https://www.nasm.us/pub/nasm/releasebuilds/2.14/win32/nasm-2.14-win32.zip';
NASMWIN64URL='https://www.nasm.us/pub/nasm/releasebuilds/2.14/win64/nasm-2.14-win64.zip';
NASMFPCURL=FPCBINARIES+'/install/crossbinmsdos/nasm.exe';
GITREPO='https://github.com/LongDirtyAnimAlf';
FPCUPGITREPO=GITREPO+'/fpcupdeluxe';
FPCGITMIRRORREPO='https://github.com/fpc';
BOOTSTRAPPERVERSION='bootstrappers_v1.0';
FPCUPGITREPOBOOTSTRAPPER=FPCUPGITREPO+'/releases/download/'+BOOTSTRAPPERVERSION;
FPCUPGITREPOAPI='https://api.github.com/repos/LongDirtyAnimAlf/fpcupdeluxe/releases';
FPCUPGITREPOBOOTSTRAPPERAPI=FPCUPGITREPOAPI+'/tags/'+BOOTSTRAPPERVERSION;
SOURCEPATCHES='patches_v1.0';
FPCUPGITREPOSOURCEPATCHESAPI=FPCUPGITREPOAPI+'/tags/'+SOURCEPATCHES;
FPCUPPRIVATEGITREPO='https://www.consulab.nl/git/Alfred/FPCbootstrappers/raw/master';
FPCUP_ACKNOWLEDGE='acknowledgement_fpcup.txt';
{$IF (defined(OpenBSD)) and (defined(CPU64))}
// 2.6.2 and older do not work anymore on newer OpenBSD64 versions
FPC_OFFICIAL_MINIMUM_BOOTSTRAPVERSION=(2*10000+6*100+2);
{$else}
// 2.2.4 and older have no official FPC bootstrapper available online
FPC_OFFICIAL_MINIMUM_BOOTSTRAPVERSION=(2*10000+2*100+4);
{$endif}
{$ifdef win64}
OpenSSLSourceURL : array [0..3] of string = (
//'https://indy.fulgan.com/SSL/openssl-1.0.2u-x64_86-win64.zip',
'https://github.com/IndySockets/OpenSSL-Binaries/raw/master/openssl-1.0.2u-x64_86-win64.zip',
'http://wiki.overbyte.eu/arch/openssl-1.0.2u-win64.zip',
'http://www.magsys.co.uk/download/software/openssl-1.0.2o-win64.zip',
'https://indy.fulgan.com/SSL/Archive/openssl-1.0.2p-x64_86-win64.zip'
);
{$endif}
{$ifdef win32}
OpenSSLSourceURL : array [0..3] of string = (
//'https://indy.fulgan.com/SSL/openssl-1.0.2u-i386-win32.zip',
'https://github.com/IndySockets/OpenSSL-Binaries/raw/master/openssl-1.0.2u-i386-win32.zip',
'http://wiki.overbyte.eu/arch/openssl-1.0.2u-win32.zip',
'http://www.magsys.co.uk/download/software/openssl-1.0.2o-win32.zip',
'https://indy.fulgan.com/SSL/Archive/openssl-1.0.2p-i386-win32.zip'
);
{$endif}
REVISIONSLOG = 'fpcuprevisions.log';
SnipMagicBegin = '# begin fpcup do not remove '; //look for this/add this in fpc.cfg cross-compile snippet. Note: normally followed by FPC CPU-os code
SnipMagicEnd = '# end fpcup do not remove'; //denotes end of fpc.cfg cross-compile snippet
FPCSnipMagic = '# If you don''t want so much verbosity use'; //denotes end of standard fpc.cfg
FPCREVMAGIC = 'FPC new revision: ';
LAZREVMAGIC = 'Lazarus new revision: ';
FPCDATEMAGIC = 'FPC update at: ';
LAZDATEMAGIC = 'Lazarus update at: ';
FPCHASHMAGIC = 'FPC new GIT hash: ';
LAZHASHMAGIC = 'Lazarus new GIT hash: ';
FPCURLLOOKUPMAGIC = 'fpcURL';
FPCTAGLOOKUPMAGIC = 'fpcTAG';
FPCBRANCHLOOKUPMAGIC = 'fpcBRANCH';
LAZARUSURLLOOKUPMAGIC = 'lazURL';
LAZARUSTAGLOOKUPMAGIC = 'lazTAG';
LAZARUSBRANCHLOOKUPMAGIC = 'lazBRANCH';
GITLABEXTENSION = '.gitlab';
DIFFMAGIC = 'revhash_';
//Sequence contants for statemachine
_SEP = ';';
_FPC = 'FPC';
_LAZARUS = 'Lazarus';
_LAZARUSSIMPLE = _LAZARUS+'Simple';
_MAKEFILECHECK = 'MakefileCheck';
_MAKEFILECHECKFPC = _MAKEFILECHECK+_FPC;
_MAKEFILECHECKLAZARUS = _MAKEFILECHECK+_LAZARUS;
_DEFAULT = 'Default';
_DEFAULTSIMPLE = 'DefaultSimple';
_CLEAN = 'Clean';
_CHECK = 'Check';
_GET = 'Get';
_CONFIG = 'Config';
_BUILD = 'Build';
_INSTALL = 'Install';
_UNINSTALL = 'Uninstall';
_RESET = 'Reset';
_ONLY = 'Only';
_DO = 'Do ';
_DECLARE = 'Declare ';
_EXECUTE = 'Exec ';
_SETCPU = 'SetCPU ';
_SETOS = 'SetOS ';
_REQUIRES = 'Requires ';
_DECLAREHIDDEN = 'DeclareHidden ';
_MODULE = 'Module ';
_CLEANMODULE = _CLEAN+_MODULE;
_CHECKMODULE = _CHECK+_MODULE;
_GETMODULE = _GET+_MODULE;
_CONFIGMODULE = _CONFIG+_MODULE;
_BUILDMODULE = _BUILD+_MODULE;
_UNINSTALLMODULE = _UNINSTALL+_MODULE;
_CREATESCRIPT = 'CreateScript';
_CREATEFPCUPSCRIPT = 'CreateFpcupScript';
_CREATELAZARUSSCRIPT = 'CreateLazarusScript';
_DELETELAZARUSSCRIPT = 'DeleteLazarusScript';
_CHECKDEVLIBS = 'CheckDevLibs';
_LAZBUILD = 'Lazbuild';
_STARTLAZARUS = 'StartLazarus';
_LCL = 'LCL';
_COMPONENTS = 'Components';
_PACKAGER = 'Packager';
_IDE = 'IDE';
_BIGIDE = 'BigIDE';
_USERIDE = 'UserIDE';
_OLDLAZARUS = 'OldLazarus';
_PAS2JS = 'Pas2JS';
_DOCKER = 'Docker';
_SUGGESTED = 'suggestedpackages';
_SUGGESTEDADD = _SUGGESTED+'add';
_UNIVERSALDEFAULT = 'Universal'+_DEFAULT;
_FPCCLEANBUILDONLY = _FPC+_CLEAN+_BUILD+_ONLY;
_FPCREMOVEONLY = _FPC+_UNINSTALL+_ONLY;
_LAZARUSCLEANBUILDONLY = _LAZARUS+_CLEAN+_BUILD+_ONLY;
_LAZARUSREMOVEONLY = _LAZARUS+_UNINSTALL+_ONLY;
_LCLALLREMOVEONLY = _LCL+'ALL'+_CLEAN+_ONLY;
_LCLREMOVEONLY = _LCL+_CLEAN+_ONLY;
_COMPONENTSREMOVEONLY = _COMPONENTS+_CLEAN+_ONLY;
_PACKAGERREMOVEONLY = _PACKAGER+_CLEAN+_ONLY;
_HELP = 'Help';
_HELPFPC = _HELP+_FPC;
_HELPLAZARUS = _HELP+_LAZARUS;
_LHELP = 'lhelp';
_INSTALLLAZARUS = _INSTALL+_LAZARUS;
{$ifdef mswindows}
{$ifdef win32}
_CROSSWIN = 'CrossWin32-64';
{$endif}
{$ifdef win64}
_CROSSWIN = 'CrossWin64-32';
{$endif}
{$endif}
_RESETLCL = 'ResetLCL';
_LCLCROSS = 'LCLCross';
_ENDFINAL = 'End';
_END = _ENDFINAL+_SEP;
URL_ERROR = 'sources error (URL mismatch)';
const
ppcSuffix : array[TCPU] of string=(
'none','386','x64','arm','a64','ppc','ppc64', 'mips', 'mipsel','avr','jvm','8086','sparc','sparc64','rv32','rv64','68k','xtensa','wasm32'
);
type
TUtilCategory = (ucBinutil {regular binutils like as.exe},
ucDebugger32 {Debugger (support) files 32bit},
ucDebugger64 {Debugger (support) files 64bit},
ucDebuggerWince {Debugger (support) files for wince},
ucQtFile {e.g. Qt binding},
ucOther {unknown});
// Keeps track of downloadable files, e.g. binutils
TUtilsList= record
FileName: string;
//OS as determined by FPC (e.g. WIN32). Blank for all
OS: string; // For now, OS field is not used as compiler defines manage filling the initial list
RootURL: string; //URL including trailing / but without filename
Category: TUtilCategory;
end;
TRevision= record
SVNRevision: string;
GITHash: string;
end;
{ TInstaller }
TInstaller = class(TObject)
private
FURL : string;
FTAG : string;
FUltibo : boolean;
FKeepLocalChanges : boolean;
FReApplyLocalChanges : boolean;
FCrossInstaller : TCrossInstaller;
FCrossCPU_Target : TCPU; //When cross-compiling: CPU, e.g. x86_64
FCrossOS_Target : TOS; //When cross-compiling: OS, e.g. win64
FCrossOS_SubArch : TSUBARCH; //When cross-compiling for embedded: CPU, e.g. for Teensy SUBARCH=ARMV7EM
FCrossOS_ABI : TABI; //When cross-compiling for arm: hardfloat or softfloat calling convention
FCrossToolsDirectory : string;
FCrossLibraryDirectory : string;
procedure SetURL(value:string);
procedure SetSourceDirectory(value:string);
procedure SetBaseDirectory(value:string);
procedure SetInstallDirectory(value:string);
procedure SetFPCInstallDirectory(value:string);
procedure SetFPCSourceDirectory(value:string);
function GetShell: string;
function GetMake: string;
procedure SetVerbosity(aValue:boolean);
procedure SetHTTPProxyHost(AValue: string);
procedure SetHTTPProxyPassword(AValue: string);
procedure SetHTTPProxyPort(AValue: integer);
procedure SetHTTPProxyUser(AValue: string);
function DownloadFromBase(aClient:TRepoClient; aModuleName: string; var aBeforeRevision, aAfterRevision: string; UpdateWarnings: TStringList): boolean;
// Get fpcup registred cross-compiler, if any, if not, return nil
function GetCrossInstaller: TCrossInstaller;
function GetCrossCompilerPresent:boolean;
function GetFullVersionString:string;
function GetFullVersion:dword;
function GetDefaultCompilerFilename(const TargetCPU: TCPU; Cross: boolean): string;
function GetInstallerClass(aClassToFind:TClass):boolean;
function IsFPCInstaller:boolean;
function IsLazarusInstaller:boolean;
function IsUniversalInstaller:boolean;
protected
FCleanModuleSuccess: boolean;
FNeededExecutablesChecked: boolean;
FFPCCompilerBinPath: string; //path where compiler lives
FBaseDirectory: string; //Base directory for fpc(laz)up(deluxe) install itself
FSourceDirectory: string; //Top source directory for a product (FPC, Lazarus)
FInstallDirectory: string; //Top install directory for a product (FPC, Lazarus)
FFPCInstallDir: string;
FFPCSourceDir: string;
FTempDirectory: string; //For storing temp files and logs
FCompiler: string; // Compiler executable
FCompilerOptions: string; //options passed when compiling (FPC or Lazarus currently)
FCPUCount: integer; //logical cpu count (i.e. hyperthreading=2cpus)
FCrossOPT: string; //options passed (only) when cross-compiling
FPreviousRevision: string;
FDesiredRevision: string;
FActualRevision: string;
FBranch: string;
// Stores tprocessex exception info:
FErrorLog: TStringList;
FHTTPProxyHost: string;
FHTTPProxyPassword: string;
FHTTPProxyPort: integer;
FHTTPProxyUser: string;
FLog: TLogger;
FLogVerbose: TLogger; // Log file separate from main fpcup.log, for verbose logging
FShell: string;
FMake: string;
FMakeDir: string; //Binutils/make/patch directory
FPatchCmd: string;
FGitClient: TGitClient;
FHGClient: THGClient;
FSVNClient: TSVNClient;
FRepositoryUpdated: boolean;
FSourcePatches: string;
FMajorVersion: integer; //major part of the version number, e.g. 1 for 1.0.8, or -1 if unknown
FMinorVersion: integer; //minor part of the version number, e.g. 0 for 1.0.8, or -1 if unknown
FReleaseVersion: integer; //release part of the version number, e.g. 8 for 1.0.8, or -1 if unknown
FPatchVersion: integer; //release candidate part of the version number, e.g. 3 for 1.0.8_RC3, or -1 if unknown
FUtilFiles: array of TUtilsList; //Keeps track of binutils etc download locations, filenames...
FExportOnly: boolean;
FNoJobs: boolean;
FOnlinePatching: boolean;
FVerbose: boolean;
FUseWget: boolean;
FTar: string;
FGunzip: string;
F7zip: string;
FWget: string;
FUnrar: string;
//FGit: string;
FExternalTool: TExternalTool;
FExternalToolResult: integer;
FSwitchURL: boolean;
FSolarisOI: boolean;
FMUSL: boolean;
FMUSLLinker: string;
property Shell: string read GetShell;
property Make: string read GetMake;
// Check for existence of required executables; if not there, get them if possible
function CheckAndGetTools: boolean;
// Check for existence of required binutils; if not there, get them if possible
function CheckAndGetNeededBinUtils: boolean;
// Make a list (in FUtilFiles) of all binutils that can be downloaded
procedure CreateBinutilsList({%H-}aVersion:string='');
// Get a diff of all modified files in and below the directory and save it
procedure CreateStoreRepositoryDiff(DiffFileName: string; UpdateWarnings: TStringList; RepoClass: TObject);
// Clone/update using HG; use FSourceDirectory as local repository
// Any generated warnings will be added to UpdateWarnings
function DownloadFromHG(aModuleName: string; var aBeforeRevision, aAfterRevision: string; UpdateWarnings: TStringList): boolean;
// Clone/update using Git; use FSourceDirectory as local repository
// Any generated warnings will be added to UpdateWarnings
function DownloadFromGit(aModuleName: string; var aBeforeRevision, aAfterRevision: string; UpdateWarnings: TStringList): boolean;
// Checkout/update using SVN; use FSourceDirectory as local repository
// Any generated warnings will be added to UpdateWarnings
function DownloadFromSVN(aModuleName: string; var aBeforeRevision, aAfterRevision: string; UpdateWarnings: TStringList): boolean;
function DownloadFromURL(ModuleName: string): boolean;
// Clone/update using Git; use FSourceDirectory as local repository
// Any generated warnings will be added to UpdateWarnings
{$IFDEF MSWINDOWS}
// Download make.exe, patch.exe etc into the make directory (only implemented for Windows):
function DownloadBinUtils: boolean;
function DownloadSVN: boolean;
{$ifndef USEONLYCURL}
function DownloadOpenSSL: boolean;
{$endif}
function DownloadWget: boolean;
function DownloadFreetype: boolean;
function DownloadZlib: boolean;
{$ENDIF}
function DownloadJasmin: boolean;
// Looks for SVN client in subdirectories and sets FSVNClient.SVNExecutable if found.
{$IFDEF MSWINDOWS}
function FindSVNSubDirs: boolean;
{$ENDIF}
// Returns CPU-OS in the format used by the FPC bin directory, e.g. x86_64-win64:
function GetFPCTarget(Native: boolean): string;
// Sets the search/binary path to NewPath or adds NewPath before or after existing path:
procedure SetPath(NewPath: string; Prepend: boolean; Append: boolean);
// Get currently set path
function GetPath: string;
function GetFile(aURL,aFile:string; forceoverwrite:boolean=false; forcenative:boolean=false):boolean;
function GetSanityCheck:boolean;
function GetVersionFromSource({%H-}aSourcePath:string):string;virtual;
function GetVersionFromURL({%H-}aUrl:string):string;virtual;
function GetReleaseCandidateFromSource({%H-}aSourcePath:string):integer;virtual;
function GetVersion:string;
public
InfoText: string;
LocalInfoText: string;
property SVNClient: TSVNClient read FSVNClient;
property GitClient: TGitClient read FGitClient;
property HGClient: THGClient read FHGClient;
// Get processor for termination of running processes
property Processor: TExternalTool read FExternalTool;
property ProcessorResult: integer read FExternalToolResult write FExternalToolResult;
// Source directory for installation (fpcdir, lazdir,... option)
property SourceDirectory: string write SetSourceDirectory;
//Base directory for fpc(laz)up(deluxe) itself
property BaseDirectory: string write SetBaseDirectory;
// Final install directory
property InstallDirectory: string write SetInstallDirectory;
//Base directory for fpc(laz)up(deluxe) itself
// FPC install directory
property FPCInstallDir: string write SetFPCInstallDirectory;
// FPC source directory
property FPCSourceDir: string write SetFPCSourceDirectory;
property TempDirectory: string write FTempDirectory;
// Compiler to use for building. Specify empty string when using bootstrap compiler.
property Compiler: string {read GetCompiler} write FCompiler;
// Compiler options passed on to make as OPT= or FPCOPT=
property CompilerOptions: string write FCompilerOptions;
// SubArch for target embedded
property CrossOS_SubArch: TSUBARCH read FCrossOS_SubArch;
// When cross-compiling for arm: hardfloat or softfloat calling convention
property CrossOS_ABI: TABI read FCrossOS_ABI;
// Options for cross compiling. User can specify his own, but cross compilers can set defaults, too
property CrossOPT: string read FCrossOPT write FCrossOPT;
property CrossToolsDirectory:string read FCrossToolsDirectory write FCrossToolsDirectory;
property CrossLibraryDirectory:string read FCrossLibraryDirectory write FCrossLibraryDirectory;
// SVN revision override. Default is HEAD/latest revision
property PreviousRevision: string read FPreviousRevision;
property DesiredRevision: string write FDesiredRevision;
property ActualRevision: string read FActualRevision;
property Branch: string write FBranch;
// If using HTTP proxy: host
property HTTPProxyHost: string read FHTTPProxyHost write SetHTTPProxyHost;
// If using HTTP proxy: port (optional, default 8080)
property HTTPProxyPort: integer read FHTTPProxyPort write SetHTTPProxyPort;
// If using HTTP proxy: username (optional)
property HTTPProxyUser: string read FHTTPProxyUser write SetHTTPProxyUser;
// If using HTTP proxy: password (optional)
property HTTPProxyPassword: string read FHTTPProxyPassword write SetHTTPProxyPassword;
// Whether or not to let locally modified files remain or back them up to .diff and svn revert before compiling
property KeepLocalChanges: boolean write FKeepLocalChanges;
// auto switchover SVN URL
property SwitchURL: boolean write FSwitchURL;
// do we have OpenIndiana instead of plain Solaris
property SolarisOI: boolean write FSolarisOI;
// do we have musl instead of libc
property MUSL: boolean write FMUSL;
// Are we installing Ultibo
property Ultibo: boolean read FUltibo write FUltibo;
property Log: TLogger write FLog;
// Directory where make (and the other binutils on Windows) is located
property MakeDirectory: string write FMakeDir;
// Patch utility to use. Defaults to 'patch'
property PatchCmd:string write FPatchCmd;
// Whether or not to back up locale changes to .diff and reapply them before compiling
property ReApplyLocalChanges: boolean write FReApplyLocalChanges;
// URL for download. HTTP, ftp or svn or git or hg
property URL: string read FURL write SetURL;
property TAG: string read FURL write FTAG;
// patches
property SourcePatches: string write FSourcePatches;
// do not download the repo itself, but only get the files (of master)
property ExportOnly: boolean write FExportOnly;
property NoJobs: boolean write FNoJobs;
property OnlinePatching: boolean write FOnlinePatching;
// display and log in temp log file all sub process output
property Verbose: boolean write SetVerbosity;
// use wget as downloader ??
property UseWget: boolean write FUseWget;
// get cross-installer
property CrossInstaller:TCrossInstaller read GetCrossInstaller;
property CrossCompilerPresent: boolean read GetCrossCompilerPresent;
property SourceVersionStr:string read GetFullVersionString;
property SourceVersionNum:dword read GetFullVersion;
property SanityCheck:boolean read GetSanityCheck;
function GetCompilerName(Cpu_Target:TCPU):string;overload;
function GetCompilerName(Cpu_Target:string):string;overload;
function GetCrossCompilerName(Cpu_Target:TCPU):string;
procedure SetTarget(aCPU:TCPU;aOS:TOS;aSubArch:TSUBARCH);virtual;
procedure SetABI(aABI:TABI);
// append line ending and write to log and, if specified, to console
procedure WritelnLog(msg: TStrings; ToConsole: boolean = true);overload;
procedure WritelnLog(msg: string; ToConsole: boolean = true);overload;
procedure WritelnLog(EventType: TEventType; msg: string; ToConsole: boolean = true);overload;
function GetSuitableRepoClient:TRepoClient;
function GetTempFileNameExt(Prefix,Ext : String) : String;
function GetTempDirName(Prefix: String='fpcup') : String;
// Build module
function BuildModule(ModuleName: string): boolean; virtual;
// Clean up environment
function CleanModule(ModuleName: string): boolean; virtual;
// Config module
function ConfigModule(ModuleName: string): boolean; virtual;
// Constructs FPC compiler path from install directory and architecture
// Corrects for use of our fpc.sh launcher on *nix
// Does not verify compiler actually exists.
function GetFPCInBinDir: string;
// Install update sources
function GetModule(ModuleName: string): boolean; virtual;
// Perform some checks on the sources
function CheckModule(ModuleName: string): boolean; virtual;
// Patch sources
function PatchModule(ModuleName: string): boolean;
//Source revision
function CreateRevision(ModuleName,aRevision:string): boolean;
function GetRevision(ModuleName:string): string;
function GetRevisionFromVersion(aModuleName,aVersion:string): string;
// Uninstall module
function UnInstallModule(ModuleName: string): boolean; virtual;
procedure Infoln(Message: string; const Level: TEventType=etInfo);
function ExecuteCommand(Commandline: string; Verbosity:boolean): integer; overload;
function ExecuteCommand(Commandline: string; out Output:string; Verbosity:boolean): integer; overload;
function ExecuteCommand(const ExeName:String;const Arguments:array of String;Verbosity:boolean):integer;
function ExecuteCommand(const ExeName:String;const Arguments:array of String;out Output:string;Verbosity:boolean):integer;overload;
function ExecuteCommandInDir(Commandline, Directory: string; Verbosity:boolean): integer; overload;
function ExecuteCommandInDir(Commandline, Directory: string; out Output:string; Verbosity:boolean): integer; overload;
function ExecuteCommandInDir(Commandline, Directory: string; out Output:string; PrependPath: string; Verbosity:boolean): integer; overload;
function ExecuteCommandInDir(const ExeName:String;const Arguments:array of String;const Directory:String;out Output:string; PrependPath: string;Verbosity:boolean):integer;overload;
constructor Create;
destructor Destroy; override;
end;
TBaseUniversalInstaller = class(TInstaller);
TBaseFPCInstaller = class(TInstaller);
TBaseLazarusInstaller = class(TInstaller);
TBaseHelpInstaller = class(TInstaller);
TBaseWinInstaller = class(TInstaller);
implementation
uses
StrUtils,
{$ifdef LCL}
//For messaging to MainForm: no writeln
Forms,
//LMessages,
LCLIntf,
{$endif}
process,
RegExpr
{$IFDEF UNIX}
,LazFileUtils
{$ENDIF UNIX}
{$IF NOT DEFINED(HAIKU) AND NOT DEFINED(AROS) AND NOT DEFINED(MORPHOS)}
//,ssl_openssl
// for runtime init of openssl
{$ifndef USEONLYCURL}
{$IFDEF MSWINDOWS}
//,blcksock, ssl_openssl_lib
,openssl
{$ENDIF}
{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)}
,opensslsockets
{$ENDIF}
{$ENDIF}
{$endif}
;
{ TInstaller }
function TInstaller.GetCrossInstaller: TCrossInstaller;
var
idx: integer;
target: string;
begin
result:=nil;
if ((FCrossCPU_Target<>TCPU.cpuNone) AND (FCrossOS_Target<>TOS.osNone)) then
begin
if (NOT Assigned(FCrossInstaller)) OR ((FCrossInstaller.TargetCPU<>FCrossCPU_Target) OR (FCrossInstaller.TargetOS<>FCrossOS_Target)) then
begin
target := GetFPCTarget(false);
FCrossInstaller:=nil;
if assigned(CrossInstallers) then
for idx := 0 to Pred(CrossInstallers.Count) do
if CrossInstallers[idx] = target then
begin
FCrossInstaller:=TCrossInstaller(CrossInstallers.Objects[idx]);
break;
end;
end;
if (NOT Assigned(FCrossInstaller)) then
begin
Infoln(localinfotext+'Could not find crosscompiler logic for '+target+' !!',etError);
Infoln(localinfotext+'This is a fatal error. Exception will be created.',etError);
Infoln(localinfotext+'Please file a bug-report.',etError);
raise Exception.CreateFmt('%s fpcup cross-logic not found. Please report this issue.',[target]);
end
else
begin
result:=FCrossInstaller;
end;
end;
end;
function TInstaller.GetCrossCompilerPresent:boolean;
var
FPCCfg,aDir,s : string;
ConfigText : TStringList;
SnipBegin,i : integer;
aCPU,aOS : string;
{%H-}aArch : string;
begin
result:=false;
if (NOT DirectoryExists(FInstallDirectory)) then exit;
if CheckDirectory(FInstallDirectory) then exit;
if ((FCrossCPU_Target=TCPU.cpuNone) OR (FCrossOS_Target=TOS.osNone)) then exit;
//if (Self is TFPCCrossInstaller) then
begin
// check for existing cross-dirs
if (NOT result) then
begin
aDir:=ConcatPaths([FInstallDirectory,'bin',GetFPCTarget(false)]);
result:=DirectoryExists(aDir);
end;
if (NOT result) then
begin
aDir:=ConcatPaths([FInstallDirectory,'units',GetFPCTarget(false)]);
{$ifdef UNIX}
if FileIsSymlink(aDir) then
begin
try
aDir:=GetPhysicalFilename(aDir,pfeException);
except
end;
end;
{$endif}
result:=DirectoryExists(aDir);
end;
if result then exit;
// Check FPC config-file
aCPU:='';
aOS:='';
aArch:='';
FPCCfg:=FFPCCompilerBinPath+FPCCONFIGFILENAME;
if (NOT FileExists(FPCCfg)) then exit;
ConfigText:=TStringList.Create;
try
ConfigText.LoadFromFile(FPCCFG);
SnipBegin:=0;
while (SnipBegin<ConfigText.Count) do
begin
if Pos(SnipMagicBegin,ConfigText.Strings[SnipBegin])>0 then
begin
s:=ConfigText.Strings[SnipBegin];
Delete(s,1,Length(SnipMagicBegin));
i:=Pos('-',s);
if i>0 then
begin
aCPU:=Copy(s,1,i-1);
aOS:=Trim(Copy(s,i+1,MaxInt));
// try to distinguish between different ARM CPU versons ... very experimental and [therefor] only for Linux
if (UpperCase(aCPU)='ARM') AND (UpperCase(aOS)='LINUX') then
begin
for i:=SnipBegin to SnipBegin+5 do
begin
if Pos('#IFDEF CPU',ConfigText.Strings[i])>0 then
begin
s:=ConfigText.Strings[i];
Delete(s,1,Length('#IFDEF CPU'));
aArch:=s;
break;
end;
end;
end;
end;
end;
Inc(SnipBegin);
end;
result:=((GetCPU(FCrossCPU_Target)=aCPU) AND (GetOS(FCrossOS_Target)=aOS));
finally
ConfigText.Free;
end;
end;
//if (Self is TLazarusCrossInstaller) then
begin
if (NOT result) then
begin
aDir:=ConcatPaths([FInstallDirectory,'lcl','units',GetFPCTarget(false)]);
{$ifdef UNIX}
if FileIsSymlink(aDir) then
begin
try
aDir:=GetPhysicalFilename(aDir,pfeException);
except
end;
end;
{$endif}
result:=DirectoryExists(aDir);
end;
end;
end;
procedure TInstaller.SetURL(value:string);
begin
FURL:=value;
if (FURL <> '') and (FURL[Length(FURL)] <> '/') then
FURL := FURL + '/';
if (IsFPCInstaller OR IsLazarusInstaller) then
begin
FMajorVersion := -1;
FMinorVersion := -1;
FReleaseVersion := -1;
FPatchVersion := -1;
end;
end;
procedure TInstaller.SetSourceDirectory(value:string);
begin
FSourceDirectory:=value;
if (IsFPCInstaller OR IsLazarusInstaller) then
begin
FMajorVersion := -1;
FMinorVersion := -1;
FReleaseVersion := -1;
FPatchVersion := -1;
end;
end;
procedure TInstaller.SetBaseDirectory(value:string);
begin
FBaseDirectory:=value;
end;
procedure TInstaller.SetInstallDirectory(value:string);
begin
FInstallDirectory:=value;
if (IsFPCInstaller OR IsLazarusInstaller) then
begin
ForceDirectoriesSafe(FInstallDirectory);
end;
end;
procedure TInstaller.SetFPCInstallDirectory(value:string);
begin
FFPCInstallDir:=value;
FFPCCompilerBinPath:=ConcatPaths([FFPCInstallDir,'bin',GetFPCTarget(true)])+DirectorySeparator;
if (IsFPCInstaller) then
SetInstallDirectory(value);
end;
procedure TInstaller.SetFPCSourceDirectory(value:string);
begin
FFPCSourceDir:=value;
if (IsFPCInstaller) then
SetSourceDirectory(value);
end;
function TInstaller.GetMake: string;
const
{$if (defined(BSD) and not defined(DARWIN)) or (defined(Solaris))}
GNUMake='gmake';
{$else}
GNUMake='make';
{$endif}
begin
if FMake = '' then
{$IFDEF MSWINDOWS}
//Only use our own make !!
FMake := IncludeTrailingPathDelimiter(FMakeDir) + GNUMake + '.exe';
{$ELSE}
FMake:=Which(GNUMake);
if FMake='' then
begin
Infoln(localinfotext+'Could not find '+GNUMake+' executable.',etError);
Infoln(localinfotext+'This is a fatal error. Exception will be created.',etError);
Infoln(localinfotext+'Please make sure it is installed.',etError);
raise Exception.CreateFmt('%s not found. Please install %s',[GNUMake,GNUMake]);
end;
{$ENDIF MSWINDOWS}
Result := FMake;
end;
function TInstaller.GetShell: string;
begin
{$IFDEF MSWINDOWS}
{$IFDEF CPUX86}
if FShell = '' then
begin
// disable for now .... not working 100%
{
// do we have a stray sh.exe in the path ...
if (Length(Which('sh.exe'))>0) then
begin
FShell := GetEnvironmentVariable('COMSPEC');
//ExecuteCommand('cmd.exe /C echo %COMSPEC%', output, False);
//FShell := Trim(output);
if FShell = '' then
begin
//for older Windows versions
ExecuteCommand('ECHO %COMSPEC%', output, False);
FShell := Trim(output);
end;
end;
}
end;
{$ENDIF CPU32}
{$ENDIF MSWINDOWS}
Result := FShell;
end;
procedure TInstaller.SetVerbosity(aValue:boolean);
begin
FVerbose:=aValue;
if Assigned(Processor) then Processor.Verbose:=FVerbose;
{
if Assigned(SVNClient) then SVNClient.Verbose:=FVerbose;
if Assigned(GitClient) then GitClient.Verbose:=FVerbose;
if Assigned(HGClient) then HGClient.Verbose:=FVerbose;
}
end;
procedure TInstaller.SetHTTPProxyHost(AValue: string);
begin
if FHTTPProxyHost=AValue then Exit;
FHTTPProxyHost:=AValue;
if Assigned(GitClient) then GitClient.HTTPProxyHost:=FHTTPProxyHost;
if Assigned(HGClient) then HGClient.HTTPProxyHost:=FHTTPProxyHost;
if Assigned(SVNClient) then SVNClient.HTTPProxyHost:=FHTTPProxyHost;
end;
procedure TInstaller.SetHTTPProxyPassword(AValue: string);
begin
if FHTTPProxyPassword=AValue then Exit;
FHTTPProxyPassword:=AValue;
if Assigned(GitClient) then GitClient.HTTPProxyPassword:=FHTTPProxyPassword;
if Assigned(HGClient) then HGClient.HTTPProxyPassword:=FHTTPProxyPassword;
if Assigned(SVNClient) then SVNClient.HTTPProxyPassword:=FHTTPProxyPassword;
end;
procedure TInstaller.SetHTTPProxyPort(AValue: integer);
begin
if FHTTPProxyPort=AValue then Exit;
FHTTPProxyPort:=AValue;
if Assigned(GitClient) then GitClient.HTTPProxyPort:=FHTTPProxyPort;
if Assigned(HGClient) then HGClient.HTTPProxyPort:=FHTTPProxyPort;
if Assigned(SVNClient) then SVNClient.HTTPProxyPort:=FHTTPProxyPort;
end;
procedure TInstaller.SetHTTPProxyUser(AValue: string);
begin
if FHTTPProxyUser=AValue then Exit;
FHTTPProxyUser:=AValue;
if Assigned(GitClient) then GitClient.HTTPProxyUser:=FHTTPProxyUser;
if Assigned(HGClient) then HGClient.HTTPProxyUser:=FHTTPProxyUser;
if Assigned(SVNClient) then SVNClient.HTTPProxyUser:=FHTTPProxyUser;
end;
function TInstaller.CheckAndGetTools: boolean;
var
OperationSucceeded: boolean;
{$ifdef MSWINDOWS}
aURL,aLocalClientBinary,Output: string;
{$endif}
begin
localinfotext:=Copy(Self.ClassName,2,MaxInt)+' (CheckAndGetTools): ';
OperationSucceeded := true;
if not FNeededExecutablesChecked then
begin
// The extractors used depend on the bootstrap compiler URL/file we download
// todo: adapt extractor based on URL that's being passed (low priority as these will be pretty stable)
{$IFDEF MSWINDOWS}
// Need to do it here so we can pick up make path.
FGunzip := '';
FTar := '';
FUnrar := '';
F7zip := '';
FWget := '';
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
FGunzip := 'gunzip';
if FMUSL then
begin
FGunzip := 'unzip';
end;
FTar := 'tar';
F7zip := '7za';
FWget := 'wget';
FUnrar := 'unrar';
{$ENDIF LINUX}
{$IFDEF BSD} //OSX, *BSD
{$IFDEF DARWIN}
FGunzip := ''; //not really necessary now
FTar := 'bsdtar'; //gnutar is not available by default on Mavericks
F7zip := '7za';
FWget := 'wget';
FUnrar := 'unrar';
{$ELSE} //FreeBSD, OpenBSD, NetBSD
FGunzip := 'gunzip';
FTar := 'tar'; //At least FreeBSD tar apparently takes some gnu tar options nowadays.
F7zip := '7za';
FWget := 'wget';
FUnrar := 'unrar';
{$ENDIF DARWIN}
{$ENDIF BSD}
{$IFDEF MSWINDOWS}
ForceDirectoriesSafe(FMakeDir);
{$ifdef win64}
// the standard make by FPC does not work when Git is present (and in the path), but this one works ??!!
// (but the FPC installer sets its own path to isolate itself from the system, so FPC make still works)
// strange, but do not enable (yet) !!