|
@@ -16,7 +16,7 @@ unit pkgoptions;
|
|
|
|
|
|
interface
|
|
|
|
|
|
-uses Classes, Sysutils, Inifiles, fprepos, fpTemplate;
|
|
|
+uses Classes, Sysutils, Inifiles, fprepos, fpTemplate, pkgglobals;
|
|
|
|
|
|
Const
|
|
|
UnitConfigFileName = 'fpunits.conf';
|
|
@@ -32,6 +32,7 @@ Type
|
|
|
|
|
|
TGlobalOptions = Class(TPersistent)
|
|
|
private
|
|
|
+ FConfigFilename: string;
|
|
|
FSaveInifileChanges : Boolean;
|
|
|
FConfigVersion : Integer;
|
|
|
FRemoteMirrorsURL,
|
|
@@ -62,7 +63,7 @@ Type
|
|
|
Procedure InitGlobalDefaults;
|
|
|
Procedure LoadGlobalFromFile(const AFileName : String);
|
|
|
Procedure SaveGlobalToFile(const AFileName : String);
|
|
|
- procedure LogValues;
|
|
|
+ procedure LogValues(ALogLevel: TLogLevel);
|
|
|
// Is set when the inifile has an old version number (which is also the case when a new file is generated)
|
|
|
Property SaveInifileChanges : Boolean Read FSaveInifileChanges;
|
|
|
Property ConfigVersion : Integer read FConfigVersion;
|
|
@@ -96,6 +97,7 @@ Type
|
|
|
|
|
|
TCompilerOptions = Class(TPersistent)
|
|
|
private
|
|
|
+ FConfigFilename: string;
|
|
|
FSaveInifileChanges: Boolean;
|
|
|
FConfigVersion : Integer;
|
|
|
FCompiler,
|
|
@@ -119,7 +121,7 @@ Type
|
|
|
Procedure InitCompilerDefaults;
|
|
|
Procedure LoadCompilerFromFile(const AFileName : String);
|
|
|
Procedure SaveCompilerToFile(const AFileName : String);
|
|
|
- procedure LogValues(const ACfgName:string);
|
|
|
+ procedure LogValues(ALogLevel: TLogLevel; const ACfgName:string);
|
|
|
procedure UpdateLocalRepositoryOption;
|
|
|
procedure CheckCompilerValues;
|
|
|
Function LocalUnitDir:string;
|
|
@@ -150,7 +152,6 @@ var
|
|
|
Implementation
|
|
|
|
|
|
uses
|
|
|
- pkgglobals,
|
|
|
pkgmessages;
|
|
|
|
|
|
Const
|
|
@@ -292,7 +293,10 @@ begin
|
|
|
else
|
|
|
FLocalRepository:='{UserDir}.fppkg/';
|
|
|
{$else}
|
|
|
- FLocalRepository:=IncludeTrailingPathDelimiter(GetAppConfigDir(IsSuperUser));
|
|
|
+ if IsSuperUser then
|
|
|
+ FLocalRepository:=IncludeTrailingPathDelimiter(GetAppConfigDir(true))
|
|
|
+ else
|
|
|
+ FLocalRepository:='{AppConfigDir}';
|
|
|
{$endif}
|
|
|
UpdateLocalRepositoryOption;
|
|
|
// Directories
|
|
@@ -329,6 +333,7 @@ Var
|
|
|
begin
|
|
|
try
|
|
|
Ini:=TMemIniFile.Create(AFileName);
|
|
|
+ FConfigFileName:=AFileName;
|
|
|
With Ini do
|
|
|
begin
|
|
|
FConfigVersion:=ReadInteger(SDefaults,KeyConfigVersion,0);
|
|
@@ -397,18 +402,18 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TGlobalOptions.LogValues;
|
|
|
+procedure TGlobalOptions.LogValues(ALogLevel: TLogLevel);
|
|
|
begin
|
|
|
- Log(vlDebug,SLogGlobalCfgHeader);
|
|
|
- Log(vlDebug,SLogGlobalCfgRemoteMirrorsURL,[FRemoteMirrorsURL]);
|
|
|
- Log(vlDebug,SLogGlobalCfgRemoteRepository,[FRemoteRepository]);
|
|
|
- Log(vlDebug,SLogGlobalCfgLocalRepository,[LocalRepository]);
|
|
|
- Log(vlDebug,SLogGlobalCfgBuildDir,[BuildDir]);
|
|
|
- Log(vlDebug,SLogGlobalCfgArchivesDir,[ArchivesDir]);
|
|
|
- Log(vlDebug,SLogGlobalCfgCompilerConfigDir,[CompilerConfigDir]);
|
|
|
- Log(vlDebug,SLogGlobalCfgDefaultCompilerConfig,[FDefaultCompilerConfig]);
|
|
|
- Log(vlDebug,SLogGlobalCfgFPMakeCompilerConfig,[FFPMakeCompilerConfig]);
|
|
|
- Log(vlDebug,SLogGlobalCfgDownloader,[FDownloader]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgHeader,[FConfigFilename]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgRemoteMirrorsURL,[FRemoteMirrorsURL]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgRemoteRepository,[FRemoteRepository]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgLocalRepository,[FLocalRepository,LocalRepository]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgBuildDir,[FBuildDir,BuildDir]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgArchivesDir,[FArchivesDir,ArchivesDir]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgCompilerConfigDir,[FCompilerConfigDir,CompilerConfigDir]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgDefaultCompilerConfig,[FDefaultCompilerConfig]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgFPMakeCompilerConfig,[FPMakeCompilerConfig]);
|
|
|
+ Log(ALogLevel,SLogGlobalCfgDownloader,[FDownloader]);
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -421,6 +426,13 @@ begin
|
|
|
FOptionParser := TTemplateParser.Create;
|
|
|
FOptionParser.Values['AppConfigDir'] := GetAppConfigDir(false);
|
|
|
FOptionParser.Values['UserDir'] := GetUserDir;
|
|
|
+ {$ifdef unix}
|
|
|
+ FLocalInstallDir:='{LocalPrefix}'+'lib'+PathDelim+'fpc'+PathDelim+'{CompilerVersion}'+PathDelim;
|
|
|
+ FGlobalInstallDir:='{GlobalPrefix}'+'lib'+PathDelim+'fpc'+PathDelim+'{CompilerVersion}'+PathDelim;
|
|
|
+ {$else unix}
|
|
|
+ FLocalInstallDir:='{LocalPrefix}';
|
|
|
+ FGlobalInstallDir:='{GlobalPrefix}';
|
|
|
+ {$endif}
|
|
|
end;
|
|
|
|
|
|
destructor TCompilerOptions.Destroy;
|
|
@@ -465,7 +477,10 @@ begin
|
|
|
Case Index of
|
|
|
1 : FCompiler:=AValue;
|
|
|
2 : StringToCPUOS(AValue,FCompilerCPU,FCompilerOS);
|
|
|
- 3 : FCompilerVersion:=AValue;
|
|
|
+ 3 : begin
|
|
|
+ FCompilerVersion:=AValue;
|
|
|
+ FOptionParser.Values['CompilerVersion'] := FCompilerVersion;
|
|
|
+ end;
|
|
|
4 : FGlobalInstallDir:=FixPath(AValue);
|
|
|
5 : FLocalInstallDir:=FixPath(AValue);
|
|
|
6 : begin
|
|
@@ -529,14 +544,7 @@ end;
|
|
|
function TCompilerOptions.LocalUnitDir:string;
|
|
|
var ALocalInstallDir: string;
|
|
|
begin
|
|
|
- if LocalInstallDir<>'' then
|
|
|
- ALocalInstallDir:=LocalInstallDir
|
|
|
- else if LocalPrefix<>'' then
|
|
|
-{$ifdef unix}
|
|
|
- ALocalInstallDir:=LocalPrefix+'lib'+PathDelim+'fpc'+PathDelim+FCompilerVersion+PathDelim;
|
|
|
-{$else unix}
|
|
|
- ALocalInstallDir:=LocalPrefix;
|
|
|
-{$endif}
|
|
|
+ ALocalInstallDir:=LocalInstallDir;
|
|
|
|
|
|
if ALocalInstallDir<>'' then
|
|
|
result:=ALocalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim
|
|
@@ -548,14 +556,7 @@ end;
|
|
|
function TCompilerOptions.GlobalUnitDir:string;
|
|
|
var AGlobalInstallDir: string;
|
|
|
begin
|
|
|
- if GlobalInstallDir<>'' then
|
|
|
- AGlobalInstallDir:=GlobalInstallDir
|
|
|
- else if GlobalPrefix<>'' then
|
|
|
-{$ifdef unix}
|
|
|
- AGlobalInstallDir:=GlobalPrefix+'lib'+PathDelim+'fpc'+PathDelim+FCompilerVersion+PathDelim;
|
|
|
-{$else unix}
|
|
|
- AGlobalInstallDir:=GlobalPrefix;
|
|
|
-{$endif}
|
|
|
+ AGlobalInstallDir:=GlobalInstallDir;
|
|
|
|
|
|
if AGlobalInstallDir<>'' then
|
|
|
result:=AGlobalInstallDir+'units'+PathDelim+CompilerTarget+PathDelim
|
|
@@ -571,7 +572,9 @@ end;
|
|
|
|
|
|
|
|
|
procedure TCompilerOptions.InitCompilerDefaults;
|
|
|
-
|
|
|
+var
|
|
|
+ ACompilerVersion: string;
|
|
|
+ fpcdir: string;
|
|
|
begin
|
|
|
FConfigVersion:=CurrentConfigVersion;
|
|
|
if fcompiler = '' then
|
|
@@ -579,7 +582,8 @@ begin
|
|
|
if FCompiler='' then
|
|
|
Raise EPackagerError.Create(SErrMissingFPC);
|
|
|
// Detect compiler version/target from -i option
|
|
|
- GetCompilerInfo(FCompiler,'-iVTPTO',FCompilerVersion,FCompilerCPU,FCompilerOS);
|
|
|
+ GetCompilerInfo(FCompiler,'-iVTPTO',ACompilerVersion,FCompilerCPU,FCompilerOS);
|
|
|
+ CompilerVersion := ACompilerVersion;
|
|
|
// Temporary hack to workaround bug in fpc.exe that doesn't support spaces
|
|
|
// We retrieve the real binary
|
|
|
if FCompilerVersion='2.2.0' then
|
|
@@ -599,7 +603,7 @@ begin
|
|
|
if not(DirectoryExists(FGlobalPrefix+PathDelim+'units')) and
|
|
|
not(DirectoryExists(FGlobalPrefix+PathDelim+'rtl')) then
|
|
|
FGlobalPrefix:=FGlobalPrefix+'..'+PathDelim;
|
|
|
- FGlobalPrefix:=ExpandFileName(FGlobalInstallDir);
|
|
|
+ FGlobalPrefix:=ExpandFileName(FGlobalPrefix);
|
|
|
{$endif unix}
|
|
|
|
|
|
Log(vlDebug,SLogDetectedPrefix,['global',FGlobalPrefix]);
|
|
@@ -610,12 +614,15 @@ begin
|
|
|
Log(vlDebug,SLogDetectedPrefix,['local',FLocalPrefix]);
|
|
|
end;
|
|
|
|
|
|
- FGlobalInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
|
|
|
-{$ifndef Unix}
|
|
|
- FGlobalInstallDir:=ExpandFileName(FGlobalInstallDir);
|
|
|
-{$endif unix}
|
|
|
- if FGlobalInstallDir<>'' then
|
|
|
- Log(vlDebug,SLogFPCDirEnv,[FGlobalInstallDir]);
|
|
|
+ fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'));
|
|
|
+ if fpcdir<>'' then
|
|
|
+ begin
|
|
|
+ {$ifndef Unix}
|
|
|
+ fpcdir:=ExpandFileName(fpcdir);
|
|
|
+ {$endif unix}
|
|
|
+ Log(vlDebug,SLogFPCDirEnv,[fpcdir]);
|
|
|
+ FGlobalInstallDir:=fpcdir;
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -625,6 +632,7 @@ Var
|
|
|
begin
|
|
|
try
|
|
|
Ini:=TMemIniFile.Create(AFileName);
|
|
|
+ FConfigFilename:=AFileName;
|
|
|
With Ini do
|
|
|
begin
|
|
|
FConfigVersion:=ReadInteger(SDefaults,KeyConfigVersion,0);
|
|
@@ -642,7 +650,7 @@ begin
|
|
|
FCompiler:=ReadString(SDefaults,KeyCompiler,FCompiler);
|
|
|
FCompilerOS:=StringToOS(ReadString(SDefaults,KeyCompilerOS,OSToString(CompilerOS)));
|
|
|
FCompilerCPU:=StringToCPU(ReadString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU)));
|
|
|
- FCompilerVersion:=ReadString(SDefaults,KeyCompilerVersion,FCompilerVersion);
|
|
|
+ CompilerVersion:=ReadString(SDefaults,KeyCompilerVersion,FCompilerVersion);
|
|
|
end;
|
|
|
finally
|
|
|
Ini.Free;
|
|
@@ -678,16 +686,17 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-procedure TCompilerOptions.LogValues(const ACfgName:string);
|
|
|
+procedure TCompilerOptions.LogValues(ALogLevel: TLogLevel; const ACfgName:string);
|
|
|
begin
|
|
|
- Log(vlDebug,SLogCompilerCfgHeader,[ACfgName]);
|
|
|
- Log(vlDebug,SLogCompilerCfgCompiler,[FCompiler]);
|
|
|
- Log(vlDebug,SLogCompilerCfgTarget,[MakeTargetString(CompilerCPU,CompilerOS)]);
|
|
|
- Log(vlDebug,SLogCompilerCfgVersion,[FCompilerVersion]);
|
|
|
- Log(vlDebug,SLogCompilerCfgGlobalInstallDir,[GlobalInstallDir]);
|
|
|
- Log(vlDebug,SLogCompilerCfgLocalInstallDir,[LocalInstallDir]);
|
|
|
- Log(vlDebug,SLogCompilerCfgGlobalPrefix,[GlobalPrefix]);
|
|
|
- Log(vlDebug,SLogCompilerCfgLocalPrefix,[LocalPrefix]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgHeader,[ACfgName,FConfigFilename]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgCompiler,[FCompiler]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgTarget,[MakeTargetString(CompilerCPU,CompilerOS)]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgVersion,[FCompilerVersion]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgGlobalPrefix,[FGlobalPrefix,GlobalPrefix]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgLocalPrefix,[FLocalPrefix,LocalPrefix]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgGlobalInstallDir,[FGlobalInstallDir,GlobalInstallDir]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgLocalInstallDir,[FLocalInstallDir,LocalInstallDir]);
|
|
|
+ Log(ALogLevel,SLogCompilerCfgOptions,[Options.DelimitedText]);
|
|
|
end;
|
|
|
|
|
|
|