|
@@ -20,86 +20,102 @@ uses Classes, Sysutils, Inifiles, fprepos;
|
|
|
|
|
|
Const
|
|
|
DefaultManifestFile = 'manifest.xml';
|
|
|
+ CurrentConfigVersion = '0.1';
|
|
|
|
|
|
Type
|
|
|
|
|
|
- { TPackagerOptions }
|
|
|
+ { TGlobalOptions }
|
|
|
|
|
|
- TPackagerOptions = Class(TPersistent)
|
|
|
+ TGlobalOptions = Class(TPersistent)
|
|
|
private
|
|
|
- FDirty: Boolean;
|
|
|
- // Global options
|
|
|
- FRemoteMirrorsLocation : String;
|
|
|
- FLocalMirrorsLocation : String;
|
|
|
- FRemoteRepository : String;
|
|
|
- FLocalRepository : String;
|
|
|
+ FDirty : Boolean;
|
|
|
+ FConfigVersion,
|
|
|
+ FRemoteMirrorsLocation,
|
|
|
+ FLocalMirrorsLocation,
|
|
|
+ FRemoteRepository,
|
|
|
+ FLocalRepository,
|
|
|
FCompilerConfigDir,
|
|
|
FPackagesDir,
|
|
|
- FBuildDir : String;
|
|
|
+ FBuildDir,
|
|
|
FDefaultVerbosity,
|
|
|
- FCurrentCompilerConfig,
|
|
|
- FDefaultCompilerConfig : String;
|
|
|
- // Compiler specific options
|
|
|
- FCompiler : String;
|
|
|
- FCompilerCPU: TCPU;
|
|
|
- FCompilerOS: TOS;
|
|
|
- FCompilerVersion : String;
|
|
|
- FLocalInstallDir,
|
|
|
- FGlobalInstallDir : String;
|
|
|
- // Compiler settings for compiling FPMake.pp
|
|
|
- FFPMakeCompiler,
|
|
|
- FFPMakeLocalUnitDir,
|
|
|
- FFPMakeGlobalUnitDir : String;
|
|
|
+ FDefaultCompilerConfig,
|
|
|
+ FFPMakeCompilerConfig : String;
|
|
|
// Parameter options
|
|
|
- FBootStrap : Boolean;
|
|
|
- FInstallGlobal : Boolean;
|
|
|
- function GetOptString(Index: integer): String;
|
|
|
+ FCompilerConfig : String;
|
|
|
+ FInstallGlobal : Boolean;
|
|
|
+ function GetOptString(Index: integer): String;
|
|
|
procedure SetOptString(Index: integer; const AValue: String);
|
|
|
- procedure SetCompilerCPU(const AValue: TCPU);
|
|
|
- procedure SetCompilerOS(const AValue: TOS);
|
|
|
Public
|
|
|
Constructor Create;
|
|
|
Procedure InitGlobalDefaults;
|
|
|
Procedure LoadGlobalFromIni(Ini : TCustomIniFile); virtual;
|
|
|
Procedure SaveGlobalToIni(Ini : TCustomIniFile); virtual;
|
|
|
- Procedure LoadGlobalFromFile(FileName : String);
|
|
|
- Procedure SaveGlobalToFile(FileName : String);
|
|
|
- Procedure InitCompilerDefaults;
|
|
|
- Procedure LoadCompilerFromIni(Ini : TCustomIniFile); virtual;
|
|
|
- Procedure SaveCompilerToIni(Ini : TCustomIniFile); virtual;
|
|
|
- Procedure LoadCompilerFromFile(FileName : String);
|
|
|
- Procedure SaveCompilerToFile(FileName : String);
|
|
|
+ Procedure LoadGlobalFromFile(const AFileName : String);
|
|
|
+ Procedure SaveGlobalToFile(const AFileName : String);
|
|
|
Property Dirty : Boolean Read FDirty;
|
|
|
+ Property ConfigVersion : String read FConfigVersion;
|
|
|
function RemotePackagesFile:string;
|
|
|
function LocalPackagesFile:string;
|
|
|
- function LocalVersionsFile(CompilerConfig:String):string;
|
|
|
+ function LocalVersionsFile(const ACompilerConfig:String):string;
|
|
|
Published
|
|
|
Property RemoteMirrorsLocation : String Index 0 Read GetOptString Write SetOptString;
|
|
|
Property LocalMirrorsLocation : String Index 1 Read GetOptString Write SetOptString;
|
|
|
Property RemoteRepository : String Index 2 Read GetOptString Write SetOptString;
|
|
|
Property LocalRepository : String Index 3 Read GetOptString Write SetOptString;
|
|
|
- Property BuildDir : String Index 5 Read GetOptString Write SetOptString;
|
|
|
- Property Compiler : String Index 6 Read GetOptString Write SetOptString;
|
|
|
- Property CompilerTarget : String Index 7 Read GetOptString Write SetOptString;
|
|
|
+ Property BuildDir : String Index 4 Read GetOptString Write SetOptString;
|
|
|
+ Property PackagesDir : String Index 5 Read GetOptString Write SetOptString;
|
|
|
+ Property CompilerConfigDir : String Index 6 Read GetOptString Write SetOptString;
|
|
|
+ Property DefaultVerbosity : String Index 7 Read GetOptString Write SetOptString;
|
|
|
Property DefaultCompilerConfig : String Index 8 Read GetOptString Write SetOptString;
|
|
|
- Property CompilerVersion : String Index 9 Read GetOptString Write SetOptString;
|
|
|
- Property GlobalInstallDir : String Index 10 Read GetOptString Write SetOptString;
|
|
|
- Property LocalInstallDir : String Index 11 Read GetOptString Write SetOptString;
|
|
|
- Property DefaultVerbosity : String Index 12 Read GetOptString Write SetOptString;
|
|
|
- Property PackagesDir : String Index 13 Read GetOptString Write SetOptString;
|
|
|
- Property CompilerConfigDir : String Index 14 Read GetOptString Write SetOptString;
|
|
|
- Property FPMakeCompiler : String Index 15 Read GetOptString Write SetOptString;
|
|
|
- Property FPMakeGlobalUnitDir : String Index 16 Read GetOptString Write SetOptString;
|
|
|
- Property FPMakeLocalUnitDir : String Index 17 Read GetOptString Write SetOptString;
|
|
|
- Property CurrentCompilerConfig : String Index 18 Read GetOptString Write SetOptString;
|
|
|
+ Property FPMakeCompilerConfig : String Index 9 Read GetOptString Write SetOptString;
|
|
|
+ // Parameters
|
|
|
+ Property CompilerConfig : String Read FCompilerConfig Write FCompilerConfig;
|
|
|
+ Property InstallGlobal : Boolean Read FInstallGlobal Write FInstallGlobal;
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
+ { TCompilerOptions }
|
|
|
+
|
|
|
+ TCompilerOptions = Class(TPersistent)
|
|
|
+ private
|
|
|
+ FDirty: Boolean;
|
|
|
+ FConfigVersion,
|
|
|
+ FCompiler,
|
|
|
+ FCompilerVersion,
|
|
|
+ FLocalInstallDir,
|
|
|
+ FGlobalInstallDir : String;
|
|
|
+ FCompilerCPU: TCPU;
|
|
|
+ FCompilerOS: TOS;
|
|
|
+ function GetOptString(Index: integer): String;
|
|
|
+ procedure SetOptString(Index: integer; const AValue: String);
|
|
|
+ procedure SetCompilerCPU(const AValue: TCPU);
|
|
|
+ procedure SetCompilerOS(const AValue: TOS);
|
|
|
+ Public
|
|
|
+ Constructor Create;
|
|
|
+ Procedure InitCompilerDefaults;
|
|
|
+ Procedure LoadCompilerFromIni(Ini : TCustomIniFile); virtual;
|
|
|
+ Procedure SaveCompilerToIni(Ini : TCustomIniFile); virtual;
|
|
|
+ Procedure LoadCompilerFromFile(const AFileName : String);
|
|
|
+ Procedure SaveCompilerToFile(const AFileName : String);
|
|
|
+ Property Dirty : Boolean Read FDirty;
|
|
|
+ Property ConfigVersion : String read FConfigVersion;
|
|
|
+ Function LocalUnitDir:string;
|
|
|
+ Function GlobalUnitDir:string;
|
|
|
+ Published
|
|
|
+ Property Compiler : String Index 1 Read GetOptString Write SetOptString;
|
|
|
+ Property CompilerTarget : String Index 2 Read GetOptString Write SetOptString;
|
|
|
+ Property CompilerVersion : String Index 3 Read GetOptString Write SetOptString;
|
|
|
+ Property GlobalInstallDir : String Index 4 Read GetOptString Write SetOptString;
|
|
|
+ Property LocalInstallDir : String Index 5 Read GetOptString Write SetOptString;
|
|
|
Property CompilerOS : TOS Read FCompilerOS Write SetCompilerOS;
|
|
|
Property CompilerCPU : TCPU Read FCompilerCPU Write SetCompilerCPU;
|
|
|
- Property BootStrap : Boolean Read FBootStrap Write FBootStrap;
|
|
|
- Property InstallGlobal : Boolean Read FInstallGlobal Write FInstallGlobal;
|
|
|
end;
|
|
|
|
|
|
var
|
|
|
- Options : TPackagerOptions;
|
|
|
+ GlobalOptions : TGlobalOptions;
|
|
|
+ CompilerOptions : TCompilerOptions;
|
|
|
+ FPMakeCompilerOptions : TCompilerOptions;
|
|
|
+
|
|
|
|
|
|
Implementation
|
|
|
|
|
@@ -122,16 +138,21 @@ Const
|
|
|
// ini file keys
|
|
|
SDefaults = 'Defaults';
|
|
|
|
|
|
+ // All configs
|
|
|
+ KeyConfigVersion = 'ConfigVersion';
|
|
|
+
|
|
|
// Global config
|
|
|
KeyLocalMirrorsLocation = 'LocalMirrors';
|
|
|
KeyRemoteMirrorsLocation = 'RemoteMirrors';
|
|
|
KeyRemoteRepository = 'RemoteRepository';
|
|
|
KeyLocalRepository = 'LocalRepository';
|
|
|
- KeyCompilerConfigDir = 'CompilerConfigDir';
|
|
|
KeyPackagesDir = 'PackagesDir';
|
|
|
KeyBuildDir = 'BuildDir';
|
|
|
- KeyCompilerConfig = 'CompilerConfig';
|
|
|
+ KeyCompilerConfigDir = 'CompilerConfigDir';
|
|
|
KeyVerbosity = 'Verbosity';
|
|
|
+ KeyCompilerConfig = 'CompilerConfig';
|
|
|
+ KeyFPMakeCompilerConfig = 'FPMakeCompilerConfig';
|
|
|
+
|
|
|
// Compiler dependent config
|
|
|
KeyGlobalInstallDir = 'GlobalInstallDir';
|
|
|
KeyLocalInstallDir = 'LocalInstallDir';
|
|
@@ -139,44 +160,37 @@ Const
|
|
|
KeyCompilerOS = 'OS';
|
|
|
KeyCompilerCPU = 'CPU';
|
|
|
KeyCompilerVersion = 'Version';
|
|
|
- KeyFPMakeCompiler = 'FPMakeCompiler';
|
|
|
- KeyFPMakeGlobalUnitDir = 'FPMakeGlobalUnitDir';
|
|
|
- KeyFPMakeLocalUnitDir = 'FPMakeLocalUnitDir';
|
|
|
|
|
|
|
|
|
-{ TPackagerOptions }
|
|
|
+{*****************************************************************************
|
|
|
+ TGlobalOptions
|
|
|
+*****************************************************************************}
|
|
|
|
|
|
-constructor TPackagerOptions.Create;
|
|
|
+constructor TGlobalOptions.Create;
|
|
|
begin
|
|
|
InitGlobalDefaults;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-function TPackagerOptions.GetOptString(Index: integer): String;
|
|
|
+function TGlobalOptions.GetOptString(Index: integer): String;
|
|
|
begin
|
|
|
Case Index of
|
|
|
0 : Result:=FRemoteMirrorsLocation;
|
|
|
1 : Result:=FLocalMirrorsLocation;
|
|
|
2 : Result:=FRemoteRepository;
|
|
|
3 : Result:=FLocalRepository;
|
|
|
- 5 : Result:=FBuildDir;
|
|
|
- 6 : Result:=FCompiler;
|
|
|
- 7 : Result:=MakeTargetString(CompilerCPU,CompilerOS);
|
|
|
+ 4 : Result:=FBuildDir;
|
|
|
+ 5 : Result:=FPackagesDir;
|
|
|
+ 6 : Result:=FCompilerConfigDir;
|
|
|
+ 7 : Result:=FDefaultVerbosity;
|
|
|
8 : Result:=FDefaultCompilerConfig;
|
|
|
- 9 : Result:=FCompilerVersion;
|
|
|
- 10 : Result:=FGlobalInstallDir;
|
|
|
- 11 : Result:=FLocalInstallDir;
|
|
|
- 12 : Result:=FDefaultVerbosity;
|
|
|
- 13 : Result:=FPackagesDir;
|
|
|
- 14 : Result:=FCompilerConfigDir;
|
|
|
- 15 : Result:=FFPMakeCompiler;
|
|
|
- 16 : Result:=FFPMakeGlobalUnitDir;
|
|
|
- 17 : Result:=FFPMakeLocalUnitDir;
|
|
|
- 18 : Result:=FCurrentCompilerConfig;
|
|
|
+ 9 : Result:=FFPMakeCompilerConfig;
|
|
|
+ else
|
|
|
+ Error('Unknown option');
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-procedure TPackagerOptions.SetOptString(Index: integer; const AValue: String);
|
|
|
+procedure TGlobalOptions.SetOptString(Index: integer; const AValue: String);
|
|
|
begin
|
|
|
If AValue=GetOptString(Index) then
|
|
|
Exit;
|
|
@@ -185,64 +199,42 @@ begin
|
|
|
1 : FRemoteMirrorsLocation:=AValue;
|
|
|
2 : FRemoteRepository:=AValue;
|
|
|
3 : FLocalRepository:=AValue;
|
|
|
- 5 : FBuildDir:=FixPath(AValue);
|
|
|
- 6 : FCompiler:=AValue;
|
|
|
- 7 : StringToCPUOS(AValue,FCompilerCPU,FCompilerOS);
|
|
|
+ 4 : FBuildDir:=FixPath(AValue);
|
|
|
+ 5 : FPackagesDir:=FixPath(AValue);
|
|
|
+ 6 : FCompilerConfigDir:=FixPath(AValue);
|
|
|
+ 7 : FDefaultVerbosity:=AValue;
|
|
|
8 : FDefaultCompilerConfig:=AValue;
|
|
|
- 9 : FCompilerVersion:=AValue;
|
|
|
- 10 : FGlobalInstallDir:=FixPath(AValue);
|
|
|
- 11 : FLocalInstallDir:=FixPath(AValue);
|
|
|
- 12 : FDefaultVerbosity:=AValue;
|
|
|
- 13 : FPackagesDir:=FixPath(AValue);
|
|
|
- 14 : FCompilerConfigDir:=FixPath(AValue);
|
|
|
- 15 : FFPMakeCompiler:=AValue;
|
|
|
- 16 : FFPMakeGlobalUnitDir:=FixPath(AValue);
|
|
|
- 17 : FFPMakeLocalUnitDir:=FixPath(AValue);
|
|
|
- 18 : FCurrentCompilerConfig:=AValue;
|
|
|
+ 9 : FFPMakeCompilerConfig:=AValue;
|
|
|
+ else
|
|
|
+ Error('Unknown option');
|
|
|
end;
|
|
|
FDirty:=True;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.SetCompilerCPU(const AValue: TCPU);
|
|
|
-begin
|
|
|
- if FCompilerCPU=AValue then
|
|
|
- exit;
|
|
|
- FCompilerCPU:=AValue;
|
|
|
- FDirty:=True;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-procedure TPackagerOptions.SetCompilerOS(const AValue: TOS);
|
|
|
-begin
|
|
|
- if FCompilerOS=AValue then
|
|
|
- exit;
|
|
|
- FCompilerOS:=AValue;
|
|
|
- FDirty:=True;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-function TPackagerOptions.RemotePackagesFile:string;
|
|
|
+function TGlobalOptions.RemotePackagesFile:string;
|
|
|
begin
|
|
|
Result:=FRemoteRepository+DefaultPackagesFile;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-function TPackagerOptions.LocalPackagesFile:string;
|
|
|
+function TGlobalOptions.LocalPackagesFile:string;
|
|
|
begin
|
|
|
Result:=FLocalRepository+DefaultPackagesFile;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-function TPackagerOptions.LocalVersionsFile(CompilerConfig:String):string;
|
|
|
+function TGlobalOptions.LocalVersionsFile(const ACompilerConfig:String):string;
|
|
|
begin
|
|
|
- Result:=FLocalRepository+Format(DefaultVersionsFile,[CompilerConfig]);
|
|
|
+ Result:=FLocalRepository+Format(DefaultVersionsFile,[ACompilerConfig]);
|
|
|
end;
|
|
|
|
|
|
-Procedure TPackagerOptions.InitGlobalDefaults;
|
|
|
+
|
|
|
+Procedure TGlobalOptions.InitGlobalDefaults;
|
|
|
var
|
|
|
LocalDir : String;
|
|
|
begin
|
|
|
+ FConfigVersion:=CurrentConfigVersion;
|
|
|
// Retrieve Local fppkg directory
|
|
|
{$ifdef unix}
|
|
|
if IsSuperUser then
|
|
@@ -268,76 +260,22 @@ begin
|
|
|
FRemoteMirrorsLocation:=DefaultMirrorsLocation;
|
|
|
FRemoteRepository:=DefaultRemoteRepository;
|
|
|
// Other config
|
|
|
- FDefaultCompilerConfig:='default';
|
|
|
- FCurrentCompilerConfig:=FDefaultCompilerConfig;
|
|
|
FDefaultVerbosity:='error,warning,info,debug,commands';
|
|
|
- FBootStrap:=False;
|
|
|
+ FDefaultCompilerConfig:='default';
|
|
|
+ FFPMakeCompilerConfig:='default';
|
|
|
+ // Parameter defaults
|
|
|
+ FCompilerConfig:=FDefaultCompilerConfig;
|
|
|
FInstallGlobal:=False;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-Procedure TPackagerOptions.InitCompilerDefaults;
|
|
|
-var
|
|
|
- infoSL : TStringList;
|
|
|
- i : Integer;
|
|
|
-begin
|
|
|
- FCompiler:=FileSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
|
|
|
- if FCompiler='' then
|
|
|
- Raise EPackagerError.Create(SErrMissingFPC);
|
|
|
- // Detect compiler version/target from -i option
|
|
|
- infosl:=TStringList.Create;
|
|
|
- infosl.Delimiter:=' ';
|
|
|
- infosl.DelimitedText:=GetCompilerInfo(FCompiler,'-iVTPTO');
|
|
|
- if infosl.Count<>3 then
|
|
|
- Raise EPackagerError.Create(SErrInvalidFPCInfo);
|
|
|
- FCompilerVersion:=infosl[0];
|
|
|
- FCompilerCPU:=StringToCPU(infosl[1]);
|
|
|
- FCompilerOS:=StringToOS(infosl[2]);
|
|
|
- Log(vDebug,SLogDetectedCompiler,[FCompiler,FCompilerVersion,MakeTargetString(FCompilerCPU,FCompilerOS)]);
|
|
|
- // Use the same algorithm as the compiler, see options.pas
|
|
|
-{$ifdef Unix}
|
|
|
- FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
|
|
|
- if FGlobalInstallDir='' then
|
|
|
- begin
|
|
|
- FGlobalInstallDir:='/usr/local/lib/fpc/'+FCompilerVersion+'/';
|
|
|
- if not DirectoryExists(FGlobalInstallDir) and
|
|
|
- DirectoryExists('/usr/lib/fpc/'+FCompilerVersion) then
|
|
|
- FGlobalInstallDir:='/usr/lib/fpc/'+FCompilerVersion+'/';
|
|
|
- end;
|
|
|
-{$else unix}
|
|
|
- FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
|
|
|
- if FGlobalInstallDir='' then
|
|
|
- begin
|
|
|
- FGlobalInstallDir:=ExtractFilePath(FCompiler)+'../';
|
|
|
- if not(DirectoryExists(FGlobalInstallDir+'/units')) and
|
|
|
- not(DirectoryExists(FGlobalInstallDir+'/rtl')) then
|
|
|
- FGlobalInstallDir:=FGlobalInstallDir+'../';
|
|
|
- end;
|
|
|
-{$endif unix}
|
|
|
- Log(vDebug,SLogDetectedFPCDIR,['global',FGlobalInstallDir]);
|
|
|
- // User writable install directory
|
|
|
- if not IsSuperUser then
|
|
|
- begin
|
|
|
- FLocalInstallDir:=FLocalRepository+'lib'+PathDelim+FCompilerVersion+PathDelim;
|
|
|
- Log(vDebug,SLogDetectedFPCDIR,['local',FLocalInstallDir]);
|
|
|
- end;
|
|
|
- // Detect directory where fpmake units are located
|
|
|
- FFPMakeCompiler:=FCompiler;
|
|
|
- FFPMakeGlobalUnitDir:=FGlobalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim;
|
|
|
- FFPMakeLocalUnitDir:=FLocalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim;
|
|
|
- for i:=low(FPMKUnitDeps) to high(FPMKUnitDeps) do
|
|
|
- begin
|
|
|
- if not DirectoryExistsLog(FFPMakeGlobalUnitDir+FPMKUnitDeps[i]+PathDelim) and
|
|
|
- not DirectoryExistsLog(FFPMakeLocalUnitDir+FPMKUnitDeps[i]+PathDelim) then
|
|
|
- Log(vWarning,SWarnFPMKUnitDirNotFound,[FPMKUnitDeps[i]]);
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-procedure TPackagerOptions.LoadGlobalFromIni(Ini: TCustomIniFile);
|
|
|
+procedure TGlobalOptions.LoadGlobalFromIni(Ini: TCustomIniFile);
|
|
|
begin
|
|
|
With Ini do
|
|
|
begin
|
|
|
+ FConfigVersion:=ReadString(SDefaults,KeyConfigVersion,'');
|
|
|
+ if FConfigVersion<>CurrentConfigVersion then
|
|
|
+ Error('Old configuration found, please delete manual');
|
|
|
FLocalMirrorsLocation:=ReadString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation);
|
|
|
FRemoteMirrorsLocation:=ReadString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation);
|
|
|
FRemoteRepository:=ReadString(SDefaults,KeyRemoteRepository,FRemoteRepository);
|
|
@@ -345,16 +283,18 @@ begin
|
|
|
FBuildDir:=FixPath(ReadString(SDefaults,KeyBuildDir,FBuildDir));
|
|
|
FPackagesDir:=FixPath(ReadString(SDefaults,KeyPackagesDir,FPackagesDir));
|
|
|
FCompilerConfigDir:=FixPath(ReadString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir));
|
|
|
- FDefaultCompilerConfig:=ReadString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
|
|
|
FDefaultVerbosity:=ReadString(SDefaults,KeyVerbosity,FDefaultVerbosity);
|
|
|
+ FDefaultCompilerConfig:=ReadString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
|
|
|
+ FFPMakeCompilerConfig:=ReadString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig);
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.SaveGlobalToIni(Ini: TCustomIniFile);
|
|
|
+procedure TGlobalOptions.SaveGlobalToIni(Ini: TCustomIniFile);
|
|
|
begin
|
|
|
With Ini do
|
|
|
begin
|
|
|
+ WriteString(SDefaults,KeyConfigVersion,FConfigVersion);
|
|
|
WriteString(SDefaults,KeyBuildDir,FBuildDir);
|
|
|
WriteString(SDefaults,KeyPackagesDir,FPackagesDir);
|
|
|
WriteString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir);
|
|
@@ -362,17 +302,18 @@ begin
|
|
|
WriteString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation);
|
|
|
WriteString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation);
|
|
|
WriteString(SDefaults,KeyRemoteRepository,FRemoteRepository);
|
|
|
- WriteString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
|
|
|
WriteString(SDefaults,KeyVerbosity,FDefaultVerbosity);
|
|
|
+ WriteString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
|
|
|
+ WriteString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig);
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.LoadGlobalFromFile(FileName: String);
|
|
|
+procedure TGlobalOptions.LoadGlobalFromFile(const AFileName: String);
|
|
|
Var
|
|
|
Ini : TMemIniFile;
|
|
|
begin
|
|
|
- Ini:=TMemIniFile.Create(FileName);
|
|
|
+ Ini:=TMemIniFile.Create(AFileName);
|
|
|
try
|
|
|
LoadGlobalFromIni(Ini);
|
|
|
finally
|
|
@@ -381,11 +322,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.SaveGlobalToFile(FileName: String);
|
|
|
+procedure TGlobalOptions.SaveGlobalToFile(const AFileName: String);
|
|
|
Var
|
|
|
Ini : TIniFile;
|
|
|
begin
|
|
|
- Ini:=TIniFile.Create(FileName);
|
|
|
+ if FileExists(AFileName) then
|
|
|
+ BackupFile(AFileName);
|
|
|
+ Ini:=TIniFile.Create(AFileName);
|
|
|
try
|
|
|
SaveGlobalToIni(Ini);
|
|
|
Ini.UpdateFile;
|
|
@@ -395,45 +338,166 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.LoadCompilerFromIni(Ini: TCustomIniFile);
|
|
|
+{*****************************************************************************
|
|
|
+ TCompilerOptions
|
|
|
+*****************************************************************************}
|
|
|
+
|
|
|
+constructor TCompilerOptions.Create;
|
|
|
+begin
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+function TCompilerOptions.GetOptString(Index: integer): String;
|
|
|
+begin
|
|
|
+ Case Index of
|
|
|
+ 1 : Result:=FCompiler;
|
|
|
+ 2 : Result:=MakeTargetString(CompilerCPU,CompilerOS);
|
|
|
+ 3 : Result:=FCompilerVersion;
|
|
|
+ 4 : Result:=FGlobalInstallDir;
|
|
|
+ 5 : Result:=FLocalInstallDir;
|
|
|
+ else
|
|
|
+ Error('Unknown option');
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TCompilerOptions.SetOptString(Index: integer; const AValue: String);
|
|
|
+begin
|
|
|
+ If AValue=GetOptString(Index) then
|
|
|
+ Exit;
|
|
|
+ Case Index of
|
|
|
+ 1 : FCompiler:=AValue;
|
|
|
+ 2 : StringToCPUOS(AValue,FCompilerCPU,FCompilerOS);
|
|
|
+ 3 : FCompilerVersion:=AValue;
|
|
|
+ 4 : FGlobalInstallDir:=FixPath(AValue);
|
|
|
+ 5 : FLocalInstallDir:=FixPath(AValue);
|
|
|
+ else
|
|
|
+ Error('Unknown option');
|
|
|
+ end;
|
|
|
+ FDirty:=True;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TCompilerOptions.SetCompilerCPU(const AValue: TCPU);
|
|
|
+begin
|
|
|
+ if FCompilerCPU=AValue then
|
|
|
+ exit;
|
|
|
+ FCompilerCPU:=AValue;
|
|
|
+ FDirty:=True;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TCompilerOptions.SetCompilerOS(const AValue: TOS);
|
|
|
+begin
|
|
|
+ if FCompilerOS=AValue then
|
|
|
+ exit;
|
|
|
+ FCompilerOS:=AValue;
|
|
|
+ FDirty:=True;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+function TCompilerOptions.LocalUnitDir:string;
|
|
|
+begin
|
|
|
+ if FLocalInstallDir<>'' then
|
|
|
+ result:=FLocalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim
|
|
|
+ else
|
|
|
+ result:='';
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+function TCompilerOptions.GlobalUnitDir:string;
|
|
|
+begin
|
|
|
+ if FGlobalInstallDir<>'' then
|
|
|
+ result:=FGlobalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim
|
|
|
+ else
|
|
|
+ result:='';
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TCompilerOptions.InitCompilerDefaults;
|
|
|
+var
|
|
|
+ infoSL : TStringList;
|
|
|
+begin
|
|
|
+ FConfigVersion:=CurrentConfigVersion;
|
|
|
+ FCompiler:=FileSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
|
|
|
+ if FCompiler='' then
|
|
|
+ Raise EPackagerError.Create(SErrMissingFPC);
|
|
|
+ // Detect compiler version/target from -i option
|
|
|
+ infosl:=TStringList.Create;
|
|
|
+ infosl.Delimiter:=' ';
|
|
|
+ infosl.DelimitedText:=GetCompilerInfo(FCompiler,'-iVTPTO');
|
|
|
+ if infosl.Count<>3 then
|
|
|
+ Raise EPackagerError.Create(SErrInvalidFPCInfo);
|
|
|
+ FCompilerVersion:=infosl[0];
|
|
|
+ FCompilerCPU:=StringToCPU(infosl[1]);
|
|
|
+ FCompilerOS:=StringToOS(infosl[2]);
|
|
|
+ Log(vDebug,SLogDetectedCompiler,[FCompiler,FCompilerVersion,MakeTargetString(FCompilerCPU,FCompilerOS)]);
|
|
|
+ // Use the same algorithm as the compiler, see options.pas
|
|
|
+{$ifdef Unix}
|
|
|
+ FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
|
|
|
+ if FGlobalInstallDir='' then
|
|
|
+ begin
|
|
|
+ FGlobalInstallDir:='/usr/local/lib/fpc/'+FCompilerVersion+'/';
|
|
|
+ if not DirectoryExists(FGlobalInstallDir) and
|
|
|
+ DirectoryExists('/usr/lib/fpc/'+FCompilerVersion) then
|
|
|
+ FGlobalInstallDir:='/usr/lib/fpc/'+FCompilerVersion+'/';
|
|
|
+ end;
|
|
|
+{$else unix}
|
|
|
+ FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
|
|
|
+ if FGlobalInstallDir='' then
|
|
|
+ begin
|
|
|
+ FGlobalInstallDir:=ExtractFilePath(FCompiler)+'../';
|
|
|
+ if not(DirectoryExists(FGlobalInstallDir+'/units')) and
|
|
|
+ not(DirectoryExists(FGlobalInstallDir+'/rtl')) then
|
|
|
+ FGlobalInstallDir:=FGlobalInstallDir+'../';
|
|
|
+ end;
|
|
|
+{$endif unix}
|
|
|
+ Log(vDebug,SLogDetectedFPCDIR,['global',FGlobalInstallDir]);
|
|
|
+ // User writable install directory
|
|
|
+ if not IsSuperUser then
|
|
|
+ begin
|
|
|
+ FLocalInstallDir:=GlobalOptions.LocalRepository+'lib'+PathDelim+FCompilerVersion+PathDelim;
|
|
|
+ Log(vDebug,SLogDetectedFPCDIR,['local',FLocalInstallDir]);
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TCompilerOptions.LoadCompilerFromIni(Ini: TCustomIniFile);
|
|
|
begin
|
|
|
With Ini do
|
|
|
begin
|
|
|
+ FConfigVersion:=ReadString(SDefaults,KeyConfigVersion,'');
|
|
|
+ if FConfigVersion<>CurrentConfigVersion then
|
|
|
+ Error('Old configuration found, please delete manual');
|
|
|
FGlobalInstallDir:=FixPath(ReadString(SDefaults,KeyGlobalInstallDir,FGlobalInstallDir));
|
|
|
FLocalInstallDir:=FixPath(ReadString(SDefaults,KeyLocalInstallDir,FLocalInstallDir));
|
|
|
FCompiler:=ReadString(SDefaults,KeyCompiler,FCompiler);
|
|
|
FCompilerOS:=StringToOS(ReadString(SDefaults,KeyCompilerOS,OSToString(CompilerOS)));
|
|
|
FCompilerCPU:=StringToCPU(ReadString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU)));
|
|
|
FCompilerVersion:=ReadString(SDefaults,KeyCompilerVersion,FCompilerVersion);
|
|
|
- FFPMakeCompiler:=ReadString(SDefaults,KeyFPMakeCompiler,FFPMakeCompiler);
|
|
|
- FFPMakeGlobalUnitDir:=FixPath(ReadString(SDefaults,KeyFPMakeGlobalUnitDir,FFPMakeGlobalUnitDir));
|
|
|
- FFPMakeLocalUnitDir:=FixPath(ReadString(SDefaults,KeyFPMakeLocalUnitDir,FFPMakeLocalUnitDir));
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.SaveCompilerToIni(Ini: TCustomIniFile);
|
|
|
+procedure TCompilerOptions.SaveCompilerToIni(Ini: TCustomIniFile);
|
|
|
begin
|
|
|
With Ini do
|
|
|
begin
|
|
|
+ WriteString(SDefaults,KeyConfigVersion,FConfigVersion);
|
|
|
WriteString(SDefaults,KeyGlobalInstallDir,FGlobalInstallDir);
|
|
|
WriteString(SDefaults,KeyLocalInstallDir,FLocalInstallDir);
|
|
|
WriteString(SDefaults,KeyCompiler,FCompiler);
|
|
|
WriteString(SDefaults,KeyCompilerOS,OSToString(CompilerOS));
|
|
|
WriteString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU));
|
|
|
WriteString(SDefaults,KeyCompilerVersion,FCompilerVersion);
|
|
|
- WriteString(SDefaults,KeyFPMakeCompiler,FFPMakeCompiler);
|
|
|
- WriteString(SDefaults,KeyFPMakeGlobalUnitDir,FFPMakeGlobalUnitDir);
|
|
|
- WriteString(SDefaults,KeyFPMakeLocalUnitDir,FFPMakeLocalUnitDir);
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.LoadCompilerFromFile(FileName: String);
|
|
|
+procedure TCompilerOptions.LoadCompilerFromFile(const AFileName: String);
|
|
|
Var
|
|
|
Ini : TMemIniFile;
|
|
|
begin
|
|
|
- Ini:=TMemIniFile.Create(FileName);
|
|
|
+ Ini:=TMemIniFile.Create(AFileName);
|
|
|
try
|
|
|
LoadCompilerFromIni(Ini);
|
|
|
finally
|
|
@@ -442,11 +506,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TPackagerOptions.SaveCompilerToFile(FileName: String);
|
|
|
+procedure TCompilerOptions.SaveCompilerToFile(const AFileName: String);
|
|
|
Var
|
|
|
Ini : TIniFile;
|
|
|
begin
|
|
|
- Ini:=TIniFile.Create(FileName);
|
|
|
+ if FileExists(AFileName) then
|
|
|
+ BackupFile(AFileName);
|
|
|
+ Ini:=TIniFile.Create(AFileName);
|
|
|
try
|
|
|
SaveCompilerToIni(Ini);
|
|
|
Ini.UpdateFile;
|
|
@@ -457,7 +523,11 @@ end;
|
|
|
|
|
|
|
|
|
initialization
|
|
|
- Options:=TPackagerOptions.Create;
|
|
|
+ GlobalOptions:=TGlobalOptions.Create;
|
|
|
+ CompilerOptions:=TCompilerOptions.Create;
|
|
|
+ FPMakeCompilerOptions:=TCompilerOptions.Create;
|
|
|
finalization
|
|
|
- FreeAndNil(Options);
|
|
|
+ FreeAndNil(GlobalOptions);
|
|
|
+ FreeAndNil(CompilerOptions);
|
|
|
+ FreeAndNil(FPMakeCompilerOptions);
|
|
|
end.
|