-
Notifications
You must be signed in to change notification settings - Fork 11
/
installeruniversal.pas
executable file
·3849 lines (3428 loc) · 134 KB
/
installeruniversal.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 installerUniversal;
{ Universal (external) installer unit driven by .ini file directives
Copyright (C) 2012-2013 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+}
{$modeswitch advancedrecords}
{$warn 6058 off}
{$i fpcupdefines.inc}
interface
uses
Classes, SysUtils, installerCore, m_crossinstaller, processutils
{$ifndef FPCONLY}
,updatelazconfig
{$endif}
;
type
{$ifndef FPCONLY}
TAPkgVersion = record
private
FName:string;
FFileVersion:longint;
FMajor: integer;
FMinor: integer;
FRelease: integer;
FBuild: integer;
public
function AsString: string;
procedure GetVersion(alpkdoc:TConfig;key:string);
property Name: string read FName write FName;
property FileVersion: longint read FFileVersion write FFileVersion;
//property Major: integer read FMajor;
//property Minor: integer read FMinor;
//property Release: integer read FRelease;
//property Build: integer read FBuild;
end;
{$endif}
{ TUniversalInstaller }
TUniversalInstaller = class(TBaseUniversalInstaller)
private
FPath:string; //Path to be used within this session (e.g. including compiler path)
InitDone:boolean;
{$ifndef FPCONLY}
// Compiler options chosen by user to build Lazarus. There is a CompilerOptions property,
// but let's leave that for use with FPC.
FLazarusCompilerOptions:string;
// Keep track of whether Lazarus needs to be rebuilt after package installation
// or running lazbuild with an .lpk
FLazarusNeedsRebuild:boolean;
FLazarusVersion:string;
// LCL widget set to be built
FLCL_Platform: string;
function RebuildLazarus:boolean;
{$endif}
protected
// Scans for and adds all packages specified in a (module's) stringlist with commands:
function AddPackages(sl:TStringList): boolean;
// Get a value for a key=value pair. Case-insensitive for keys. Expands macros in values.
function GetValueFromKey(Key:string;sl:TStringList;recursion:integer=0):string;
// internal initialisation, called from BuildModule,CleanModule,GetModule
// and UnInstallModule but executed only once
function InitModule:boolean;
{$ifndef FPCONLY}
// Installs a single package:
function InstallPackage(PackagePath, WorkingDir: string; RegisterOnly:boolean; {%H-}Silent:boolean=false): boolean;
// Scans for and removes all packages specfied in a (module's) stringlist with commands:
function RemovePackages(sl:TStringList): boolean;
// Uninstall a single package:
function UnInstallPackage(PackagePath, WorkingDir: string): boolean;
function GetVersionFromUrl({%H-}aUrl: string): string;override;
function GetVersionFromSource: string;override;
function GetReleaseCandidateFromSource:integer;override;
{$endif}
// Filters (a module's) sl stringlist and runs all <Directive> commands:
function RunCommands(Directive:string;sl:TStringList):boolean;
public
// FPC base directories
property TempDirectory:string read FTempDirectory;
// FPC base directories
property FPCSourceDir:string read FFPCSourceDir;
property FPCInstallDir:string read FFPCInstallDir;
{$ifndef FPCONLY}
// Lazarus base directories
property LazarusSourceDir:string read FLazarusSourceDir;
property LazarusInstallDir:string read FLazarusInstallDir;
// Compiler options user chose to compile Lazarus with (coming from fpcup).
property LazarusCompilerOptions: string write FLazarusCompilerOptions;
// Lazarus primary config path
property LazarusPrimaryConfigPath:string read FLazarusPrimaryConfigPath;
// LCL widget set to be built
property LCL_Platform: string write FLCL_Platform;
property LazarusVersion:string read FLazarusVersion;
{$endif}
// Build module
function BuildModule(ModuleName:string): boolean; override;
// Clean up environment
function CleanModule(ModuleName:string): boolean; override;
// Configure module
function ConfigModule(ModuleName:string): boolean; override;
// Install/update sources (e.g. via svn)
function GetModule(ModuleName:string): boolean; override;
// Uninstall module
function UnInstallModule(ModuleName:string): boolean; override;
end;
{ TmORMotPXLInstaller }
TmORMotPXLInstaller = class(TUniversalInstaller)
public
function BuildModule(ModuleName: string): boolean; override;
end;
{ TAWGGInstaller }
TAWGGInstaller = class(TUniversalInstaller)
public
function BuildModule(ModuleName: string): boolean; override;
end;
{ TPas2jsInstaller }
TPas2jsInstaller = class(TUniversalInstaller)
public
function BuildModule(ModuleName: string): boolean; override;
end;
{ TInternetToolsInstaller }
TInternetToolsInstaller = class(TUniversalInstaller)
public
function GetModule(ModuleName: string): boolean; override;
end;
{ TDeveltools4FPCInstaller }
TDeveltools4FPCInstaller = class(TUniversalInstaller)
public
function GetModule(ModuleName: string): boolean; override;
end;
TXTensaTools4FPCInstaller = class(TUniversalInstaller)
public
function GetModule(ModuleName: string): boolean; override;
end;
{ TMBFFreeRTOSWioInstaller }
TMBFFreeRTOSWioInstaller = class(TUniversalInstaller)
public
function GetModule(ModuleName: string): boolean; override;
end;
{ TmORMot2Installer }
TmORMot2Installer = class(TUniversalInstaller)
public
function GetModule(ModuleName: string): boolean; override;
end;
{ TWSTInstaller }
TWSTInstaller = class(TUniversalInstaller)
public
function GetModule(ModuleName: string): boolean; override;
end;
// Gets the list of modules enabled in ConfigFile. Appends to existing TStringList
function GetModuleEnabledList(var ModuleList:TStringList):boolean;
// Gets the sequence representation for all modules in the ini file
// Used to pass on to higher level code for selection, display etc.
//todo: get Description field into module list
function GetModuleList:string;
// gets keywords for alias in Dictionary.
function GetKeyword(aDictionary,aAlias: string): string;
// gets alias for keywords in Dictionary.
//The keyword 'list' is reserved and returns the list of keywords as commatext
function GetAlias(aDictionary,aKeyword: string): string;
function SetAlias(aDictionary,aKeyWord,aValue: string):boolean;
// check if enabled modules are allowed !
function CheckIncludeModule(ModuleName: string):boolean;
function SetConfigFile(aConfigFile: string):boolean;
var
sequences:string;
UniModuleList:TStringList=nil;
Const
CONFIGFILENAME='fpcup.ini';
SETTTINGSFILENAME='settings.ini';
DELUXEFILENAME='fpcupdeluxe.ini';
INIKEYWORD_NAME='Name';
INIKEYWORD_CATEGORY='Category';
INIKEYWORD_DESCRIPTION='Description';
implementation
uses
StrUtils, typinfo,inifiles, process, fpjson,
FileUtil,
fpcuputil;
Const
MAXSYSMODULES=250;
MAXUSERMODULES=20;
// Allow enough instructions per module:
MAXINSTRUCTIONS=255;
MAXEMPTYINSTRUCTIONS=5;
MAXRECURSIONS=10;
LOCATIONMAGIC='Workingdir';
INSTALLMAGIC='Installdir';
var
CurrentConfigFile:string;
IniGeneralSection:TStringList=nil;
UniModuleEnabledList:TStringlist=nil;
{$ifndef FPCONLY}
function TAPkgVersion.AsString: string;
var
AddValues:boolean;
begin
result:='';
AddValues:=(FBuild>0);
if AddValues then Result:='.'+IntToStr(FBuild)+Result else AddValues:=(FRelease>0);
if AddValues then Result:='.'+IntToStr(FRelease)+Result else AddValues:=(FMinor>0);
if AddValues then Result:='.'+IntToStr(FMinor)+Result;
Result:=IntToStr(FMajor)+Result;
end;
procedure TAPkgVersion.GetVersion(alpkdoc:TConfig;key:string);
begin
FMajor:=alpkdoc.GetValue(key+'Major',0);
FMinor:=alpkdoc.GetValue(key+'Minor',0);
FRelease:=alpkdoc.GetValue(key+'Release',0);
FBuild:=alpkdoc.GetValue(key+'Build',0);
end;
{$endif}
{ TUniversalInstaller }
{$ifndef FPCONLY}
function TUniversalInstaller.RebuildLazarus:boolean;
var
OldPath,s:string;
LazarusConfig: TUpdateLazConfig;
i,j:integer;
begin
result:=false;
FLazarusNeedsRebuild:=false;
Infoln(infotext+'Going to rebuild Lazarus.',etInfo);
Processor.Process.Parameters.Clear;
Processor.Process.CurrentDirectory := ExcludeTrailingPathDelimiter(LazarusSourceDir);
{$push}
{$warn 6018 off}
{$ifdef FORCELAZBUILD}
if false then
{$else}
if true then
{$endif}
begin
Processor.Executable := Make;
Processor.Process.Parameters.Add('--directory=' + Processor.Process.CurrentDirectory);
{$IFDEF MSWINDOWS}
if Length(Shell)>0 then Processor.Process.Parameters.Add('SHELL='+Shell);
{$ENDIF}
{$IF DEFINED(CPUARM) AND DEFINED(LINUX)}
Processor.Process.Parameters.Add('--jobs=1');
{$ELSE}
//Still not clear if jobs can be enabled for Lazarus make builds ... :-|
//if (NOT FNoJobs) then
// Processor.Process.Parameters.Add('--jobs='+IntToStr(FCPUCount));
{$ENDIF}
Processor.Process.Parameters.Add('FPC=' + FCompiler);
Processor.Process.Parameters.Add('PP=' + ExtractFilePath(FCompiler)+GetCompilerName(GetTargetCPU));
Processor.Process.Parameters.Add('USESVN2REVISIONINC=0');
Processor.Process.Parameters.Add('PREFIX='+ExcludeTrailingPathDelimiter(LazarusInstallDir));
Processor.Process.Parameters.Add('INSTALL_PREFIX='+ExcludeTrailingPathDelimiter(LazarusInstallDir));
Processor.Process.Parameters.Add('LAZARUS_INSTALL_DIR='+IncludeTrailingPathDelimiter(LazarusInstallDir));
//Make sure our FPC units can be found by Lazarus
//Processor.Process.Parameters.Add('FPCDIR=' + ExcludeTrailingPathDelimiter(FPCSourceDir));
Processor.Process.Parameters.Add('FPCDIR=' + ExcludeTrailingPathDelimiter(FPCInstallDir));
//Make sure Lazarus does not pick up these tools from other installs
Processor.Process.Parameters.Add('FPCMAKE=' + FFPCCompilerBinPath+'fpcmake'+GetExeExt);
Processor.Process.Parameters.Add('PPUMOVE=' + FFPCCompilerBinPath+'ppumove'+GetExeExt);
s:=IncludeTrailingPathDelimiter(LazarusPrimaryConfigPath)+DefaultIDEMakeOptionFilename;
//if FileExists(s) then
Processor.Process.Parameters.Add('CFGFILE=' + s);
{$IFDEF MSWINDOWS}
Processor.Process.Parameters.Add('UPXPROG=echo'); //Don't use UPX
{$else}
//Processor.Process.Parameters.Add('INSTALL_BINDIR='+FBinPath);
{$ENDIF MSWINDOWS}
if FLCL_Platform <> '' then Processor.Process.Parameters.Add('LCL_PLATFORM=' + FLCL_Platform);
//Set options
s := FLazarusCompilerOptions;
{$ifdef Unix}
{$ifndef Darwin}
{$ifdef LCLQT}
{$endif}
{$ifdef LCLQT5}
// Did we copy the QT5 libs ??
// If so, add some linker help.
if (NOT LibWhich(LIBQT5)) AND (FileExists(IncludeTrailingPathDelimiter(LazarusInstallDir)+LIBQT5)) then
begin
s:=s+' -k"-rpath=./"';
s:=s+' -k"-rpath=$$ORIGIN"';
s:=s+' -k"-rpath=\\$$$$$\\ORIGIN"';
s:=s+' -Fl'+ExcludeTrailingPathDelimiter(LazarusInstallDir);
end;
{$endif}
{$endif}
{$endif}
while Pos(' ',s)>0 do
begin
s:=StringReplace(s,' ',' ',[rfReplaceAll]);
end;
s:=Trim(s);
if Length(s)>0 then Processor.Process.Parameters.Add('OPT='+s);
{$ifdef DISABLELAZBUILDJOBS}
Processor.Process.Parameters.Add('LAZBUILDJOBS=1');//prevent runtime 217 errors
{$else}
Processor.Process.Parameters.Add('LAZBUILDJOBS='+IntToStr(FCPUCount));
{$endif}
Processor.Process.Parameters.Add('useride');
try
{$ifdef MSWindows}
//Prepend FPC binary directory to PATH to prevent pickup of strange tools
OldPath:=Processor.Environment.GetVar(PATHVARNAME);
s:=ExcludeTrailingPathDelimiter(FFPCCompilerBinPath);
if OldPath<>'' then
Processor.Environment.SetVar(PATHVARNAME, s+PathSeparator+OldPath)
else
Processor.Environment.SetVar(PATHVARNAME, s);
{$endif}
ProcessorResult:=Processor.ExecuteAndWait;
result := (ProcessorResult=0);
if result then
begin
Infoln(infotext+'Lazarus rebuild succeeded',etDebug);
end
else
WritelnLog(etError,infotext+'Failure trying to rebuild Lazarus. '+LineEnding+
'Details: '+FErrorLog.Text,true);
{$ifdef MSWindows}
Processor.Environment.SetVar(PATHVARNAME, OldPath);
{$endif}
except
on E: Exception do
begin
result:=false;
WritelnLog(etError, infotext+'Exception trying to rebuild Lazarus '+LineEnding+
'Details: '+E.Message,true);
end;
end;
end
else
begin
Processor.Executable := IncludeTrailingPathDelimiter(LazarusInstallDir)+LAZBUILDNAME+GetExeExt;
OldPath:=Processor.Environment.GetVar('FPCDIR');
Processor.Environment.SetVar('FPCDIR',ExcludeTrailingPathDelimiter(FFPCSourceDir));
{$IFDEF DEBUG}
Processor.Process.Parameters.Add('--verbose');
{$ELSE}
// See compileroptions.pp
// Quiet:=ConsoleVerbosity<=-3;
Processor.Process.Parameters.Add('--quiet');
{$ENDIF}
{$ifdef DISABLELAZBUILDJOBS}
Processor.Process.Parameters.Add('--max-process-count=1');
{$else}
Processor.Process.Parameters.Add('--max-process-count='+IntToStr(FCPUCount));
{$endif}
Processor.Process.Parameters.Add('--pcp=' + DoubleQuoteIfNeeded(LazarusPrimaryConfigPath));
Processor.Process.Parameters.Add('--cpu=' + GetTargetCPU);
Processor.Process.Parameters.Add('--os=' + GetTargetOS);
if FLCL_Platform <> '' then
Processor.Process.Parameters.Add('--ws=' + FLCL_Platform);
Processor.Process.Parameters.Add('--build-ide=-dKeepInstalledPackages ' + FCompilerOptions);
//Processor.Process.Parameters.Add('--build-ide= ' + FCompilerOptions);
//Processor.Process.Parameters.Add('--build-mode="Normal IDE"');
Infoln(infotext+'Running lazbuild to get IDE with user-specified packages', etInfo);
try
ProcessorResult:=Processor.ExecuteAndWait;
result := (ProcessorResult=0);
//Restore FPCDIR environment variable ... could be trivial, but better safe than sorry
Processor.Environment.SetVar('FPCDIR',OldPath);
if (NOT result) then
begin
WritelnLog(etError, infotext+ExtractFileName(Processor.Executable)+' returned error code ' + IntToStr(ProcessorResult) + LineEnding +
'Details: ' + FErrorLog.Text, true);
end;
except
on E: Exception do
begin
result := false;
WritelnLog(etError, infotext+'Exception running '+ExtractFileName(Processor.Executable)+' to get IDE with user-specified packages!' + LineEnding +
'Details: ' + E.Message, true);
end;
end;
end;
{$pop}
//We now have, for certain, a miscellaneousoptions.xml file.
//This file has been generated by lazbuild..
//Edit it to reflect our own settings, if needed.
LazarusConfig:=TUpdateLazConfig.Create(LazarusPrimaryConfigPath);
try
i:=LazarusConfig.GetVariable(MiscellaneousConfig, 'MiscellaneousOptions/BuildLazarusOptions/Profiles/Count',0);
if i>0 then
begin
// Change the build modes to reflect the options set.
j:=LazarusConfig.GetVariable(MiscellaneousConfig, 'MiscellaneousOptions/BuildLazarusOptions/Profiles/Profile0/Options/Count', 0);
s:=Trim(FLazarusCompilerOptions);
if ((j=0) AND (Length(s)>0)) then
begin
LazarusConfig.SetVariable(MiscellaneousConfig, 'MiscellaneousOptions/BuildLazarusOptions/Profiles/Profile0/Options/Count', 1);
LazarusConfig.SetVariable(MiscellaneousConfig, 'MiscellaneousOptions/BuildLazarusOptions/Profiles/Profile0/Options/Item1/Value', Trim(FLazarusCompilerOptions));
end;
if Length(FLCL_Platform)>0 then
begin
// Change the build modes to reflect the default LCL widget set.
for j:=0 to (i-1) do
begin
Infoln(infotext+'Changing default LCL_platforms for build-profiles in '+MiscellaneousConfig+' to build for '+FLCL_Platform, etInfo);
LazarusConfig.SetVariable(MiscellaneousConfig, 'MiscellaneousOptions/BuildLazarusOptions/Profiles/Profile'+InttoStr(j)+'/LCLPlatform/Value', FLCL_Platform);
end;
end;
end;
finally
LazarusConfig.Free;
end;
end;
{$endif}
function TUniversalInstaller.GetValueFromKey(Key: string; sl: TStringList;
recursion: integer): string;
// Look for entries with Key and process macros etc in value
var
i,len:integer;
s,macro:string;
doublequote:boolean;
begin
Key:=UpperCase(Key);
s:='';
if recursion=MAXRECURSIONS then
exit;
for i:=0 to sl.Count-1 do
begin
s:=sl[i];
if (copy(UpperCase(s),1, length(Key))=Key) and ((s[length(Key)+1]='=') or (s[length(Key)+1]=' ')) then
begin
if Pos('=',s)>0 then
s:=trim(copy(s,pos('=',s)+1,length(s)));
break;
end;
s:='';
end;
if s='' then //search general section
for i:=0 to IniGeneralSection.Count-1 do
begin
s:=IniGeneralSection[i];
if (copy(UpperCase(s),1, length(Key))=Key) and ((s[length(Key)+1]='=') or
(s[length(Key)+1]=' ')) then
begin
if Pos('=',s)>0 then
s:=trim(copy(s,pos('=',s)+1,length(s)));
break;
end;
s:='';
end;
//expand macros
doublequote:=true;
if s<>'' then
while Pos('$(',s)>0 do
begin
i:=pos('$(',s);
macro:=copy(s,i+2,length(s));
if Pos(')',macro)>0 then
begin
delete(macro,pos(')',macro),length(macro));
macro:=UpperCase(macro);
len:=length(macro)+3; // the brackets
// For the directory macros, the user expects to add path separators himself in fpcup.ini,
// so strip them out if they are there.
if macro='BASEDIR' then
macro:=ExcludeTrailingPathDelimiter(BaseDirectory)
else if macro='FPCDIR' then
macro:=ExcludeTrailingPathDelimiter(FPCInstallDir)
else if macro='FPCBINDIR' then
macro:=ExcludeTrailingPathDelimiter(FFPCCompilerBinPath)
else if macro='FPCBIN' then
macro:=ExcludeTrailingPathDelimiter(FCompiler)
else if macro='TOOLDIR' then
{$IFDEF MSWINDOWS}
// make is a binutil and should be located in the make dir
macro:=ExcludeTrailingPathDelimiter(FMakeDir)
{$ENDIF}
{$IFDEF UNIX}
// Strip can be anywhere in the path
macro:=ExcludeTrailingPathDelimiter(ExtractFilePath(Which('make')))
{$ENDIF}
else if macro='GETEXEEXT' then
macro:=GetExeExt
{$ifndef FPCONLY}
else if macro='LAZARUSDIR' then
macro:=ExcludeTrailingPathDelimiter(FLazarusInstallDir)
else if macro='LAZARUSPRIMARYCONFIGPATH' then
macro:=ExcludeTrailingPathDelimiter(FLazarusPrimaryConfigPath)
{$endif}
else if macro='STRIPDIR' then
{$IFDEF MSWINDOWS}
// Strip is a binutil and should be located in the make dir
macro:=ExcludeTrailingPathDelimiter(FMakeDir)
{$ENDIF}
{$IFDEF UNIX}
// Strip can be anywhere in the path
macro:=ExcludeTrailingPathDelimiter(ExtractFilePath(Which('strip')))
{$ENDIF}
else if macro='REMOVEDIRECTORY' then
begin
doublequote:=false;
{$IFDEF MSWINDOWS}
macro:='cmd /c rmdir /s /q';
{$ENDIF}
{$IFDEF UNIX}
macro:='rm -Rf';
{$ENDIF}
end
else if macro='TERMINAL' then
begin
doublequote:=false;
{$ifdef MSWINDOWS}
macro:=GetEnvironmentVariable('COMSPEC');
if NOT FileExists(macro) then macro:='c:\windows\system32\cmd.exe';
if NOT FileExists(macro) then macro:='' else macro:=macro+' /c';
{$endif MSWINDOWS}
{$ifdef UNIX}
macro := '/bin/sh';
if NOT FileExists(macro) then macro:='' else macro:=macro+' -c';
{$endif UNIX}
end
else if macro='REMOVEINSTALLDIRECTORY' then
begin
doublequote:=false;
{$IFDEF MSWINDOWS}
macro:='cmd /c rmdir '+'$(Installdir)'+' /s /q';
{$ENDIF}
{$IFDEF UNIX}
macro:='rm -Rf '+'$(Installdir)';
{$ENDIF}
end
else macro:=GetValueFromKey(macro,sl,recursion+1); //user defined value
// quote if containing spaces
if doublequote then
begin
//if Pos(' ',macro)>0 then macro:='"'+macro+'"';
macro:=MaybeQuoted(macro);
end;
delete(s,i,len);
insert(macro,s,i);
end;
end;
// correct path delimiter
if (pos('URL',Key)<=0) and (pos('ADDTO',Key)<>1)then
begin
{$IFDEF MSWINDOWS}
len:=2;
{$ELSE}
len:=1;
{$ENDIF}
//DoDirSeparators(s);
for i:=len to length(s) do
if (s[i] in ['/','\']){$IFDEF MSWINDOWS} AND (s[i-1]<>' '){$ENDIF} then
s[i]:=DirectorySeparator;
end;
result:=s;
end;
function TUniversalInstaller.InitModule: boolean;
begin
result:=true;
localinfotext:=InitInfoText(' (InitModule): ');
Infoln(localinfotext+'Entering ...',etDebug);
if InitDone then exit;
// While getting svn etc may help a bit, if Lazarus isn't installed correctly,
// it probably won't help for normal use cases.
// However, in theory, we could run only external modules and
// only download some SVN repositories
// So.. enable this.
result:=(CheckAndGetTools) AND (CheckAndGetNeededBinUtils);
if not(result) then
Infoln(localinfotext+'Missing required executables. Aborting.',etError);
// Need to remember because we don't always use ProcessEx
FPath:=ExcludeTrailingPathDelimiter(FFPCCompilerBinPath)+PathSeparator+
{$IFDEF MSWINDOWS}
FMakeDir+PathSeparator+
{$ENDIF MSWINDOWS}
{$IFDEF DARWIN}
// pwd is located in /bin ... the makefile needs it !!
// tools are located in /usr/bin ... the makefile needs it !!
// don't ask, but this is needed when fpcupdeluxe runs out of an .app package ... quirk solved this way .. ;-)
'/bin'+PathSeparator+'/usr/bin'+PathSeparator+
{$ENDIF}
ExcludeTrailingPathDelimiter(FPCInstallDir)+PathSeparator;
SetPath(FPath,true,false);
// No need to build Lazarus IDE again right now; will
// be changed by buildmodule/configmodule installexecute/
// installpackage
{$ifndef FPCONLY}
FLazarusNeedsRebuild:=false;
FLazarusVersion:=GetVersion;
{$endif}
InitDone:=result;
end;
{$ifndef FPCONLY}
function TUniversalInstaller.InstallPackage(PackagePath, WorkingDir: string; RegisterOnly:boolean; Silent:boolean=false): boolean;
var
PackageName,PackageAbsolutePath: string;
Path: String;
lpkdoc:TConfig;
lpkversion:TAPkgVersion;
TxtFile:TextFile;
RegisterPackageFeature:boolean;
i,ReqCount:integer;
ReqPackage:string;
PackageFiles: TStringList;
begin
result:=false;
localinfotext:=InitInfoText(' (InstallPackage): ');
PackageName:=FileNameWithoutExt(PackagePath);
// Convert any relative path to absolute path, if it's not just a file/package name:
if ExtractFileName(PackagePath)=PackagePath then
// we have a relative path or packagename: let Lazarus handle it
PackageAbsolutePath:=PackagePath
else
// Just use absolute path
PackageAbsolutePath:=SafeExpandFileName(PackagePath);
// find a package component, if any
// all other packages will be ignored
if ( (NOT FileExists(PackageAbsolutePath)) AND (Length(WorkingDir)>0) AND DirectoryExists(WorkingDir) ) then
begin
PackageFiles:=FindAllFiles(WorkingDir, PackageName+'.lpk' , true);
if PackageFiles.Count>0 then PackageAbsolutePath:=PackageFiles.Strings[0];
PackageFiles.Free;
end;
// find a Lazarus component, if any
// all other packages will be ignored
if (NOT FileExists(PackageAbsolutePath)) then
begin
PackageFiles:=FindAllFiles(IncludeTrailingPathDelimiter(LazarusInstallDir)+'components', PackageName+'.lpk' , true);
if PackageFiles.Count>0 then PackageAbsolutePath:=PackageFiles.Strings[0];
PackageFiles.Free;
end;
// find an OPM component, if any
// all other packages will be ignored
if (NOT FileExists(PackageAbsolutePath)) then
begin
PackageFiles:=FindAllFiles(IncludeTrailingPathDelimiter(LazarusPrimaryConfigPath)+'onlinepackagemanager'+DirectorySeparator+'packages', PackageName+'.lpk' , true);
if PackageFiles.Count>0 then PackageAbsolutePath:=PackageFiles.Strings[0];
PackageFiles.Free;
end;
// find a fpcupdeluxe ccr component, if any
// all other packages will be ignored
{
Path:=IncludeTrailingPathDelimiter(BaseDirectory)+'ccr';
if ( (NOT FileExists(PackageAbsolutePath)) AND DirectoryExists(Path) ) then
begin
PackageFiles:=FindAllFiles(Path, PackageName+'.lpk' , true);
if PackageFiles.Count>0 then PackageAbsolutePath:=PackageFiles.Strings[0];
PackageFiles.Free;
end;
}
lpkversion.Name:='unknown';
if FileExists(PackageAbsolutePath) then
begin
lpkdoc:=TConfig.Create(PackageAbsolutePath);
try
// if only a filename (without path) is given, then lazarus will handle everything by itself
// set lpkversion.Name to 'unknown' to flag this case
// if not, get some extra info from package file !!
if (ExtractFileName(PackagePath)<>PackagePath) then
begin
Path:='Package/';
lpkversion.FileVersion:=lpkdoc.GetValue(Path+'Version',0);
Path:='Package/Name/';
lpkversion.Name:=lpkdoc.GetValue(Path+'Value','unknown');
Path:='Package/Version/';
lpkversion.GetVersion(lpkdoc,Path);
end;
// get package requirements
Path:='Package/RequiredPkgs/';
ReqCount:=lpkdoc.GetValue(Path+'Count',0);
for i:=1 to ReqCount do
begin
Path:='Package/RequiredPkgs/';
ReqPackage:=lpkdoc.GetValue(Path+'Item'+InttoStr(i)+'/PackageName/Value','unknown');
// try to auto-resolve dependencies, but skip trivial packages
// not very elegant, but working
if (ReqPackage<>'unknown') AND
(ReqPackage<>'LCL') AND
(ReqPackage<>'LazControls') AND
(ReqPackage<>'IDEIntf') AND
(ReqPackage<>'FCL') AND
(ReqPackage<>'LCLBase') AND
(ReqPackage<>'LazControlDsgn') AND
(ReqPackage<>'LazUtils') AND
(ReqPackage<>'cairocanvas_pkg') AND
(ReqPackage<>'SynEdit') AND
(ReqPackage<>'DebuggerIntf') AND
(ReqPackage<>'LazDebuggerGdbmi') AND
(ReqPackage<>'CodeTools') then
begin
InstallPackage(ReqPackage, WorkingDir, RegisterOnly, true);
end;
end;
finally
lpkdoc.Free;
end;
end;
//if (NOT Silent){ OR FVerbose} then
begin
if lpkversion.Name='unknown'
then WritelnLog(localinfotext+'Installing '+PackageName,True)
else WritelnLog(localinfotext+'Installing '+PackageName+' version '+lpkversion.AsString,True);
end;
Processor.Executable := IncludeTrailingPathDelimiter(LazarusInstallDir)+LAZBUILDNAME+GetExeExt;
RegisterPackageFeature:=false;
// get lazbuild version to see if we can register packages (available from version 1.7 and up)
Processor.Process.Parameters.Clear;
Processor.Process.Parameters.Add('--version');
try
ProcessorResult:=Processor.ExecuteAndWait;
result := (ProcessorResult=0);
if result then
begin
if Processor.WorkerOutput.Count>0 then
RegisterPackageFeature:=(CalculateNumericalVersion(Processor.WorkerOutput.Strings[Processor.WorkerOutput.Count-1])>=CalculateFullVersion(1,7,0));
end;
except
on E: Exception do
begin
result:=false;
WritelnLog(localinfotext+'Exception trying to getting lazbuild version. Details: '+E.Message,true);
end;
end;
if (NOT result) then
begin
WritelnLog(localinfotext+'Error trying to add package '+PackageName,true);
exit;
end;
if RegisterPackageFeature then RegisterPackageFeature:=RegisterOnly;
Processor.Process.Parameters.Clear;
FErrorLog.Clear;
if WorkingDir<>'' then
Processor.Process.CurrentDirectory:=ExcludeTrailingPathDelimiter(WorkingDir);
Processor.Process.Parameters.Clear;
{$IFDEF DEBUG}
Processor.Process.Parameters.Add('--verbose');
{$ELSE}
Processor.Process.Parameters.Add('--quiet');
{$ENDIF}
Processor.Process.Parameters.Add('--pcp=' + DoubleQuoteIfNeeded(FLazarusPrimaryConfigPath));
Processor.Process.Parameters.Add('--cpu=' + GetTargetCPU);
Processor.Process.Parameters.Add('--os=' + GetTargetOS);
if FLCL_Platform <> '' then
Processor.Process.Parameters.Add('--ws=' + FLCL_Platform);
if RegisterPackageFeature then
Processor.Process.Parameters.Add('--add-package-link')
else
Processor.Process.Parameters.Add('--add-package');
Processor.Process.Parameters.Add(DoubleQuoteIfNeeded(PackageAbsolutePath));
try
ProcessorResult:=Processor.ExecuteAndWait;
result := (ProcessorResult=0);
// runtime packages will return false, but output will have info about package being "only for runtime"
if result then
begin
if (NOT RegisterPackageFeature) then
begin
Infoln('Marking Lazarus for rebuild based on package install for '+PackageAbsolutePath,etDebug);
FLazarusNeedsRebuild:=true; //Mark IDE for rebuild
end;
end
else
begin
// if the package is only for runtime, just add an lpl file to inform Lazarus of its existence and location ->> set result to true
if (Pos('only for runtime',Processor.WorkerOutput.Text)>0) OR (RegisterPackageFeature) OR (ProcessorResult=4)
then result:=True
else WritelnLog(localinfotext+'Error trying to add package '+PackageName+'. Details: '+FErrorLog.Text,true);
end;
except
on E: Exception do
begin
WritelnLog(localinfotext+'Exception trying to add package '+PackageName+'. Details: '+E.Message,true);
end;
end;
// all ok AND a filepath is given --> check / add lpl file to inform Lazarus of package excistence and location
// if only a filename (without path) is given, then lazarus will handle everything (including lpl) by itself
// in fact, we cannot do anything in that case : we do not know anything about the package !
if (result) AND (lpkversion.Name<>'unknown') then
begin
if FVerbose then WritelnLog(localinfotext+'Checking lpl file for '+PackageName,true);
Path := ConcatPaths([LazarusInstallDir,'packager','globallinks'])+DirectorySeparator+LowerCase(lpkversion.Name)+'-'+lpkversion.AsString+'.lpl';
if NOT FileExists(Path) then
begin
AssignFile(TxtFile,Path);
try
Rewrite(TxtFile);
writeln(TxtFile,PackageAbsolutePath);
finally
CloseFile(TxtFile);
end;
if FVerbose then WritelnLog(localinfotext+'Created lpl file ('+Path+') with contents: '+PackageAbsolutePath,true);
end;
end;
end;
function TUniversalInstaller.RemovePackages(sl: TStringList): boolean;
const
// The command that will be processed:
Directive='AddPackage';
var
Failure: boolean;
i:integer;
RealDirective:string;
PackagePath:string;
Workingdir:string;
BaseWorkingdir:string;
RegisterOnly:boolean;
begin
Failure:=false;
localinfotext:=InitInfoText(' (RemovePackages): ');
BaseWorkingdir:=GetValueFromKey(LOCATIONMAGIC,sl);
if BaseWorkingdir='' then BaseWorkingdir:=GetValueFromKey(INSTALLMAGIC,sl);
BaseWorkingdir:=FixPath(BaseWorkingdir);
Workingdir:=BaseWorkingdir;
for RegisterOnly:=false to true do
begin
// Go backward; reverse order to deal with any dependencies
for i:=MAXINSTRUCTIONS downto -1 do
begin
if RegisterOnly then
RealDirective:=Directive+'Link'
else
RealDirective:=Directive;
if i>=0 then
begin
RealDirective:=RealDirective+IntToStr(i);
Workingdir:=GetValueFromKey(LOCATIONMAGIC+IntToStr(i),sl);
Workingdir:=FixPath(Workingdir);
end else
begin
Workingdir:=BaseWorkingdir;
end;
PackagePath:=GetValueFromKey(RealDirective,sl);
PackagePath:=FixPath(PackagePath);
// Skip over missing data or if no AddPackage is defined
if (PackagePath='') then continue;
if Workingdir='' then Workingdir:=BaseWorkingdir;
if NOT FileExists(PackagePath) then
begin
Infoln(localinfotext+'Package '+ExtractFileName(PackagePath)+' not found ... skipping.',etInfo);
UnInstallPackage(PackagePath, WorkingDir);
continue;
end;
// Try to uninstall everything, even if some of these fail.
if UnInstallPackage(PackagePath, WorkingDir)=false then Failure:=true;
end;
result:=Failure;
end;
end;
{$endif}
function TUniversalInstaller.AddPackages(sl:TStringList): boolean;
const
// The command that will be processed:
Directive='AddPackage';
NAMEMAGIC='Name';
var
i:integer;
s,s2:string;
PackagePath:string;
ModuleName:string;
Workingdir:string;
BaseWorkingdir:string;
RealDirective:string;
RegisterOnly:boolean;
ReadyCounter:integer;
{$ifndef FPCONLY}
LazarusConfig:TUpdateLazConfig;
LegacyList:boolean;
ListCount:integer;
{$endif}
begin
BaseWorkingdir:=GetValueFromKey(LOCATIONMAGIC,sl);
if BaseWorkingdir='' then BaseWorkingdir:=GetValueFromKey(INSTALLMAGIC,sl);;
BaseWorkingdir:=FixPath(BaseWorkingdir);
Workingdir:=BaseWorkingdir;
ModuleName:=GetValueFromKey(NAMEMAGIC,sl);
localinfotext:=InitInfoText(' (AddPackages of '+ModuleName+'): ');
for RegisterOnly:=false to true do
begin
//Reset ready counter
ReadyCounter:=0;