Pārlūkot izejas kodu

* Added new structure to hold the global options. The goal is to get rid
of all globals and to contain all fppkg-related stuff into this
structure. So it will be easier to embed fppkg into other applications.

git-svn-id: trunk@34400 -

joost 9 gadi atpakaļ
vecāks
revīzija
9487b46b8a

+ 1 - 0
.gitattributes

@@ -3384,6 +3384,7 @@ packages/fppkg/src/pkgcommands.pp svneol=native#text/plain
 packages/fppkg/src/pkgdownload.pp svneol=native#text/plain
 packages/fppkg/src/pkgfphttp.pp svneol=native#text/plain
 packages/fppkg/src/pkgfpmake.pp svneol=native#text/plain
+packages/fppkg/src/pkgfppkg.pp svneol=native#text/plain
 packages/fppkg/src/pkgglobals.pp svneol=native#text/plain
 packages/fppkg/src/pkghandler.pp svneol=native#text/plain
 packages/fppkg/src/pkgmessages.pp svneol=native#text/plain

+ 1 - 0
packages/fppkg/fpmake.pp

@@ -62,6 +62,7 @@ begin
     T.ResourceStrings:=true;
 
     T:=P.Targets.AddUnit('pkgoptions.pp');
+    T:=P.Targets.AddUnit('pkgfppkg.pp');
     T:=P.Targets.AddUnit('pkgglobals.pp');
     T:=P.Targets.AddUnit('pkghandler.pp');
     T:=P.Targets.AddUnit('pkgmkconv.pp');

+ 24 - 24
packages/fppkg/src/pkgcommands.pp

@@ -218,9 +218,9 @@ end;
 
 procedure TCommandListSettings.Execute;
 begin
-  GlobalOptions.LogValues(llProgres);
-  CompilerOptions.LogValues(llProgres,'');
-  FPMakeCompilerOptions.LogValues(llProgres,'fpmake-building ');
+  GFPpkg.Options.LogValues(llProgres);
+  GFPpkg.CompilerOptions.LogValues(llProgres,'');
+  GFPpkg.FPMakeCompilerOptions.LogValues(llProgres,'fpmake-building ');
 end;
 
 
@@ -240,27 +240,27 @@ var
 begin
   // Download and load mirrors.xml
   // This can be skipped when a custom RemoteRepository is configured
-  if (GlobalOptions.GlobalSection.RemoteMirrorsURL<>'') and
-     (GlobalOptions.GlobalSection.RemoteRepository='auto') then
+  if (GFPpkg.Options.GlobalSection.RemoteMirrorsURL<>'') and
+     (GFPpkg.Options.GlobalSection.RemoteRepository='auto') then
     begin
-      Log(llCommands,SLogDownloading,[GlobalOptions.GlobalSection.RemoteMirrorsURL,GlobalOptions.GlobalSection.LocalMirrorsFile]);
-      DownloadFile(GlobalOptions.GlobalSection.RemoteMirrorsURL,GlobalOptions.GlobalSection.LocalMirrorsFile);
+      Log(llCommands,SLogDownloading,[GFPpkg.Options.GlobalSection.RemoteMirrorsURL,GFPpkg.Options.GlobalSection.LocalMirrorsFile]);
+      DownloadFile(GFPpkg.Options.GlobalSection.RemoteMirrorsURL,GFPpkg.Options.GlobalSection.LocalMirrorsFile);
       LoadLocalAvailableMirrors;
     end;
   // Download packages.xml
   PackagesURL:=GetRemoteRepositoryURL(PackagesFileName);
-  Log(llCommands,SLogDownloading,[PackagesURL,GlobalOptions.GlobalSection.LocalPackagesFile]);
-  DownloadFile(PackagesURL,GlobalOptions.GlobalSection.LocalPackagesFile);
+  Log(llCommands,SLogDownloading,[PackagesURL,GFPpkg.Options.GlobalSection.LocalPackagesFile]);
+  DownloadFile(PackagesURL,GFPpkg.Options.GlobalSection.LocalPackagesFile);
   // Read the repository again
   LoadLocalAvailableRepository;
   // no need to log errors again
-  FindInstalledPackages(CompilerOptions,False);
+  FindInstalledPackages(GFPpkg.CompilerOptions,False);
 end;
 
 
 procedure TCommandListPackages.Execute;
 begin
-  ListPackages(GlobalOptions.CommandLineSection.ShowLocation);
+  ListPackages(GFPpkg.Options.CommandLineSection.ShowLocation);
 end;
 
 
@@ -385,9 +385,9 @@ var
         // If the package is recompiled, the installation-location is dependent on where
         // the package was installed originally.
         if P.InstalledLocally then
-          Result:=CompilerOptions.LocalUnitDir
+          Result:=GFPpkg.CompilerOptions.LocalUnitDir
         else
-          Result:=CompilerOptions.GlobalUnitDir;
+          Result:=GFPpkg.CompilerOptions.GlobalUnitDir;
         // Setting RecompileBroken to false is in a strict sense not needed. But it is better
         // to clean this temporary flag, to avoid problems with changes in the future
         P.RecompileBroken := false;
@@ -395,10 +395,10 @@ var
       end
     else
       begin
-        if (IsSuperUser or GlobalOptions.CommandLineSection.InstallGlobal) then
-          Result:=CompilerOptions.GlobalUnitDir
+        if (IsSuperUser or GFPpkg.Options.CommandLineSection.InstallGlobal) then
+          Result:=GFPpkg.CompilerOptions.GlobalUnitDir
         else
-          Result:=CompilerOptions.LocalUnitDir;
+          Result:=GFPpkg.CompilerOptions.LocalUnitDir;
       end;
     Result:=IncludeTrailingPathDelimiter(Result)+S+PathDelim+UnitConfigFileName;
   end;
@@ -410,9 +410,9 @@ var
         // If the package is recompiled, the installation-location is dependent on where
         // the package was installed originally.
         if P.InstalledLocally then
-          Result:=CompilerOptions.LocalInstallDir
+          Result:=GFPpkg.CompilerOptions.LocalInstallDir
         else
-          Result:=CompilerOptions.GlobalInstallDir;
+          Result:=GFPpkg.CompilerOptions.GlobalInstallDir;
         // Setting RecompileBroken to false is in a strict sense not needed. But it is better
         // to clean this temporary flag, to avoid problems with changes in the future
         P.RecompileBroken := false;
@@ -420,12 +420,12 @@ var
       end
     else
       begin
-        if (IsSuperUser or GlobalOptions.CommandLineSection.InstallGlobal) then
-          Result:=CompilerOptions.GlobalInstallDir
+        if (IsSuperUser or GFPpkg.Options.CommandLineSection.InstallGlobal) then
+          Result:=GFPpkg.CompilerOptions.GlobalInstallDir
         else
-          Result:=CompilerOptions.LocalInstallDir;
+          Result:=GFPpkg.CompilerOptions.LocalInstallDir;
       end;
-    Result:=IncludeTrailingPathDelimiter(Result)+'fpmkinst'+PathDelim+CompilerOptions.CompilerTarget+PathDelim+s+FpmkExt;
+    Result:=IncludeTrailingPathDelimiter(Result)+'fpmkinst'+PathDelim+GFPpkg.CompilerOptions.CompilerTarget+PathDelim+s+FpmkExt;
   end;
 
 
@@ -530,8 +530,8 @@ begin
       for i:=0 to P.Dependencies.Count-1 do
         begin
           D:=P.Dependencies[i];
-          if not ((CompilerOptions.CompilerOS in D.OSes) and (CompilerOptions.CompilerCPU in D.CPUs)) then
-            Log(llDebug,SDbgPackageDependencyOtherTarget,[D.PackageName,MakeTargetString(CompilerOptions.CompilerCPU,CompilerOptions.CompilerOS)])
+          if not ((GFPpkg.CompilerOptions.CompilerOS in D.OSes) and (GFPpkg.CompilerOptions.CompilerCPU in D.CPUs)) then
+            Log(llDebug,SDbgPackageDependencyOtherTarget,[D.PackageName,MakeTargetString(GFPpkg.CompilerOptions.CompilerCPU,GFPpkg.CompilerOptions.CompilerOS)])
           // Skip dependencies that are available within the fpmake-file itself
           else if not (assigned(ManifestPackages) and assigned(ManifestPackages.FindPackage(D.PackageName))) then
             begin

+ 3 - 3
packages/fppkg/src/pkgdownload.pp

@@ -76,7 +76,7 @@ procedure DownloadFile(const RemoteFile,LocalFile:String);
 var
   DownloaderClass : TBaseDownloaderClass;
 begin
-  DownloaderClass:=GetDownloader(GlobalOptions.GlobalSection.Downloader);
+  DownloaderClass:=GetDownloader(GFPpkg.Options.GlobalSection.Downloader);
   with DownloaderClass.Create(nil) do
     try
       Download(RemoteFile,LocalFile);
@@ -165,7 +165,7 @@ var
   P : TFPPackage;
 begin
   P:=AvailableRepository.PackageByName(PackageName);
-  DownloaderClass:=GetDownloader(GlobalOptions.GlobalSection.Downloader);
+  DownloaderClass:=GetDownloader(GFPpkg.Options.GlobalSection.Downloader);
   with DownloaderClass.Create(nil) do
     try
       Log(llCommands,SLogDownloading,[PackageRemoteArchive(P),PackageLocalArchive(P)]);
@@ -173,7 +173,7 @@ begin
 
       // Force the existing of the archives-directory if it is being used
       if (P.Name<>CurrentDirPackageName) and (P.Name<>CmdLinePackageName) then
-        ForceDirectories(GlobalOptions.GlobalSection.ArchivesDir);
+        ForceDirectories(GFPpkg.Options.GlobalSection.ArchivesDir);
 
       Download(PackageRemoteArchive(P),PackageLocalArchive(P));
     finally

+ 28 - 28
packages/fppkg/src/pkgfpmake.pp

@@ -138,16 +138,16 @@ var
   function CheckUnitDir(const AUnitName:string;Out AUnitDir:string):boolean;
   begin
     Result:=false;
-    if FPMakeCompilerOptions.LocalUnitDir<>'' then
+    if GFPpkg.FpmakeCompilerOptions.LocalUnitDir<>'' then
       begin
-        AUnitDir:=IncludeTrailingPathDelimiter(FPMakeCompilerOptions.LocalUnitDir+AUnitName);
+        AUnitDir:=IncludeTrailingPathDelimiter(GFPpkg.FPMakeCompilerOptions.LocalUnitDir+AUnitName);
         if DirectoryExistsLog(AUnitDir) then
           begin
             Result:=true;
             exit;
           end;
       end;
-    AUnitDir:=IncludeTrailingPathDelimiter(FPMakeCompilerOptions.GlobalUnitDir+AUnitName);
+    AUnitDir:=IncludeTrailingPathDelimiter(GFPpkg.FPMakeCompilerOptions.GlobalUnitDir+AUnitName);
     if DirectoryExistsLog(AUnitDir) then
       begin
         Result:=true;
@@ -239,9 +239,9 @@ begin
       if NeedFPMKUnitSource then
         CreateFPMKUnitSource(TempBuildDir+PathDelim+'fpmkunit.pp');
       // Call compiler
-      If ExecuteProcess(FPMakeCompilerOptions.Compiler,OOptions+' '+FPmakeSrc)<>0 then
+      If ExecuteProcess(GFPpkg.FPMakeCompilerOptions.Compiler,OOptions+' '+FPmakeSrc)<>0 then
         begin
-          if not GlobalOptions.CommandLineSection.RecoveryMode then
+          if not GFPpkg.Options.CommandLineSection.RecoveryMode then
             Error(SErrCompileFailureFPMakeTryRecovery)
           else
             Error(SErrCompileFailureFPMake);
@@ -313,9 +313,9 @@ begin
   if assigned(P) then
     begin
       if (command<>'archive') and (command<>'manifest') and
-         (not(CompilerOptions.CompilerOS in P.OSes) or
-          not(CompilerOptions.CompilerCPU in P.CPUs)) then
-        Error(SErrPackageDoesNotSupportTarget,[P.Name,MakeTargetString(CompilerOptions.CompilerCPU,CompilerOptions.CompilerOS)]);
+         (not(GFPpkg.CompilerOptions.CompilerOS in P.OSes) or
+          not(GFPpkg.CompilerOptions.CompilerCPU in P.CPUs)) then
+        Error(SErrPackageDoesNotSupportTarget,[P.Name,MakeTargetString(GFPpkg.CompilerOptions.CompilerCPU,GFPpkg.CompilerOptions.CompilerOS)]);
     end;
   { Maybe compile fpmake executable? }
   ExecuteAction(PackageName,'compilefpmake');
@@ -333,32 +333,32 @@ begin
     end
   else
     begin
-      if CompilerOptions.HasOptions then
-        AddOption('--options='+CompilerOptions.Options.DelimitedText);
+      if GFPpkg.CompilerOptions.HasOptions then
+        AddOption('--options='+GFPpkg.CompilerOptions.Options.DelimitedText);
 
-      if GlobalOptions.GlobalSection.CustomFPMakeOptions<>'' then
+      if GFPpkg.Options.GlobalSection.CustomFPMakeOptions<>'' then
         begin
         AddOption('--ignoreinvalidoption');
-        AddOption(GlobalOptions.GlobalSection.CustomFPMakeOptions);
+        AddOption(GFPpkg.Options.GlobalSection.CustomFPMakeOptions);
         end;
     end;
 
   AddOption('--nofpccfg');
-  AddOption('--compiler='+CompilerOptions.Compiler);
-  AddOption('--cpu='+CPUToString(CompilerOptions.CompilerCPU));
-  AddOption('--os='+OSToString(CompilerOptions.CompilerOS));
-  if IsSuperUser or GlobalOptions.CommandLineSection.InstallGlobal then
+  AddOption('--compiler='+GFPpkg.CompilerOptions.Compiler);
+  AddOption('--cpu='+CPUToString(GFPpkg.CompilerOptions.CompilerCPU));
+  AddOption('--os='+OSToString(GFPpkg.CompilerOptions.CompilerOS));
+  if IsSuperUser or GFPpkg.Options.CommandLineSection.InstallGlobal then
     begin
-      CondAddOption('--prefix',CompilerOptions.GlobalPrefix);
-      CondAddOption('--baseinstalldir',CompilerOptions.GlobalInstallDir);
+      CondAddOption('--prefix',GFPpkg.CompilerOptions.GlobalPrefix);
+      CondAddOption('--baseinstalldir',GFPpkg.CompilerOptions.GlobalInstallDir);
     end
   else
     begin
-      CondAddOption('--prefix',CompilerOptions.LocalPrefix);
-      CondAddOption('--baseinstalldir',CompilerOptions.LocalInstallDir);
+      CondAddOption('--prefix',GFPpkg.CompilerOptions.LocalPrefix);
+      CondAddOption('--baseinstalldir',GFPpkg.CompilerOptions.LocalInstallDir);
     end;
-  CondAddOption('--localunitdir',CompilerOptions.LocalInstallDir);
-  CondAddOption('--globalunitdir',CompilerOptions.GlobalInstallDir);
+  CondAddOption('--localunitdir',GFPpkg.CompilerOptions.LocalInstallDir);
+  CondAddOption('--globalunitdir',GFPpkg.CompilerOptions.GlobalInstallDir);
 
   { Run FPMake }
   FPMakeBin:='fpmake'+ExeExt;
@@ -411,15 +411,15 @@ var
   StoredGlobalPrefix: string;
 begin
   // In most (all?) cases we do not want a prefix in the archive.
-  StoredGlobalPrefix := CompilerOptions.GlobalPrefix;
-  StoredLocalPrefix := CompilerOptions.LocalPrefix;
-  CompilerOptions.GlobalPrefix := '';
-  CompilerOptions.LocalPrefix := '';
+  StoredGlobalPrefix := GFPpkg.CompilerOptions.GlobalPrefix;
+  StoredLocalPrefix := GFPpkg.CompilerOptions.LocalPrefix;
+  GFPpkg.CompilerOptions.GlobalPrefix := '';
+  GFPpkg.CompilerOptions.LocalPrefix := '';
   try
     RunFPMake('archive');
   finally
-    CompilerOptions.GlobalPrefix := StoredGlobalPrefix;
-    CompilerOptions.LocalPrefix := StoredLocalPrefix;
+    GFPpkg.CompilerOptions.GlobalPrefix := StoredGlobalPrefix;
+    GFPpkg.CompilerOptions.LocalPrefix := StoredLocalPrefix;
   end;
 end;
 

+ 152 - 0
packages/fppkg/src/pkgfppkg.pp

@@ -0,0 +1,152 @@
+unit pkgFppkg;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes,
+  SysUtils,
+  contnrs,
+  fprepos,
+  pkgmessages,
+  pkgglobals,
+  pkgoptions;
+
+type
+
+  { TpkgFPpkg }
+
+  TpkgFPpkg = class(TComponent)
+  private
+    FOptions: TFppkgOptions;
+    FCompilerOptions: TCompilerOptions;
+    FFpmakeCompilerOptions: TCompilerOptions;
+  protected
+  public
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+
+    procedure InitializeGlobalOptions(CfgFile: string);
+    procedure InitializeCompilerOptions;
+    property Options: TFppkgOptions read FOptions;
+    property CompilerOptions: TCompilerOptions read FCompilerOptions;
+    property FpmakeCompilerOptions: TCompilerOptions read FFpmakeCompilerOptions;
+  end;
+
+implementation
+
+{ TpkgFPpkg }
+
+constructor TpkgFPpkg.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  FOptions := TFppkgOptions.Create;
+  FCompilerOptions := TCompilerOptions.Create;
+  FFpmakeCompilerOptions := TCompilerOptions.Create;
+end;
+
+destructor TpkgFPpkg.Destroy;
+begin
+  FCompilerOptions.Free;
+  FFpmakeCompilerOptions.Free;
+  FOptions.Free;
+  inherited Destroy;
+end;
+
+procedure TpkgFPpkg.InitializeGlobalOptions(CfgFile: string);
+var
+  i : integer;
+  GeneratedConfig,
+  UseGlobalConfig : boolean;
+begin
+  GeneratedConfig:=false;
+  UseGlobalConfig:=false;
+  // First try specified config file
+  if (CfgFile<>'') then
+    begin
+      if not FileExists(cfgfile) then
+        Error(SErrNoSuchFile,[cfgfile]);
+    end
+  else
+    begin
+      // Now try if a local config-file exists
+      cfgfile:=GetAppConfigFile(False,False);
+      if not FileExists(cfgfile) then
+        begin
+          // If not, try to find a global configuration file
+          cfgfile:=GetAppConfigFile(True,False);
+          if FileExists(cfgfile) then
+            UseGlobalConfig := true
+          else
+            begin
+              // Create a new configuration file
+              if not IsSuperUser then // Make a local, not global, configuration file
+                cfgfile:=GetAppConfigFile(False,False);
+              ForceDirectories(ExtractFilePath(cfgfile));
+              FOptions.SaveToFile(cfgfile);
+              GeneratedConfig:=true;
+            end;
+        end;
+    end;
+  // Load file or create new default configuration
+  if not GeneratedConfig then
+    begin
+      FOptions.LoadFromFile(cfgfile);
+    end;
+  FOptions.CommandLineSection.CompilerConfig:=FOptions.GlobalSection.CompilerConfig;
+  // Tracing of what we've done above, need to be done after the verbosity is set
+  if GeneratedConfig then
+    pkgglobals.Log(llDebug,SLogGeneratingGlobalConfig,[cfgfile])
+  else
+    pkgglobals.Log(llDebug,SLogLoadingGlobalConfig,[cfgfile]);
+  // Log configuration
+  FOptions.LogValues(llDebug);
+end;
+
+procedure TpkgFPpkg.InitializeCompilerOptions;
+var
+  S : String;
+begin
+  // Load default compiler config
+  S:=FOptions.GlobalSection.CompilerConfigDir+FOptions.GlobalSection.CompilerConfig;
+  FCompilerOptions.UpdateLocalRepositoryOption(FOptions);
+  if FileExists(S) then
+    begin
+      pkgglobals.Log(llDebug,SLogLoadingCompilerConfig,[S]);
+      FCompilerOptions.LoadCompilerFromFile(S)
+    end
+  else
+    begin
+      // Generate a default configuration if it doesn't exists
+      if FOptions.GlobalSection.CompilerConfig='default' then
+        begin
+          pkgglobals.Log(llDebug,SLogGeneratingCompilerConfig,[S]);
+          FCompilerOptions.InitCompilerDefaults;
+          FCompilerOptions.SaveCompilerToFile(S);
+          if FCompilerOptions.SaveInifileChanges then
+            FCompilerOptions.SaveCompilerToFile(S);
+        end
+      else
+        Error(SErrMissingCompilerConfig,[S]);
+    end;
+  // Log compiler configuration
+  FCompilerOptions.LogValues(llDebug,'');
+  // Load FPMake compiler config, this is normally the same config as above
+  S:=FOptions.GlobalSection.CompilerConfigDir+FOptions.GlobalSection.FPMakeCompilerConfig;
+  FFPMakeCompilerOptions.UpdateLocalRepositoryOption(FOptions);
+  if FileExists(S) then
+    begin
+      pkgglobals.Log(llDebug,SLogLoadingFPMakeCompilerConfig,[S]);
+      FFPMakeCompilerOptions.LoadCompilerFromFile(S);
+      if FFPMakeCompilerOptions.SaveInifileChanges then
+        FFPMakeCompilerOptions.SaveCompilerToFile(S);
+    end
+  else
+    Error(SErrMissingCompilerConfig,[S]);
+  // Log compiler configuration
+  FFPMakeCompilerOptions.LogValues(llDebug,'fpmake-building');
+end;
+
+end.
+

+ 3 - 3
packages/fppkg/src/pkghandler.pp

@@ -138,11 +138,11 @@ begin
         Result:=CurrentDir;
     end
   else if (APackage.Name=CmdLinePackageName) or (APackage.Name=URLPackageName) then
-    Result:=GlobalOptions.GlobalSection.BuildDir+ChangeFileExt(ExtractFileName(APackage.LocalFileName),'')
+    Result:=GFPpkg.Options.GlobalSection.BuildDir+ChangeFileExt(ExtractFileName(APackage.LocalFileName),'')
   else if (APackage.RecompileBroken) and (APackage.SourcePath<>'') then
     Result:=APackage.SourcePath
   else
-    Result:=GlobalOptions.GlobalSection.BuildDir+APackage.Name;
+    Result:=GFPpkg.Options.GlobalSection.BuildDir+APackage.Name;
 end;
 
 
@@ -166,7 +166,7 @@ begin
   else if APackage.Name=CmdLinePackageName then
     Result:=APackage.LocalFileName
   else
-    Result:=GlobalOptions.GlobalSection.ArchivesDir+APackage.FileName;
+    Result:=GFPpkg.Options.GlobalSection.ArchivesDir+APackage.FileName;
 end;
 
 

+ 0 - 122
packages/fppkg/src/pkgoptions.pp

@@ -226,16 +226,6 @@ Type
     Property CompilerCPU : TCPU Read FCompilerCPU Write SetCompilerCPU;
   end;
 
-var
-  GlobalOptions : TFppkgOptions;
-
-  CompilerOptions : TCompilerOptions;
-  FPMakeCompilerOptions : TCompilerOptions;
-
-procedure LoadGlobalDefaults(CfgFile: string);
-procedure ClearCompilerDefaults;
-procedure LoadCompilerDefaults;
-
 Implementation
 
 uses
@@ -284,109 +274,6 @@ Const
   KeyCompilerCPU           = 'CPU';
   KeyCompilerVersion       = 'Version';
 
-
-procedure LoadGlobalDefaults(CfgFile: string);
-var
-  i : integer;
-  GeneratedConfig,
-  UseGlobalConfig : boolean;
-begin
-  GeneratedConfig:=false;
-  UseGlobalConfig:=false;
-  // First try specified config file
-  if (CfgFile<>'') then
-    begin
-      if not FileExists(cfgfile) then
-        Error(SErrNoSuchFile,[cfgfile]);
-    end
-  else
-    begin
-      // Now try if a local config-file exists
-      cfgfile:=GetAppConfigFile(False,False);
-      if not FileExists(cfgfile) then
-        begin
-          // If not, try to find a global configuration file
-          cfgfile:=GetAppConfigFile(True,False);
-          if FileExists(cfgfile) then
-            UseGlobalConfig := true
-          else
-            begin
-              // Create a new configuration file
-              if not IsSuperUser then // Make a local, not global, configuration file
-                cfgfile:=GetAppConfigFile(False,False);
-              ForceDirectories(ExtractFilePath(cfgfile));
-              GlobalOptions.SaveToFile(cfgfile);
-              GeneratedConfig:=true;
-            end;
-        end;
-    end;
-  // Load file or create new default configuration
-  if not GeneratedConfig then
-    begin
-      GlobalOptions.LoadFromFile(cfgfile);
-    end;
-  GlobalOptions.CommandLineSection.CompilerConfig:=GlobalOptions.GlobalSection.CompilerConfig;
-  // Tracing of what we've done above, need to be done after the verbosity is set
-  if GeneratedConfig then
-    pkgglobals.Log(llDebug,SLogGeneratingGlobalConfig,[cfgfile])
-  else
-    pkgglobals.Log(llDebug,SLogLoadingGlobalConfig,[cfgfile]);
-  // Log configuration
-  GlobalOptions.LogValues(llDebug);
-end;
-
-procedure ClearCompilerDefaults;
-begin
-  CompilerOptions.Free;
-  FPMakeCompilerOptions.Free;
-  CompilerOptions:=TCompilerOptions.Create;
-  FPMakeCompilerOptions:=TCompilerOptions.Create;
-end;
-
-procedure LoadCompilerDefaults;
-var
-  S : String;
-begin
-  // Load default compiler config
-  S:=GlobalOptions.GlobalSection.CompilerConfigDir+GlobalOptions.GlobalSection.CompilerConfig;
-  CompilerOptions.UpdateLocalRepositoryOption(GlobalOptions);
-  if FileExists(S) then
-    begin
-      pkgglobals.Log(llDebug,SLogLoadingCompilerConfig,[S]);
-      CompilerOptions.LoadCompilerFromFile(S)
-    end
-  else
-    begin
-      // Generate a default configuration if it doesn't exists
-      if GlobalOptions.GlobalSection.CompilerConfig='default' then
-        begin
-          pkgglobals.Log(llDebug,SLogGeneratingCompilerConfig,[S]);
-          CompilerOptions.InitCompilerDefaults;
-          CompilerOptions.SaveCompilerToFile(S);
-          if CompilerOptions.SaveInifileChanges then
-            CompilerOptions.SaveCompilerToFile(S);
-        end
-      else
-        Error(SErrMissingCompilerConfig,[S]);
-    end;
-  // Log compiler configuration
-  CompilerOptions.LogValues(llDebug,'');
-  // Load FPMake compiler config, this is normally the same config as above
-  S:=GlobalOptions.GlobalSection.CompilerConfigDir+GlobalOptions.GlobalSection.FPMakeCompilerConfig;
-  FPMakeCompilerOptions.UpdateLocalRepositoryOption(GlobalOptions);
-  if FileExists(S) then
-    begin
-      pkgglobals.Log(llDebug,SLogLoadingFPMakeCompilerConfig,[S]);
-      FPMakeCompilerOptions.LoadCompilerFromFile(S);
-      if FPMakeCompilerOptions.SaveInifileChanges then
-        FPMakeCompilerOptions.SaveCompilerToFile(S);
-    end
-  else
-    Error(SErrMissingCompilerConfig,[S]);
-  // Log compiler configuration
-  FPMakeCompilerOptions.LogValues(llDebug,'fpmake-building ');
-end;
-
 { TFppkgRepositoryOptionSection }
 
 procedure TFppkgRepositoryOptionSection.SetDescription(AValue: string);
@@ -1109,13 +996,4 @@ begin
   log(ALogLevel,SLogCompilerCfgOptions,[Options.DelimitedText]);
 end;
 
-
-initialization
-  GlobalOptions:=TFppkgOptions.Create;
-  CompilerOptions:=TCompilerOptions.Create;
-  FPMakeCompilerOptions:=TCompilerOptions.Create;
-finalization
-  FreeAndNil(GlobalOptions);
-  FreeAndNil(CompilerOptions);
-  FreeAndNil(FPMakeCompilerOptions);
 end.

+ 21 - 8
packages/fppkg/src/pkgrepos.pp

@@ -7,6 +7,7 @@ interface
 uses
   SysUtils,Classes,
   fprepos,pkgoptions,
+  pkgFppkg,
   fpmkunit;
 
 function GetRemoteRepositoryURL(const AFileName:string):string;
@@ -24,6 +25,7 @@ function  PackageInstalledStateStr(const AName:String):string;
 function  PackageAvailableVersionStr(const AName:String):string;
 procedure ListAvailablePackages;
 procedure ListPackages(const ShowGlobalAndLocal: boolean);
+procedure InitializeFppkg;
 
 procedure ListRemoteRepository;
 procedure RebuildRemoteRepository;
@@ -36,6 +38,7 @@ var
   AvailableMirrors    : TFPMirrors;
   AvailableRepository,
   InstalledRepository : TFPRepository;
+  GFPpkg: TpkgFppkg;
 
 
 implementation
@@ -81,7 +84,7 @@ begin
   AvailableMirrors:=TFPMirrors.Create(TFPMirror);
 
   // Repository
-  S:=GlobalOptions.GlobalSection.LocalMirrorsFile;
+  S:=GFPpkg.Options.GlobalSection.LocalMirrorsFile;
   log(llDebug,SLogLoadingMirrorsFile,[S]);
   if not FileExists(S) then
     exit;
@@ -150,15 +153,15 @@ function GetRemoteRepositoryURL(const AFileName:string):string;
 begin
   if CurrentRemoteRepositoryURL='' then
     begin
-      if GlobalOptions.GlobalSection.RemoteRepository='auto' then
+      if GFPpkg.Options.GlobalSection.RemoteRepository='auto' then
         CurrentRemoteRepositoryURL:=SelectRemoteMirror
       else
-        CurrentRemoteRepositoryURL:=GlobalOptions.GlobalSection.RemoteRepository;
+        CurrentRemoteRepositoryURL:=GFPpkg.Options.GlobalSection.RemoteRepository;
     end;
   result := CurrentRemoteRepositoryURL;
   if result[length(result)]<>'/' then
     result := result + '/';
-  Result:=Result+CompilerOptions.CompilerVersion+'/'+AFileName;
+  Result:=Result+GFPpkg.CompilerOptions.CompilerVersion+'/'+AFileName;
 end;
 
 
@@ -336,8 +339,8 @@ begin
   for j:=0 to APackage.Dependencies.Count-1 do
     begin
       D:=APackage.Dependencies[j];
-      if (CompilerOptions.CompilerOS in D.OSes) and
-         (CompilerOptions.CompilerCPU in D.CPUs) then
+      if (GFPpkg.CompilerOptions.CompilerOS in D.OSes) and
+         (GFPpkg.CompilerOptions.CompilerCPU in D.CPUs) then
         begin
           DepPackage:=InstalledRepository.FindPackage(D.PackageName);
           // Don't stop on missing dependencies
@@ -410,7 +413,7 @@ begin
     FPMKUnitDeps[i].available:=false;
   // Not version check needed in Recovery mode, we always need to use
   // the internal bootstrap procedure
-  if GlobalOptions.CommandLineSection.RecoveryMode then
+  if GFPpkg.Options.CommandLineSection.RecoveryMode then
     exit;
   // Check for fpmkunit dependencies
   for i:=0 to high(FPMKUnitDeps) do
@@ -454,7 +457,7 @@ begin
     AvailableRepository.Free;
   AvailableRepository:=GetDefaultRepositoryClass.Create(Nil);
   // Repository
-  S:=GlobalOptions.GlobalSection.LocalPackagesFile;
+  S:=GFPpkg.Options.GlobalSection.LocalPackagesFile;
   log(llDebug,SLogLoadingPackagesFile,[S]);
   if not FileExists(S) then
     exit;
@@ -576,6 +579,14 @@ begin
 end;
 
 
+procedure InitializeFppkg;
+begin
+  if Assigned(GFPpkg) then
+    GFPpkg.Free;
+  GFPpkg := TpkgFPpkg.Create(nil);
+end;
+
+
 {*****************************************************************************
                            Remote Repository
 *****************************************************************************}
@@ -710,6 +721,7 @@ begin
 end;
 
 initialization
+  GFPpkg := nil;
   AvailableRepository := nil;
   InstalledRepository := nil;
   AvailableMirrors := nil;
@@ -717,4 +729,5 @@ finalization
   AvailableRepository.Free;
   InstalledRepository.Free;
   AvailableMirrors.Free;
+  GFPpkg.Free;
 end.

+ 36 - 35
utils/fppkg/fppkg.pp

@@ -73,15 +73,15 @@ begin
     cfgfile:=GetOptionValue('C','config-file')
   else
     cfgfile:='';
-  pkgoptions.LoadGlobalDefaults(cfgfile);
+  GFPpkg.InitializeGlobalOptions(CfgFile);
 end;
 
 
 procedure TMakeTool.MaybeCreateLocalDirs;
 begin
-  ForceDirectories(GlobalOptions.GlobalSection.BuildDir);
-  ForceDirectories(GlobalOptions.GlobalSection.ArchivesDir);
-  ForceDirectories(GlobalOptions.GlobalSection.CompilerConfigDir);
+  ForceDirectories(GFPpkg.Options.GlobalSection.BuildDir);
+  ForceDirectories(GFPpkg.Options.GlobalSection.ArchivesDir);
+  ForceDirectories(GFPpkg.Options.GlobalSection.CompilerConfigDir);
 end;
 
 
@@ -210,45 +210,45 @@ begin
           OptionArg(I);
         end
       else if CheckOption(I,'c','config') then
-        GlobalOptions.CommandLineSection.CompilerConfig:=OptionArg(I)
+        GFPpkg.Options.CommandLineSection.CompilerConfig:=OptionArg(I)
       else if CheckOption(I,'v','verbose') then
         LogLevels:=AllLogLevels
       else if CheckOption(I,'d','debug') then
         LogLevels:=AllLogLevels+[llDebug]
       else if CheckOption(I,'g','global') then
-        GlobalOptions.CommandLineSection.InstallGlobal:=true
+        GFPpkg.Options.CommandLineSection.InstallGlobal:=true
       else if CheckOption(I,'r','recovery') then
-        GlobalOptions.CommandLineSection.RecoveryMode:=true
+        GFPpkg.Options.CommandLineSection.RecoveryMode:=true
       else if CheckOption(I,'n','') then
-        GlobalOptions.CommandLineSection.SkipConfigurationFiles:=true
+        GFPpkg.Options.CommandLineSection.SkipConfigurationFiles:=true
       else if CheckOption(I,'b','broken') then
-        GlobalOptions.CommandLineSection.AllowBroken:=true
+        GFPpkg.Options.CommandLineSection.AllowBroken:=true
       else if CheckOption(I,'l','showlocation') then
-        GlobalOptions.CommandLineSection.ShowLocation:=true
+        GFPpkg.Options.CommandLineSection.ShowLocation:=true
       else if CheckOption(I,'s','skipbroken') then
-        GlobalOptions.CommandLineSection.SkipFixBrokenAfterInstall:=true
+        GFPpkg.Options.CommandLineSection.SkipFixBrokenAfterInstall:=true
       else if CheckOption(I,'o','options') and FirstPass then
         begin
           OptString := OptionArg(I);
           while OptString <> '' do
-            CompilerOptions.Options.Add(SplitSpaces(OptString));
+            GFPpkg.CompilerOptions.Options.Add(SplitSpaces(OptString));
         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);
+          GFPpkg.CompilerOptions.GlobalPrefix := OptionArg(I);
+          GFPpkg.CompilerOptions.LocalPrefix := OptionArg(I);
+          GFPpkg.FPMakeCompilerOptions.GlobalPrefix := OptionArg(I);
+          GFPpkg.FPMakeCompilerOptions.LocalPrefix := OptionArg(I);
         end
       else if CheckOption(I,'','compiler') then
         begin
-          CompilerOptions.Compiler := OptionArg(I);
-          FPMakeCompilerOptions.Compiler := OptionArg(I);
+          GFPpkg.CompilerOptions.Compiler := OptionArg(I);
+          GFPpkg.FPMakeCompilerOptions.Compiler := OptionArg(I);
         end
       else if CheckOption(I,'','os') then
-        CompilerOptions.CompilerOS := StringToOS(OptionArg(I))
+        GFPpkg.CompilerOptions.CompilerOS := StringToOS(OptionArg(I))
       else if CheckOption(I,'','cpu') then
-        CompilerOptions.CompilerCPU := StringToCPU(OptionArg(I))
+        GFPpkg.CompilerOptions.CompilerCPU := StringToCPU(OptionArg(I))
       else if CheckOption(I,'h','help') then
         begin
           ShowUsage;
@@ -288,6 +288,7 @@ var
 begin
   OldCurrDir:=GetCurrentDir;
   Try
+    InitializeFppkg;
     LoadGlobalDefaults;
     ProcessCommandLine(true);
 
@@ -305,12 +306,12 @@ begin
       end;
 
     MaybeCreateLocalDirs;
-    if not GlobalOptions.CommandLineSection.SkipConfigurationFiles then
-      LoadCompilerDefaults
+    if not GFPpkg.Options.CommandLineSection.SkipConfigurationFiles then
+      GFPpkg.InitializeCompilerOptions
     else
       begin
-        FPMakeCompilerOptions.InitCompilerDefaults;
-        CompilerOptions.InitCompilerDefaults;
+        GFPpkg.FPMakeCompilerOptions.InitCompilerDefaults;
+        GFPpkg.CompilerOptions.InitCompilerDefaults;
       end;
 
     // The command-line is parsed for the second time, to make it possible
@@ -319,15 +320,15 @@ begin
 
     // If CompilerVersion, CompilerOS or CompilerCPU is still empty, use the
     // compiler-executable to get them
-    FPMakeCompilerOptions.CheckCompilerValues;
-    CompilerOptions.CheckCompilerValues;
+    GFPpkg.FPMakeCompilerOptions.CheckCompilerValues;
+    GFPpkg.CompilerOptions.CheckCompilerValues;
 
     LoadLocalAvailableMirrors;
 
     // Load local repository, update first if this is a new installation
     // errors will only be reported as warning. The user can be bootstrapping
     // and do an update later
-    if not FileExists(GlobalOptions.GlobalSection.LocalPackagesFile) then
+    if not FileExists(GFPpkg.Options.GlobalSection.LocalPackagesFile) then
       begin
         try
           pkghandler.ExecuteAction('','update');
@@ -337,19 +338,19 @@ begin
         end;
       end;
     LoadLocalAvailableRepository;
-    FindInstalledPackages(FPMakeCompilerOptions,true);
+    FindInstalledPackages(GFPpkg.FPMakeCompilerOptions,true);
     CheckFPMakeDependencies;
     // We only need to reload the status when we use a different
     // configuration for compiling fpmake or when the CPU, OS or compiler
     // are set in the command-line
-    if (GlobalOptions.GlobalSection.CompilerConfig<>GlobalOptions.GlobalSection.FPMakeCompilerConfig) or
-       (CompilerOptions.CompilerCPU<>FPMakeCompilerOptions.CompilerCPU) or
-       (CompilerOptions.CompilerOS<>FPMakeCompilerOptions.CompilerOS) or
-       (CompilerOptions.Compiler<>FPMakeCompilerOptions.Compiler) then
-      FindInstalledPackages(CompilerOptions,true);
+    if (GFPpkg.Options.GlobalSection.CompilerConfig<>GFPpkg.Options.GlobalSection.FPMakeCompilerConfig) or
+       (GFPpkg.CompilerOptions.CompilerCPU<>GFPpkg.FPMakeCompilerOptions.CompilerCPU) or
+       (GFPpkg.CompilerOptions.CompilerOS<>GFPpkg.FPMakeCompilerOptions.CompilerOS) or
+       (GFPpkg.CompilerOptions.Compiler<>GFPpkg.FPMakeCompilerOptions.Compiler) then
+      FindInstalledPackages(GFPpkg.CompilerOptions,true);
 
     // Check for broken dependencies
-    if not GlobalOptions.CommandLineSection.AllowBroken and
+    if not GFPpkg.Options.CommandLineSection.AllowBroken and
        (((ParaAction='fixbroken') and (ParaPackages.Count>0)) or
         (ParaAction='compile') or
         (ParaAction='build') or
@@ -388,7 +389,7 @@ begin
       end;
 
     // Recompile all packages dependent on this package
-    if (ParaAction='install') and not GlobalOptions.CommandLineSection.SkipFixBrokenAfterInstall then
+    if (ParaAction='install') and not GFPpkg.Options.CommandLineSection.SkipFixBrokenAfterInstall then
       pkghandler.ExecuteAction('','fixbroken');
 
     Terminate;