From a4f501852e0e3bf5c95aa6019842f28fc8cf253d Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 4 Feb 2007 22:10:45 +0000 Subject: [PATCH] * split config in global config and compiler config git-svn-id: trunk@6344 - --- .gitattributes | 1 + utils/fppkg/fppkg.lpi | 249 +++++++++++++++++++--------------- utils/fppkg/fppkg.pp | 110 +++++++++------ utils/fppkg/fprepos.pp | 22 +-- utils/fppkg/pkgcommands.pp | 94 +++++++++++++ utils/fppkg/pkgfpmake.pp | 87 ++++++++---- utils/fppkg/pkghandler.pp | 25 ++-- utils/fppkg/pkgmessages.pp | 7 + utils/fppkg/pkgmkconv.pp | 4 +- utils/fppkg/pkgropts.pp | 270 +++++++++++++++++++++++++++---------- 10 files changed, 598 insertions(+), 271 deletions(-) create mode 100755 utils/fppkg/pkgcommands.pp diff --git a/.gitattributes b/.gitattributes index 57ef762e01..09cdf130a8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8243,6 +8243,7 @@ utils/fppkg/lnet/sys/lkqueueeventerh.inc svneol=native#text/plain utils/fppkg/lnet/sys/lspawnfcgiunix.inc svneol=native#text/plain utils/fppkg/lnet/sys/lspawnfcgiwin.inc svneol=native#text/plain utils/fppkg/lnet/sys/osunits.inc svneol=native#text/plain +utils/fppkg/pkgcommands.pp svneol=native#text/plain utils/fppkg/pkgdownload.pp svneol=native#text/plain utils/fppkg/pkgfpmake.pp svneol=native#text/plain utils/fppkg/pkghandler.pp svneol=native#text/plain diff --git a/utils/fppkg/fppkg.lpi b/utils/fppkg/fppkg.lpi index 05f8b6ce32..fe2d419db1 100644 --- a/utils/fppkg/fppkg.lpi +++ b/utils/fppkg/fppkg.lpi @@ -12,7 +12,7 @@ - + @@ -32,25 +32,25 @@ - + - - + + - + - - - - + + + + @@ -58,7 +58,7 @@ - + @@ -66,8 +66,8 @@ - - + + @@ -77,43 +77,47 @@ - + - - + + - + - - + + + + + + - - - - + + + + - - - - + + + + @@ -122,18 +126,18 @@ - - + + - - - - + + + + @@ -141,29 +145,29 @@ - + - + - - + + - + - - + + @@ -171,33 +175,33 @@ - + - - + + - + - - - - - - + + + + + + - + - + @@ -205,129 +209,156 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + diff --git a/utils/fppkg/fppkg.pp b/utils/fppkg/fppkg.pp index 039e08e3d4..51dad667f6 100644 --- a/utils/fppkg/fppkg.pp +++ b/utils/fppkg/fppkg.pp @@ -19,12 +19,15 @@ Type TMakeTool = Class(TCustomApplication) Private FDefaults: TPackagerOptions; - FCompiler : String; - Function GetCompiler : String; + FRepository : TFPRepository; + FCompilerConfig : String; + procedure LoadRepository; + procedure MaybeCreateLocalDirs; procedure ShowUsage; Public Function GetConfigFileName : String; - Procedure LoadDefaults; + Procedure LoadGlobalDefaults; + Procedure LoadCompilerDefaults; Procedure ProcessCommandLine; Procedure DoRun; Override; procedure ExecuteAction(const AAction:string;const Args:TActionArgs); @@ -35,39 +38,6 @@ Type { TMakeTool } -function TMakeTool.GetCompiler: String; -begin - If (FCompiler='') then - begin - {$if defined(cpui386)} - FCompiler:='ppc386'; - {$elseif defined(cpuAlpha)} - FCompiler:='ppcaxp'; - {$elseif defined(cpusparc)} - FCompiler:='ppcsparc'; - {$elseif defined(cpuarm)} - FCompiler:='ppcarm'; - {$elseif defined(cpum68k)} - FCompiler:='ppcm68k'; - {$elseif defined(cpux86_64)} - FCompiler:='ppcx64'; - {$elseif defined(cpupowerpc)} - FCompiler:='ppcppc'; - {$else} - {$Fatal Unknown architecture} - {$endif} - end; - If (ExtractFilePath(FCompiler)<>'') then - Result:=FCompiler - else - begin - Result:=FileSearch(FCompiler+ExeExt,GetEnvironmentVariable('PATH')); - If (Result='') then - Result:=FCompiler+ExeExt; - end; -end; - - function TMakeTool.GetConfigFileName: String; var G : Boolean; @@ -86,11 +56,64 @@ begin end; -procedure TMakeTool.LoadDefaults; +procedure TMakeTool.LoadGlobalDefaults; +var + SL : TStringList; + i : integer; begin - Verbosity:=[vError,vInfo,vCommands,vDebug]; FDefaults:=TPackagerOptions.Create; - FDefaults.LoadFromFile(GetConfigFileName); + FDefaults.LoadGlobalFromFile(GetConfigFileName); + // Load default verbosity from config + SL:=TStringList.Create; + SL.CommaText:=FDefaults.DefaultVerbosity; + for i:=0 to SL.Count-1 do + Include(Verbosity,StringToVerbosity(SL[i])); + SL.Free; + FCompilerConfig:=FDefaults.DefaultCompilerConfig; +end; + + +procedure TMakeTool.MaybeCreateLocalDirs; +begin + ForceDirectories(FDefaults.BuildDir); + ForceDirectories(FDefaults.PackagesDir); + ForceDirectories(FDefaults.CompilerConfigDir); +end; + + +procedure TMakeTool.LoadCompilerDefaults; +var + S : String; +begin + S:=FDefaults.CompilerConfigDir+FCompilerConfig; + if FileExists(S) then + begin + Log(vDebug,SLogLoadingCompilerConfig,[S]); + FDefaults.LoadCompilerFromFile(S) + end + else + begin + Log(vDebug,SLogGeneratingCompilerConfig,[S]); + FDefaults.InitCompilerDefaults; + FDefaults.SaveCompilerToFile(S); + end; +end; + + +procedure TMakeTool.LoadRepository; +var + S : String; +begin + FRepository:=TFPRepository.Create(Nil); + // Repository + Log(vDebug,SLogLoadingRepository,[FDefaults.LocalRepository]); + if FileExists(FDefaults.LocalRepository) then + FRepository.LoadFromFile(FDefaults.LocalRepository); + // Versions + S:=FDefaults.LocalVersions(FCompilerConfig); + Log(vDebug,SLogLoadingRepository,[S]); + if FileExists(S) then + FRepository.LoadStatusFromFile(S); end; @@ -108,6 +131,7 @@ begin Writeln(' install Install package'); Writeln(' download Download package'); Writeln(' convertmk Convert Makefile.fpc to fpmake.pp'); + Halt(0); end; @@ -191,6 +215,9 @@ begin end; end; end; + { Default "package" is current directory } + if (ParaPackages.Count=0) then + ParaPackages.Add('.'); if HasAction then begin if GetPkgHandler(Action)<>nil then @@ -242,9 +269,12 @@ var Action : string; Args : TActionArgs; begin - LoadDefaults; + LoadGlobalDefaults; Try ProcessCommandLine; + MaybeCreateLocalDirs; + LoadCompilerDefaults; + LoadRepository; repeat if not ActionStack.Pop(Action,Args) then diff --git a/utils/fppkg/fprepos.pp b/utils/fppkg/fprepos.pp index 6cb1f82769..acc8d1a041 100644 --- a/utils/fppkg/fprepos.pp +++ b/utils/fppkg/fprepos.pp @@ -173,10 +173,10 @@ Type Procedure SaveToFile(AFileName : String); Procedure Save; // Loading and Saving version numbers: List of Name=Value pairs. - Procedure LoadVersionsFromStream(Stream : TStream); virtual; - Procedure SaveVersionsToStream(Stream : TStream; InstalledVersions : Boolean); virtual; - Procedure LoadVersionsFromFile(AFileName : String); - Procedure SaveVersionsToFile(AFileName : String; InstalledVersions : Boolean); + Procedure LoadStatusFromStream(Stream : TStream); virtual; + Procedure SaveStatusToStream(Stream : TStream; InstalledStatus : Boolean); virtual; + Procedure LoadStatusFromFile(AFileName : String); + Procedure SaveStatusToFile(AFileName : String; InstalledStatus : Boolean); // Package management Function IndexOfPackage(PackageName : String) : Integer; Function FindPackage(PackageName : String) : TFPPackage; @@ -646,7 +646,7 @@ begin SaveToFile(FFileName); end; -procedure TFPRepository.LoadVersionsFromStream(Stream: TStream); +procedure TFPRepository.LoadStatusFromStream(Stream: TStream); Var L : TStrings; @@ -668,7 +668,7 @@ begin end; end; -procedure TFPRepository.SaveVersionsToStream(Stream: TStream;InstalledVersions : Boolean); +procedure TFPRepository.SaveStatusToStream(Stream: TStream;InstalledStatus : Boolean); Var L : TStrings; @@ -677,7 +677,7 @@ Var begin L:=TStringList.Create; Try - If InstalledVersions then + If InstalledStatus then For I:=0 to PackageCount-1 do With Packages[i] do L.Add(Name+'='+InstalledVersion.AsString) @@ -691,7 +691,7 @@ begin end; end; -procedure TFPRepository.LoadVersionsFromFile(AFileName: String); +procedure TFPRepository.LoadStatusFromFile(AFileName: String); Var F : TFileStream; @@ -699,13 +699,13 @@ Var begin F:=TFileStream.Create(AFileName,fmOpenRead); Try - LoadVersionsFromStream(F); + LoadStatusFromStream(F); Finally F.Free; end; end; -procedure TFPRepository.SaveVersionsToFile(AFileName: String; InstalledVersions : Boolean); +procedure TFPRepository.SaveStatusToFile(AFileName: String; InstalledStatus : Boolean); Var F : TFileStream; @@ -715,7 +715,7 @@ begin BackupFile(AFileName); F:=TFileStream.Create(AFileName,fmCreate); Try - SaveVersionsToStream(F,InstalledVersions); + SaveStatusToStream(F,InstalledStatus); Finally F.Free; end; diff --git a/utils/fppkg/pkgcommands.pp b/utils/fppkg/pkgcommands.pp new file mode 100755 index 0000000000..cf9c59b084 --- /dev/null +++ b/utils/fppkg/pkgcommands.pp @@ -0,0 +1,94 @@ +unit pkgcommands; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils,pkghandler; + +type + { TCommandUpdate } + + TCommandBuild = Class(TPackagehandler) + Public + Function Execute(const Args:TActionArgs):boolean;override; + end; + + { TCommandDownload } + + TCommandDownload = Class(TPackagehandler) + Public + Function Execute(const Args:TActionArgs):boolean;override; + end; + + { TCommandBuild } + + TCommandBuild = Class(TPackagehandler) + Public + Function Execute(const Args:TActionArgs):boolean;override; + end; + + + { TCommandInstall } + + TCommandInstall = Class(TPackagehandler) + Public + Function Execute(const Args:TActionArgs):boolean;override; + end; + + +implementation + +uses + pkgmessages; + +function TCommandUpdate.Execute(const Args:TActionArgs):boolean; +Var + X : TFPXMLRepositoryHandler; + P : TFPPackage; +begin + P:=Repository.AddPackage('FirstPackage'); + P.Author:='Michael Van Canneyt'; + P.URL:='http://www.freepascal.org/packages/firstpackage.zip'; + P.Email:='michael@freepascal.org'; + P.Version.AsString:='1.2.3'; + P.Description:='First package in the repository. Provides basic information.'; + P.OSes:=[Win32,linux]; + P.CPUs:=[i386,x86_64]; + X:=TFPXMLRepositoryHandler.Create; + With X do + try + SaveToXml(Repository,'packages.xml'); + finally + Free; + end; +end; + + +function TCommandDownload.Execute(const Args:TActionArgs):boolean; +begin + ActionStack.Push('downloadpackage',Args); +end; + + +function TCommandBuild.Execute(const Args:TActionArgs):boolean; +begin + ActionStack.Push('fpmakebuild',Args); + ActionStack.Push('compilefpmake',Args); +end; + + +function TCommandInstall.Execute(const Args:TActionArgs):boolean; +begin + ActionStack.Push('fpmakeinstall',Args); + ActionStack.Push('build',Args); +end; + + +initialization + RegisterPkgHandler('update',TCommandUpdate); + RegisterPkgHandler('download',TCommandDownload); + RegisterPkgHandler('build',TCommandBuild); + RegisterPkgHandler('install',TCommandInstall); +end. diff --git a/utils/fppkg/pkgfpmake.pp b/utils/fppkg/pkgfpmake.pp index d99688d6de..11ebd16e38 100755 --- a/utils/fppkg/pkgfpmake.pp +++ b/utils/fppkg/pkgfpmake.pp @@ -12,9 +12,9 @@ type TFPMakeCompiler = Class(TPackagehandler) Private - Procedure CompileFPMake; + Procedure CompileFPMake(const ADir:string); Public - Function Execute(const Args:array of string):boolean;override; + Function Execute(const Args:TActionArgs):boolean;override; end; @@ -22,9 +22,17 @@ type TFPMakeRunner = Class(TPackagehandler) Private - Function RunFPMake : Integer; + Function RunFPMake(const ADir:string) : Integer; Public - Function Execute(const Args:array of string):boolean;override; + Function Execute(const Args:TActionArgs):boolean;override; + end; + + + { TFPMakeRunner } + + TCommandBuild = Class(TPackagehandler) + Public + Function Execute(const Args:TActionArgs):boolean;override; end; @@ -35,43 +43,52 @@ uses { TFPMakeCompiler } -Procedure TFPMakeCompiler.CompileFPMake; +Procedure TFPMakeCompiler.CompileFPMake(const ADir:string); Var - O,C : String; + D,O,C : String; + FPMakeBin, FPMakeSrc : string; HaveFpmake : boolean; begin + D:=IncludeTrailingPathDelimiter(ADir); { Check for fpmake source } - FPMakeSrc:='fpmake.pp'; + FPMakeBin:=D+'fpmake'+ExeExt; + FPMakeSrc:=D+'fpmake.pp'; HaveFpmake:=FileExists(FPMakeSrc); If Not HaveFPMake then begin - HaveFPMake:=FileExists('fpmake.pas'); + HaveFPMake:=FileExists(D+'fpmake.pas'); If HaveFPMake then - FPMakeSrc:='fpmake.pas'; + FPMakeSrc:=D+'fpmake.pas'; end; - if Not HaveFPMake then - Error(SErrMissingFPMake); - { Call compiler } - C:=Defaults.Compiler; - O:=FPmakeSrc; - Log(vCommands,SLogCompilingFPMake+C+' '+O); - If ExecuteProcess(C,O)<>0 then - Error(SErrFailedToCompileFPCMake) + { Need to compile fpmake executable? } + if FileAge(FPMakeBin)0 then + Error(SErrFailedToCompileFPCMake) + end + else + Log(vCommands,SLogNotCompilingFPMake); end; -function TFPMakeCompiler.Execute(const Args:array of string):boolean; +function TFPMakeCompiler.Execute(const Args:TActionArgs):boolean; begin {$warning TODO Check arguments} - CompileFPMake; + CompileFPMake(Args[0]); result:=true; end; { TFPMakeRunner } -Function TFPMakeRunner.RunFPMake : Integer; +Function TFPMakeRunner.RunFPMake(const ADir:string) : Integer; Function MaybeQuote(Const S : String) : String; begin @@ -86,25 +103,37 @@ Var FPMakeBin, D,O : String; begin - FPMakeBin:='fpmake'+ExeExt; - D:=IncludeTrailingPathDelimiter(GetCurrentDir); + D:=IncludeTrailingPathDelimiter(ADir); + FPMakeBin:=D+'fpmake'+ExeExt; O:=''; For I:=1 to ParamCount do begin - If (O<>'') then - O:=O+' '; - O:=O+MaybeQuote(ParamStr(I)); + If (O<>'') then + O:=O+' '; + O:=O+MaybeQuote(ParamStr(I)); end; - Log(vCommands,SLogRunningFPMake+D+FPMakeBin+' '+O); - Result:=ExecuteProcess(D+FPMakeBin,O); + Log(vCommands,SLogRunningFPMake+FPMakeBin+' '+O); + Result:=ExecuteProcess(FPMakeBin,O); end; -function TFPMakeRunner.Execute(const Args:array of string):boolean; +function TFPMakeRunner.Execute(const Args:TActionArgs):boolean; begin {$warning TODO Check arguments} - result:=(RunFPMake=0); + result:=(RunFPMake(Args[0])=0); end; + +function TCommandBuild.Execute(const Args:TActionArgs):boolean; +begin + ActionStack.Push('fpmakebuild',[]); + ActionStack.Push('compilefpmake',[]); +end; + + +initialization + RegisterPkgHandler('compilefpmake',TFPMakeCompiler); + RegisterPkgHandler('fpmakebuild',TFPMakeRunner); + RegisterPkgHandler('build',TCommandBuild); end. diff --git a/utils/fppkg/pkghandler.pp b/utils/fppkg/pkghandler.pp index 4b759ef37b..918aa8c6d1 100644 --- a/utils/fppkg/pkghandler.pp +++ b/utils/fppkg/pkghandler.pp @@ -4,7 +4,7 @@ unit pkghandler; interface -uses Classes,SysUtils, fpmktype, pkgropts; +uses Classes,SysUtils, fpmktype, pkgropts, fprepos; Const {$ifdef unix} @@ -45,15 +45,16 @@ Type private FBackupFile : Boolean; FDefaults : TPackagerOptions; + function PackageBuildPath(APackage:TFPPackage):String; Protected Procedure BackupFile(Const FileName : String); Public Constructor Create(AOwner: TComponent;ADefaults:TPackagerOptions); virtual; - Function Execute(const Args:array of string):boolean; virtual; abstract; + Function Execute(const Args:TActionArgs):boolean; virtual; abstract; Property BackupFiles : Boolean Read FBackupFile Write FBackupFile; Property Defaults:TPackagerOptions Read FDefaults; end; - TPackageHandlerClass = class(TPackageHandler); + TPackageHandlerClass = class of TPackageHandler; EPackageHandler = Class(EInstallerError); @@ -89,7 +90,7 @@ uses pkgmessages; var - PkgHandlerList : TFPHashObjectList; + PkgHandlerList : TFPHashList; procedure RegisterPkgHandler(const AAction:string;pkghandlerclass:TPackageHandlerClass); begin @@ -199,6 +200,12 @@ end; { TPackageHandler } +constructor TPackageHandler.Create(AOwner : TComponent; ADefaults:TPackagerOptions); +begin + inherited Create(AOwner); + FDefaults:=ADefaults; +end; + procedure TPackageHandler.BackupFile(const FileName: String); Var BFN : String; @@ -208,10 +215,12 @@ begin Error(SErrBackupFailed,[FileName,BFN]); end; -constructor TPackageHandler.Create(AOwner : TComponent; ADefaults:TPackagerOptions); +function TPackageHandler.PackageBuildPath(APackage:TFPPackage):String; begin - inherited Create(AOwner); - FDefaults:=ADefaults; + if APackage=nil then + Result:='.' + else + Result:=Defaults.BuildDir+APackage.Name; end; @@ -275,7 +284,7 @@ end; initialization - PkgHandlerList:=TFPHashObjectList.Create(true); + PkgHandlerList:=TFPHashList.Create; ActionStack:=TActionStack.Create; finalization FreeAndNil(PkgHandlerList); diff --git a/utils/fppkg/pkgmessages.pp b/utils/fppkg/pkgmessages.pp index 5b9821312c..e69197942b 100644 --- a/utils/fppkg/pkgmessages.pp +++ b/utils/fppkg/pkgmessages.pp @@ -8,6 +8,7 @@ interface Resourcestring SErrInValidArgument = 'Invalid command-line argument at position %d : %s'; SErrNeedArgument = 'Option at position %d (%s) needs an argument'; + SErrMissingFPC = 'Could not find a fpc executable in the PATH'; SErrMissingFPMake = 'Missing configuration fpmake.pp'; SErrMissingMakefilefpc = 'Missing configuration Makefile.fpc'; SErrRunning = 'The FPC make tool encountered the following error: %s'; @@ -31,8 +32,14 @@ Resourcestring SLogGeneratingFPMake = 'Generating fpmake.pp'; SLogCompilingFPMake = 'Compiling fpmake.pp: '; + SLogNotCompilingFPMake = 'Skipping compiling of fpmake.pp, fpmake executable already exists'; SLogRunningFPMake = 'Running fpmake'; SLogRunAction = 'Action: %s %s'; + SLogLoadingCompilerConfig = 'Loading compiler configuration from "%s"'; + SLogGeneratingCompilerConfig = 'Generating default compiler configuration in "%s"'; + SLogLoadingRepository = 'Loading repository data from "%s"'; + SLogLoadingVersions = 'Loading versions data from "%s"'; + implementation diff --git a/utils/fppkg/pkgmkconv.pp b/utils/fppkg/pkgmkconv.pp index 806151bf83..54145e746c 100644 --- a/utils/fppkg/pkgmkconv.pp +++ b/utils/fppkg/pkgmkconv.pp @@ -42,7 +42,7 @@ Type procedure ConvertFile(const AFileName: String; Src: TStrings; Dir,OS : String); Procedure ConvertFile(Const Source,Dest: String); Public - Function Execute(const Args:array of string):boolean;override; + Function Execute(const Args:TActionArgs):boolean;override; end; @@ -694,7 +694,7 @@ begin end; end; -function TMakeFileConverter.Execute(const Args:array of string):boolean; +function TMakeFileConverter.Execute(const Args:TActionArgs):boolean; begin {$warning TODO Check arguments} ConvertFile(Args[1],Args[2]); diff --git a/utils/fppkg/pkgropts.pp b/utils/fppkg/pkgropts.pp index 5ae7697a01..53d617a91c 100644 --- a/utils/fppkg/pkgropts.pp +++ b/utils/fppkg/pkgropts.pp @@ -24,42 +24,60 @@ Type TPackagerOptions = Class(TPersistent) private + FDirty: Boolean; + // Global options FRemoteMirrorsLocation : String; FLocalMirrorsLocation : String; FRemoteRepository : String; FLocalRepository : String; - FInstallDir : String; - FBuildDir : String; - FCompiler : String; - FCPU: TCPU; - FDirty: Boolean; - FOS: TOS; + FCompilerConfigDir, + FPackagesDir, + FBuildDir, FLocalDir : String; + FDefaultVerbosity, + FDefaultCompilerConfig : String; + // Compiler specific options + FCompiler : String; + FCompilerCPU: TCPU; + FCompilerOS: TOS; + FCompilerVersion : String; + FInstallDir : String; function GetOptString(Index: integer): String; - procedure SetCPU(const AValue: TCPU); procedure SetOptString(Index: integer; const AValue: String); - procedure SetOS(const AValue: TOS); + procedure SetCompilerCPU(const AValue: TCPU); + procedure SetCompilerOS(const AValue: TOS); protected Property LocalDir : String Read FLocalDir; Public Constructor Create; - Procedure InitDefaults; - Procedure LoadFromIni(Ini : TCustomIniFile); virtual; - Procedure SaveToIni(Ini : TCustomIniFile); virtual; - Procedure LoadFromFile(FileName : String); - Procedure SaveToFile(FileName : String); + 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); Property Dirty : Boolean Read FDirty; + function LocalVersions(CompilerConfig: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 InstallDir : String Index 4 Read GetOptString Write SetOptString; Property BuildDir : String Index 5 Read GetOptString Write SetOptString; Property Compiler : String Index 6 Read GetOptString Write SetOptString; - Property Target : String Index 7 Read GetOptString Write SetOptString; - Property OS : TOS Read FOS Write SetOS; - Property CPU : TCPU Read FCPU Write SetCPU; + Property CompilerTarget : 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 InstallDir : String Index 10 Read GetOptString Write SetOptString; + Property DefaultVerbosity : String Index 11 Read GetOptString Write SetOptString; + Property PackagesDir : String Index 12 Read GetOptString Write SetOptString; + Property CompilerConfigDir : String Index 13 Read GetOptString Write SetOptString; + Property CompilerOS : TOS Read FCompilerOS Write SetCompilerOS; + Property CompilerCPU : TCPU Read FCompilerCPU Write SetCompilerCPU; end; Const @@ -72,26 +90,38 @@ Const DefaultUnixBuildDir = '/tmp/fppkg/'; DefaultMirrors = 'mirrors.xml'; DefaultRepository = 'repository.dat'; + DefaultVersions = 'versions.dat'; // ini file keys SDefaults = 'Defaults'; + // Global config KeyLocalMirrorsLocation = 'LocalMirrors'; KeyRemoteMirrorsLocation = 'RemoteMirrors'; KeyRemoteRepository = 'RemoteRepository'; KeyLocalRepository = 'LocalRepository'; - KeyInstallDir = 'InstallDir'; + KeyDefaultConfig = 'DefaultCompilerConfig'; + KeyCompilerConfigDir = 'CompilerConfigDir'; + KeyPackagesDir = 'PackagesDir'; KeyBuildDir = 'BuildDir'; + KeyVerbosity = 'Verbosity'; + // Compiler dependent config + KeyInstallDir = 'InstallDir'; KeyCompiler = 'Compiler' ; - KeyOS = 'OS'; - KeyCPU = 'CPU'; + KeyCompilerOS = 'OS'; + KeyCompilerCPU = 'CPU'; + KeyCompilerVersion = 'Version'; Implementation +uses {$ifdef unix} -uses baseunix; + baseunix {$endif} + pkghandler, + pkgmessages; + Function FixPath(S : String) : string; begin @@ -104,6 +134,12 @@ end; { TPackagerOptions } +constructor TPackagerOptions.Create; +begin + InitGlobalDefaults; +end; + + function TPackagerOptions.GetOptString(Index: integer): String; begin Case Index of @@ -111,20 +147,18 @@ begin 1 : Result:=FLocalMirrorsLocation; 2 : Result:=FRemoteRepository; 3 : Result:=FLocalRepository; - 4 : Result:=FInstallDir; 5 : Result:=FBuildDir; 6 : Result:=FCompiler; - 7 : Result:=MakeTargetString(CPU,OS); + 7 : Result:=MakeTargetString(CompilerCPU,CompilerOS); + 8 : Result:=FDefaultCompilerConfig; + 9 : Result:=FCompilerVersion; + 10 : Result:=FInstallDir; + 11 : Result:=FDefaultVerbosity; + 12 : Result:=FPackagesDir; + 13 : Result:=FCompilerConfigDir; end; end; -procedure TPackagerOptions.SetCPU(const AValue: TCPU); -begin - if FCPU=AValue then exit; - FCPU:=AValue; - FDirty:=True; -end; - procedure TPackagerOptions.SetOptString(Index: integer; const AValue: String); begin If AValue=GetOptString(Index) then @@ -134,32 +168,46 @@ begin 1 : FRemoteMirrorsLocation:=AValue; 2 : FRemoteRepository:=AValue; 3 : FLocalRepository:=AValue; - 4 : FInstallDir:=FixPath(AValue); 5 : FBuildDir:=FixPath(AValue); 6 : FCompiler:=AValue; - 7 : StringToCPUOS(AValue,FCPU,FOS); + 7 : StringToCPUOS(AValue,FCompilerCPU,FCompilerOS); + 8 : FDefaultCompilerConfig:=AValue; + 9 : FCompilerVersion:=AValue; + 10 : FInstallDir:=FixPath(AValue); + 11 : FDefaultVerbosity:=AValue; + 12 : FPackagesDir:=FixPath(AValue); + 13 : FCompilerConfigDir:=FixPath(AValue); end; FDirty:=True; end; -procedure TPackagerOptions.SetOS(const AValue: TOS); + +procedure TPackagerOptions.SetCompilerCPU(const AValue: TCPU); begin - if FOS=AValue then exit; - FOS:=AValue; + if FCompilerCPU=AValue then + exit; + FCompilerCPU:=AValue; FDirty:=True; end; -constructor TPackagerOptions.Create; + +procedure TPackagerOptions.SetCompilerOS(const AValue: TOS); begin - InitDefaults; + if FCompilerOS=AValue then + exit; + FCompilerOS:=AValue; + FDirty:=True; end; -Procedure TPackagerOptions.InitDefaults; +function TPackagerOptions.LocalVersions(CompilerConfig:String):string; +begin + Result:=ExtractFilePath(FLocalRepository)+'versions-'+CompilerConfig+'.dat'; +end; + + +Procedure TPackagerOptions.InitGlobalDefaults; begin - FCPU:=StringToCPU(DefaultCPU); - FOS:=StringToOS(DefaultOS); - FCompiler:=DefaultCompiler; FRemoteMirrorsLocation:=DefaultMirrorsLocation; FRemoteRepository:=DefaultRemoteRepository; {$ifdef unix} @@ -167,75 +215,153 @@ begin FLocalDir:=DefaultUnixPrefix else FLocalDir:=IncludeTrailingPathDelimiter(GetEnvironmentVariable('HOME'))+'.fppkg/'; - FBuildDir:=DefaultUnixBuildDir; {$else} // Change as needed on all OS-es... - FLocalDir:=ExtractFilePath(Paramstr(0)); - FBuildDir:=FLocalDir+'build'+PathDelim; + FLocalDir:=ExtractFilePath(Paramstr(0))+'fppkg'+PathDelim; {$endif} + FBuildDir:=FLocalDir+'build'+PathDelim; + FPackagesDir:=FLocalDir+'packages'+PathDelim; + FCompilerConfigDir:=FLocalDir+'config'+PathDelim; FLocalMirrorsLocation:=FLocalDir+DefaultMirrors; FLocalRepository:=FLocalDir+DefaultRepository; + FDefaultCompilerConfig:='default'; + FDefaultVerbosity:='error,info,debug,commands'; end; -procedure TPackagerOptions.LoadFromIni(Ini: TCustomIniFile); - + +Procedure TPackagerOptions.InitCompilerDefaults; +begin + FCompiler:=FileSearch(DefaultCompiler+ExeExt,GetEnvironmentVariable('PATH')); + if FCompiler='' then + Error(SErrMissingFPC); +{$warning TODO detect compiler version/target from -i options } + FCompilerVersion:='2.0.4'; + FCompilerCPU:=StringToCPU(DefaultCPU); + FCompilerOS:=StringToOS(DefaultOS); + // Use the same algorithm as the compiler, see options.pas +{$ifdef Unix} + FInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR')); + if FInstallDir='' then + begin + if DirectoryExists('/usr/local/lib/fpc/'+FCompilerVersion) then + FInstallDir:='/usr/local/lib/fpc/'+FCompilerVersion+'/' + else + FInstallDir:='/usr/lib/fpc/'+FCompilerVersion+'/'; + end; +{$else unix} + FInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR')); + if FInstallDir='' then + begin + FInstallDir:=ExtractFilePath(FCompiler)+'../'; + if not(DirectoryExists(FInstallDir+'/units')) and + not(DirectoryExists(FInstallDir+'/rtl')) then + FInstallDir:=FInstallDir+'../'; + end; +{$endif unix} +end; +procedure TPackagerOptions.LoadGlobalFromIni(Ini: TCustomIniFile); begin With Ini do begin - FLocalMirrorsLocation:=ReadString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation); - FRemoteMirrorsLocation:=ReadString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation); - FRemoteRepository:=ReadString(SDefaults,KeyRemoteRepository,FRemoteRepository); - FLocalRepository:=ReadString(SDefaults,KeyLocalRepository,FLocalRepository); - FInstallDir:=FixPath(ReadString(SDefaults,KeyInstallDir,FInstallDir)); - FBuildDir:=FixPath(ReadString(SDefaults,KeyBuildDir,FBuildDir)); - FCompiler:=ReadString(SDefaults,KeyCompiler,FCompiler); - FOS:=StringToOS(ReadString(SDefaults,KeyOS,OSToString(OS))); - FCPU:=StringToCPU(ReadString(SDefaults,KeyCPU,CPUtoString(CPU))); + FLocalMirrorsLocation:=ReadString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation); + FRemoteMirrorsLocation:=ReadString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation); + FRemoteRepository:=ReadString(SDefaults,KeyRemoteRepository,FRemoteRepository); + FLocalRepository:=ReadString(SDefaults,KeyLocalRepository,FLocalRepository); + FBuildDir:=FixPath(ReadString(SDefaults,KeyBuildDir,FBuildDir)); + FDefaultCompilerConfig:=ReadString(SDefaults,KeyDefaultConfig,FDefaultCompilerConfig); end; - end; -procedure TPackagerOptions.SaveToIni(Ini: TCustomIniFile); + +procedure TPackagerOptions.SaveGlobalToIni(Ini: TCustomIniFile); begin With Ini do begin - WriteString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation); - WriteString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation); - WriteString(SDefaults,KeyRemoteRepository,FRemoteRepository); - WriteString(SDefaults,KeyLocalRepository,FLocalRepository); - WriteString(SDefaults,KeyInstallDir,FInstallDir); - WriteString(SDefaults,KeyBuildDir,FBuildDir); - WriteString(SDefaults,KeyCompiler,FCompiler); - WriteString(SDefaults,KeyOS,OSToString(OS)); - WriteString(SDefaults,KeyCPU,CPUtoString(CPU)); + WriteString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation); + WriteString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation); + WriteString(SDefaults,KeyRemoteRepository,FRemoteRepository); + WriteString(SDefaults,KeyLocalRepository,FLocalRepository); + WriteString(SDefaults,KeyBuildDir,FBuildDir); + WriteString(SDefaults,KeyDefaultConfig,FDefaultCompilerConfig); end; end; -procedure TPackagerOptions.LoadFromFile(FileName: String); +procedure TPackagerOptions.LoadGlobalFromFile(FileName: String); Var Ini : TMemIniFile; - begin Ini:=TMemIniFile.Create(FileName); try - LoadFromIni(Ini); + LoadGlobalFromIni(Ini); finally Ini.Free; end; end; -procedure TPackagerOptions.SaveToFile(FileName: String); +procedure TPackagerOptions.SaveGlobalToFile(FileName: String); Var Ini : TIniFile; - begin Ini:=TIniFile.Create(FileName); try - SaveToIni(Ini); + SaveGlobalToIni(Ini); + Ini.UpdateFile; + finally + Ini.Free; + end; +end; + + +procedure TPackagerOptions.LoadCompilerFromIni(Ini: TCustomIniFile); +begin + With Ini do + begin + FInstallDir:=FixPath(ReadString(SDefaults,KeyInstallDir,FInstallDir)); + FCompiler:=ReadString(SDefaults,KeyCompiler,FCompiler); + FCompilerOS:=StringToOS(ReadString(SDefaults,KeyCompilerOS,OSToString(CompilerOS))); + FCompilerCPU:=StringToCPU(ReadString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU))); + FCompilerVersion:=ReadString(SDefaults,KeyCompilerVersion,FCompilerVersion); + end; +end; + + +procedure TPackagerOptions.SaveCompilerToIni(Ini: TCustomIniFile); +begin + With Ini do + begin + WriteString(SDefaults,KeyInstallDir,FInstallDir); + WriteString(SDefaults,KeyCompiler,FCompiler); + WriteString(SDefaults,KeyCompilerOS,OSToString(CompilerOS)); + WriteString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU)); + WriteString(SDefaults,KeyCompilerVersion,FCompilerVersion); + end; +end; + + +procedure TPackagerOptions.LoadCompilerFromFile(FileName: String); +Var + Ini : TMemIniFile; +begin + Ini:=TMemIniFile.Create(FileName); + try + LoadCompilerFromIni(Ini); + finally + Ini.Free; + end; +end; + + +procedure TPackagerOptions.SaveCompilerToFile(FileName: String); +Var + Ini : TIniFile; +begin + Ini:=TIniFile.Create(FileName); + try + SaveCompilerToIni(Ini); Ini.UpdateFile; finally Ini.Free;