Browse Source

* Parse command-line options twice, so they can override values from the configuration files
* Added --prefix command-line option
* Added -n command-line option to skip reading of configuration files
* Added --compiler option to set compiler-executable
* When the compiler version, target os or cpu is not given in the configuration files, obtain them from the compiler-executable

git-svn-id: trunk@16007 -

joost 15 years ago
parent
commit
f6ced54fb4
3 changed files with 84 additions and 18 deletions
  1. 38 5
      utils/fppkg/fppkg.pp
  2. 18 2
      utils/fppkg/pkgglobals.pp
  3. 28 11
      utils/fppkg/pkgoptions.pp

+ 38 - 5
utils/fppkg/fppkg.pp

@@ -39,7 +39,7 @@ Type
     Destructor Destroy;override;
     Destructor Destroy;override;
     Procedure LoadGlobalDefaults;
     Procedure LoadGlobalDefaults;
     Procedure LoadCompilerDefaults;
     Procedure LoadCompilerDefaults;
-    Procedure ProcessCommandLine;
+    Procedure ProcessCommandLine(FirstPass: boolean);
     Procedure DoRun; Override;
     Procedure DoRun; Override;
   end;
   end;
 
 
@@ -178,6 +178,9 @@ begin
   Writeln('  -b --broken        Do not stop on broken packages');
   Writeln('  -b --broken        Do not stop on broken packages');
   Writeln('  -l --showlocation  Show if the packages are installed globally or locally');
   Writeln('  -l --showlocation  Show if the packages are installed globally or locally');
   Writeln('  -o --options=value Pass extra options to the compiler');
   Writeln('  -o --options=value Pass extra options to the compiler');
+  Writeln('  -n                 Do not read the default configuration files');
+  Writeln('  -p --prefix=value  Specify the prefix');
+  Writeln('  -c --compiler=val. Specify the compiler-executable');
   Writeln('Actions:');
   Writeln('Actions:');
   Writeln('  update            Update packages list');
   Writeln('  update            Update packages list');
   Writeln('  list              List available and installed packages');
   Writeln('  list              List available and installed packages');
@@ -207,7 +210,7 @@ begin
 end;
 end;
 
 
 
 
-procedure TMakeTool.ProcessCommandLine;
+procedure TMakeTool.ProcessCommandLine(FirstPass: boolean);
 
 
   Function CheckOption(Index : Integer;Short,Long : String): Boolean;
   Function CheckOption(Index : Integer;Short,Long : String): Boolean;
   var
   var
@@ -283,16 +286,30 @@ begin
         GlobalOptions.InstallGlobal:=true
         GlobalOptions.InstallGlobal:=true
       else if CheckOption(I,'r','recovery') then
       else if CheckOption(I,'r','recovery') then
         GlobalOptions.RecoveryMode:=true
         GlobalOptions.RecoveryMode:=true
+      else if CheckOption(I,'n','') then
+        GlobalOptions.SkipConfigurationFiles:=true
       else if CheckOption(I,'b','broken') then
       else if CheckOption(I,'b','broken') then
         GlobalOptions.AllowBroken:=true
         GlobalOptions.AllowBroken:=true
       else if CheckOption(I,'l','showlocation') then
       else if CheckOption(I,'l','showlocation') then
         GlobalOptions.ShowLocation:=true
         GlobalOptions.ShowLocation:=true
-      else if CheckOption(I,'o','options') then
+      else if CheckOption(I,'o','options') and FirstPass then
         begin
         begin
           OptString := OptionArg(I);
           OptString := OptionArg(I);
           while OptString <> '' do
           while OptString <> '' do
             CompilerOptions.Options.Add(SplitSpaces(OptString));
             CompilerOptions.Options.Add(SplitSpaces(OptString));
         end
         end
+      else if CheckOption(I,'p','prefix') then
+        begin
+          CompilerOptions.GlobalPrefix := OptionArg(I);
+          CompilerOptions.LocalPrefix := OptionArg(I);
+          FPMakeCompilerOptions.GlobalPrefix := OptionArg(I);
+          FPMakeCompilerOptions.LocalPrefix := OptionArg(I);
+        end
+      else if CheckOption(I,'c','compiler') then
+        begin
+          CompilerOptions.Compiler := OptionArg(I);
+          FPMakeCompilerOptions.Compiler := OptionArg(I);
+        end
       else if CheckOption(I,'h','help') then
       else if CheckOption(I,'h','help') then
         begin
         begin
           ShowUsage;
           ShowUsage;
@@ -327,7 +344,7 @@ begin
   OldCurrDir:=GetCurrentDir;
   OldCurrDir:=GetCurrentDir;
   Try
   Try
     LoadGlobalDefaults;
     LoadGlobalDefaults;
-    ProcessCommandLine;
+    ProcessCommandLine(true);
 
 
     // Scan is special, it doesn't need a valid local setup
     // Scan is special, it doesn't need a valid local setup
     if (ParaAction='scan') then
     if (ParaAction='scan') then
@@ -339,7 +356,23 @@ begin
       end;
       end;
 
 
     MaybeCreateLocalDirs;
     MaybeCreateLocalDirs;
-    LoadCompilerDefaults;
+    if not GlobalOptions.SkipConfigurationFiles then
+      LoadCompilerDefaults
+    else
+      begin
+        FPMakeCompilerOptions.InitCompilerDefaults;
+        CompilerOptions.InitCompilerDefaults;
+      end;
+
+    // The command-line is parsed for the second time, to make it possible
+    // to override the values in the compiler-configuration file. (like prefix)
+    ProcessCommandLine(false);
+
+    // If CompilerVersion, CompilerOS or CompilerCPU is still empty, use the
+    // compiler-executable to get them
+    FPMakeCompilerOptions.CheckCompilerValues;
+    CompilerOptions.CheckCompilerValues;
+
     LoadLocalAvailableMirrors;
     LoadLocalAvailableMirrors;
 
 
     // Load local repository, update first if this is a new installation
     // Load local repository, update first if this is a new installation

+ 18 - 2
utils/fppkg/pkgglobals.pp

@@ -9,7 +9,8 @@ uses
   baseunix,
   baseunix,
 {$endif}
 {$endif}
   SysUtils,
   SysUtils,
-  Classes;
+  Classes,
+  fprepos;
 
 
 Const
 Const
 {$ifdef unix}
 {$ifdef unix}
@@ -75,7 +76,8 @@ Function FileExistsLog(const AFileName:string):Boolean;
 procedure BackupFile(const AFileName: String);
 procedure BackupFile(const AFileName: String);
 Procedure DeleteDir(const ADir:string);
 Procedure DeleteDir(const ADir:string);
 Procedure SearchFiles(SL:TStringList;const APattern:string);
 Procedure SearchFiles(SL:TStringList;const APattern:string);
-Function GetCompilerInfo(const ACompiler,AOptions:string):string;
+Function GetCompilerInfo(const ACompiler,AOptions:string):string; overload;
+Procedure GetCompilerInfo(const ACompiler, AOptions: string; out AVersion: string; out ACPU: TCpu; out aOS:TOS); overload;
 function IsSuperUser:boolean;
 function IsSuperUser:boolean;
 
 
 var
 var
@@ -357,6 +359,20 @@ begin
 end;
 end;
 
 
 
 
+Procedure GetCompilerInfo(const ACompiler, AOptions: string; out AVersion: string; out ACPU: TCpu; out aOS:TOS); overload;
+var
+  infosl: TStringList;
+begin
+  infosl:=TStringList.Create;
+  infosl.Delimiter:=' ';
+  infosl.DelimitedText:=GetCompilerInfo(ACompiler,AOptions);
+  if infosl.Count<>3 then
+    Raise EPackagerError.Create(SErrInvalidFPCInfo);
+  AVersion:=infosl[0];
+  ACPU:=StringToCPU(infosl[1]);
+  AOS:=StringToOS(infosl[2]);
+end;
+
 function IsSuperUser:boolean;
 function IsSuperUser:boolean;
 begin
 begin
 {$ifdef unix}
 {$ifdef unix}

+ 28 - 11
utils/fppkg/pkgoptions.pp

@@ -50,6 +50,7 @@ Type
     FRecoveryMode   : Boolean;
     FRecoveryMode   : Boolean;
     FOptionParser: TTemplateParser;
     FOptionParser: TTemplateParser;
     FShowLocation: Boolean;
     FShowLocation: Boolean;
+    FSkipConfigurationFiles: boolean;
     function  GetOptString(Index: integer): String;
     function  GetOptString(Index: integer): String;
     procedure SetOptString(Index: integer; const AValue: String);
     procedure SetOptString(Index: integer; const AValue: String);
     procedure UpdateLocalRepositoryOption;
     procedure UpdateLocalRepositoryOption;
@@ -83,6 +84,7 @@ Type
     Property RecoveryMode : Boolean Read FRecoveryMode Write FRecoveryMode;
     Property RecoveryMode : Boolean Read FRecoveryMode Write FRecoveryMode;
     Property AllowBroken : Boolean Read FAllowBroken Write FAllowBroken;
     Property AllowBroken : Boolean Read FAllowBroken Write FAllowBroken;
     Property ShowLocation : Boolean Read FShowLocation Write FShowLocation;
     Property ShowLocation : Boolean Read FShowLocation Write FShowLocation;
+    Property SkipConfigurationFiles: boolean read FSkipConfigurationFiles write FSkipConfigurationFiles;
   end;
   end;
 
 
 
 
@@ -115,6 +117,7 @@ Type
     Procedure SaveCompilerToFile(const AFileName : String);
     Procedure SaveCompilerToFile(const AFileName : String);
     procedure LogValues(const ACfgName:string);
     procedure LogValues(const ACfgName:string);
     procedure UpdateLocalRepositoryOption;
     procedure UpdateLocalRepositoryOption;
+    procedure CheckCompilerValues;
     Function LocalUnitDir:string;
     Function LocalUnitDir:string;
     Function GlobalUnitDir:string;
     Function GlobalUnitDir:string;
     Function HasOptions: boolean;
     Function HasOptions: boolean;
@@ -478,6 +481,28 @@ begin
   FOptionParser.Values['LocalRepository'] := GlobalOptions.LocalRepository;
   FOptionParser.Values['LocalRepository'] := GlobalOptions.LocalRepository;
 end;
 end;
 
 
+procedure TCompilerOptions.CheckCompilerValues;
+var
+  AVersion : string;
+  ACpu     : TCpu;
+  AOs      : TOS;
+begin
+  if Compiler='' then
+    Exit;
+  if (CompilerCPU=cpuNone) or
+   (CompilerOS=osNone) or
+   (CompilerVersion='') then
+  begin
+    GetCompilerInfo(Compiler,'-iVTPTO',AVersion,ACpu,AOs);
+    if CompilerCPU=cpuNone then
+      CompilerCPU := ACpu;
+    if CompilerOS=osNone then
+      CompilerOS:=AOs;
+    if CompilerVersion='' then
+      CompilerVersion:=AVersion;
+  end;
+end;
+
 
 
 procedure TCompilerOptions.SetCompilerOS(const AValue: TOS);
 procedure TCompilerOptions.SetCompilerOS(const AValue: TOS);
 begin
 begin
@@ -533,22 +558,14 @@ end;
 
 
 procedure TCompilerOptions.InitCompilerDefaults;
 procedure TCompilerOptions.InitCompilerDefaults;
 
 
-var
-  infoSL : TStringList;
 begin
 begin
   FConfigVersion:=CurrentConfigVersion;
   FConfigVersion:=CurrentConfigVersion;
-  FCompiler:=ExeSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
+  if fcompiler = '' then
+    FCompiler:=ExeSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
   if FCompiler='' then
   if FCompiler='' then
     Raise EPackagerError.Create(SErrMissingFPC);
     Raise EPackagerError.Create(SErrMissingFPC);
   // Detect compiler version/target from -i option
   // 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]);
+  GetCompilerInfo(FCompiler,'-iVTPTO',FCompilerVersion,FCompilerCPU,FCompilerOS);
   // Temporary hack to workaround bug in fpc.exe that doesn't support spaces
   // Temporary hack to workaround bug in fpc.exe that doesn't support spaces
   // We retrieve the real binary
   // We retrieve the real binary
   if FCompilerVersion='2.2.0' then
   if FCompilerVersion='2.2.0' then