diff options
author | joost <joost@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2011-06-06 13:48:51 +0000 |
---|---|---|
committer | joost <joost@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2011-06-06 13:48:51 +0000 |
commit | 23523bf23e1e990b768b8ad2232b0970c024d923 (patch) | |
tree | 75e85c3f3c9b3dde16e94ddffbfa35bab1fdf8be /packages/fppkg | |
parent | 58bb0a4930fb54518f5ce9ac7244d32870ff9a02 (diff) | |
download | fpc-23523bf23e1e990b768b8ad2232b0970c024d923.tar.gz |
* Added functionality to ease overriding the repository classes
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@17671 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fppkg')
-rw-r--r-- | packages/fppkg/src/fprepos.pp | 85 | ||||
-rw-r--r-- | packages/fppkg/src/pkgcommands.pp | 2 | ||||
-rw-r--r-- | packages/fppkg/src/pkgglobals.pp | 26 | ||||
-rw-r--r-- | packages/fppkg/src/pkgrepos.pp | 119 |
4 files changed, 138 insertions, 94 deletions
diff --git a/packages/fppkg/src/fprepos.pp b/packages/fppkg/src/fprepos.pp index 15d8c624d7..404eadc21e 100644 --- a/packages/fppkg/src/fprepos.pp +++ b/packages/fppkg/src/fprepos.pp @@ -138,11 +138,14 @@ type procedure SetName(const AValue: String); procedure SetUnusedVersion(const AValue: TFPVersion); procedure SetVersion(const AValue: TFPVersion); + protected + procedure LoadUnitConfigFromStringlist(Const AStringList: TStrings); virtual; Public Constructor Create(ACollection : TCollection); override; Destructor Destroy; override; Procedure LoadFromStream(Stream : TStream; Streamversion : Integer); override; Procedure SaveToStream(Stream : TStream); override; + procedure LoadUnitConfigFromFile(Const AFileName: String); Procedure Assign(Source : TPersistent); override; Function AddDependency(Const APackageName : String; const AMinVersion : String = '') : TFPDependency; Property Dependencies : TFPDependencies Read FDependencies; @@ -191,6 +194,7 @@ type Property StreamVersion : Integer Read FVersion Write FVersion; Property Packages [Index : Integer] : TFPPackage Read GetPackage Write SetPackage; default; end; + TFPPackagesClass = class of TFPPackages; { TFPRepository } @@ -199,10 +203,10 @@ type FMaxDependencyLevel : Integer; FBackUpFiles: Boolean; FFileName: String; - FPackages : TFPPackages; function GetPackage(Index : Integer): TFPPackage; function GetPackageCount: Integer; Protected + FPackages : TFPPackages; procedure CreatePackages; virtual; Procedure BackupFile(const AFileName : String); virtual; Procedure DoGetPackageDependencies(const APackageName : String; List : TStringList; Level : Integer); virtual; @@ -232,6 +236,7 @@ type Property MaxDependencyLevel : Integer Read FMaxDependencyLevel Write FMaxDependencyLevel; Property PackageCollection : TFPPackages Read FPackages; end; + TFPRepositoryClass = class of TFPRepository; { TFPMirror } @@ -296,8 +301,22 @@ Implementation uses typinfo, + pkgglobals, uriparser; +const + // Keys for unit config + KeyName = 'Name'; + KeyVersion = 'Version'; + KeyChecksum = 'Checksum'; + KeyNeedLibC = 'NeedLibC'; + KeyDepends = 'Depends'; + KeyAddIn = 'FPMakeAddIn'; + KeySourcePath = 'SourcePath'; + KeyFPMakeOptions = 'FPMakeOptions'; + KeyCPU = 'CPU'; + KeyOS = 'OS'; + ResourceString SErrInvalidCPU = 'Invalid CPU name : "%s"'; SErrInvalidOS = 'Invalid OS name : "%s"'; @@ -658,6 +677,70 @@ begin FDependencies.SaveToStream(Stream); end; +procedure TFPPackage.LoadUnitConfigFromStringlist(const AStringList: TStrings); +var + L2 : TStrings; + VOS : TOS; + VCPU : TCPU; + i,k : Integer; + DepChecksum : Cardinal; + DepName : String; + D : TFPDependency; +begin + With AStringList do + begin + Version.AsString:=Values[KeyVersion]; + SourcePath:=Values[KeySourcePath]; + FPMakeOptionsString:=Values[KeyFPMakeOptions]; + Checksum:=Cardinal(StrToInt64Def(Values[KeyChecksum],$ffffffff)); + VCPU:=StringToCPU(Values[KeyCPU]); + VOS:=StringToOS(Values[KeyOS]); + OSes:=[VOS]; + CPUs:=[VCPU]; + L2:=TStringList.Create; + L2.CommaText:=Values[KeyDepends]; + for i:=0 to L2.Count-1 do + begin + DepName:=L2[i]; + k:=Pos('|',DepName); + if k>0 then + begin + DepChecksum:=StrToInt(Copy(DepName,k+1,Length(DepName)-k)); + DepName:=Copy(DepName,1,k-1); + end + else + DepChecksum:=$ffffffff; + D:=nil; + for k:=0 to Dependencies.Count-1 do + begin + D:=Dependencies[k]; + if D.PackageName=DepName then + break; + D:=nil; + end; + if not assigned(D) then + D:=AddDependency(DepName,''); + D.RequireChecksum:=DepChecksum; + end; + FreeAndNil(L2); + //NeedLibC:=Upcase(Values[KeyNeedLibC])='Y'; + IsFPMakeAddIn:=Upcase(Values[KeyAddIn])='Y'; + end; +end; + +procedure TFPPackage.LoadUnitConfigFromFile(const AFileName: String); +var + L : TStrings; +begin + L:=TStringList.Create; + Try + ReadIniFile(AFileName,L); + LoadUnitConfigFromStringlist(L); + Finally + L.Free; + end; +end; + procedure TFPPackage.Assign(Source: TPersistent); Var diff --git a/packages/fppkg/src/pkgcommands.pp b/packages/fppkg/src/pkgcommands.pp index 28bd147472..b35173866c 100644 --- a/packages/fppkg/src/pkgcommands.pp +++ b/packages/fppkg/src/pkgcommands.pp @@ -322,7 +322,7 @@ begin UFN:=CompilerOptions.LocalUnitDir; end; UFN:=IncludeTrailingPathDelimiter(UFN)+S+PathDelim+UnitConfigFileName; - LoadUnitConfigFromFile(P,UFN); + P.LoadUnitConfigFromFile(UFN); if P.IsFPMakeAddIn then AddFPMakeAddIn(P); end diff --git a/packages/fppkg/src/pkgglobals.pp b/packages/fppkg/src/pkgglobals.pp index 4c6968bfaa..f08dad086f 100644 --- a/packages/fppkg/src/pkgglobals.pp +++ b/packages/fppkg/src/pkgglobals.pp @@ -83,6 +83,7 @@ Procedure SearchFiles(SL:TStringList;const APattern: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; +procedure ReadIniFile(Const AFileName: String;L:TStrings); var LogLevels : TLogLevels; @@ -392,6 +393,31 @@ begin {$endif unix} end; +procedure ReadIniFile(Const AFileName: String;L:TStrings); +Var + F : TFileStream; + Line : String; + I,P,PC : Integer; +begin + F:=TFileStream.Create(AFileName,fmOpenRead); + Try + L.LoadFromStream(F); + // Fix lines. + For I:=L.Count-1 downto 0 do + begin + Line:=L[I]; + P:=Pos('=',Line); + PC:=Pos(';',Line); // Comment line. + If (P=0) or ((PC<>0) and (PC<P)) then + L.Delete(I) + else + L[i]:=Trim(System.Copy(Line,1,P-1)+'='+Trim(System.Copy(Line,P+1,Length(Line)-P))); + end; + Finally + F.Free; + end; +end; + initialization OnGetVendorName:=@FPPkgGetVendorName; diff --git a/packages/fppkg/src/pkgrepos.pp b/packages/fppkg/src/pkgrepos.pp index 7dd9e221e1..85889a52cc 100644 --- a/packages/fppkg/src/pkgrepos.pp +++ b/packages/fppkg/src/pkgrepos.pp @@ -12,7 +12,6 @@ function GetRemoteRepositoryURL(const AFileName:string):string; procedure LoadLocalAvailableMirrors; procedure LoadLocalAvailableRepository; -procedure LoadUnitConfigFromFile(APackage:TFPPackage;const AFileName: String); function LoadManifestFromFile(const AManifestFN:string):TFPPackage; procedure FindInstalledPackages(ACompilerOptions:TCompilerOptions;showdups:boolean=true); Procedure AddFPMakeAddIn(APackage: TFPPackage); @@ -29,6 +28,8 @@ procedure ListRemoteRepository; procedure RebuildRemoteRepository; procedure SaveRemoteRepository; +procedure SetDefaultRepositoryClass(ARepositoryClass: TFPRepositoryClass); + var AvailableMirrors : TFPMirrors; AvailableRepository, @@ -43,12 +44,30 @@ uses pkgglobals, pkgmessages; -{***************************************************************************** - Mirror Selection -*****************************************************************************} +resourcestring + SErrRepositoryClassAlreadyAssigned = 'Default repository class is already assigned.'; var CurrentRemoteRepositoryURL : String; + RepositoryClass : TFPRepositoryClass; + +procedure SetDefaultRepositoryClass(ARepositoryClass: TFPRepositoryClass); +begin + if assigned(RepositoryClass) then + raise exception.Create(SErrRepositoryClassAlreadyAssigned); + RepositoryClass:=ARepositoryClass; +end; + +function GetDefaultRepositoryClass: TFPRepositoryClass; +begin + if not assigned(RepositoryClass) then + SetDefaultRepositoryClass(TFPRepository); + result := RepositoryClass; +end; + +{***************************************************************************** + Mirror Selection +*****************************************************************************} procedure LoadLocalAvailableMirrors; var @@ -142,32 +161,6 @@ end; Local Repository *****************************************************************************} -procedure ReadIniFile(Const AFileName: String;L:TStrings); -Var - F : TFileStream; - Line : String; - I,P,PC : Integer; -begin - F:=TFileStream.Create(AFileName,fmOpenRead); - Try - L.LoadFromStream(F); - // Fix lines. - For I:=L.Count-1 downto 0 do - begin - Line:=L[I]; - P:=Pos('=',Line); - PC:=Pos(';',Line); // Comment line. - If (P=0) or ((PC<>0) and (PC<P)) then - L.Delete(I) - else - L[i]:=Trim(System.Copy(Line,1,P-1)+'='+Trim(System.Copy(Line,P+1,Length(Line)-P))); - end; - Finally - F.Free; - end; -end; - - function LoadManifestFromFile(const AManifestFN:string):TFPPackage; var X : TFPXMLRepositoryHandler; @@ -200,64 +193,6 @@ begin end; -procedure LoadUnitConfigFromFile(APackage:TFPPackage;const AFileName: String); -Var - L,DepSL : TStrings; - DepName, - V : String; - DepChecksum : Cardinal; - i,j,k : integer; - D : TFPDependency; -begin - L:=TStringList.Create; - Try - ReadIniFile(AFileName,L); -{$warning TODO Maybe check also CPU-OS} - // Read fpunits.conf - V:=L.Values['version']; - APackage.Version.AsString:=V; - APackage.IsFPMakeAddIn:=Upcase(L.Values['FPMakeAddIn'])='Y'; - APackage.SourcePath:=L.Values['SourcePath']; - APackage.FPMakeOptionsString:=L.Values['FPMakeOptions']; - V:=L.Values['checksum']; - if V<>'' then - APackage.Checksum:=StrToInt(V) - else - APackage.Checksum:=$ffffffff; - // Load dependencies - V:=L.Values['depends']; - DepSL:=TStringList.Create; - DepSL.CommaText:=V; - for i:=0 to DepSL.Count-1 do - begin - DepName:=DepSL[i]; - k:=Pos('|',DepName); - if k>0 then - begin - DepChecksum:=StrToInt(Copy(DepName,k+1,Length(DepName)-k)); - DepName:=Copy(DepName,1,k-1); - end - else - DepChecksum:=$ffffffff; - D:=nil; - for j:=0 to APackage.Dependencies.Count-1 do - begin - D:=APackage.Dependencies[j]; - if D.PackageName=DepName then - break; - D:=nil; - end; - if not assigned(D) then - D:=APackage.AddDependency(DepName,''); - D.RequireChecksum:=DepChecksum; - end; - DepSL.Free; - Finally - L.Free; - end; -end; - - procedure FindInstalledPackages(ACompilerOptions:TCompilerOptions;showdups:boolean=true); function AddInstalledPackage(const AName,AFileName: String; const Local: boolean):TFPPackage; @@ -309,7 +244,7 @@ procedure FindInstalledPackages(ACompilerOptions:TCompilerOptions;showdups:boole if FileExistsLog(UF) then begin P:=AddInstalledPackage(SR.Name,UF,Local); - LoadUnitConfigFromFile(P,UF); + P.LoadUnitConfigFromFile(UF); if P.IsFPMakeAddIn then AddFPMakeAddIn(P); end @@ -331,7 +266,7 @@ procedure FindInstalledPackages(ACompilerOptions:TCompilerOptions;showdups:boole begin if assigned(InstalledRepository) then InstalledRepository.Free; - InstalledRepository:=TFPRepository.Create(nil); + InstalledRepository:=GetDefaultRepositoryClass.Create(nil); // First scan the global directory // The local directory will overwrite the versions if ACompilerOptions.GlobalUnitDir<>'' then @@ -475,7 +410,7 @@ var begin if assigned(AvailableRepository) then AvailableRepository.Free; - AvailableRepository:=TFPRepository.Create(Nil); + AvailableRepository:=GetDefaultRepositoryClass.Create(Nil); // Repository S:=GlobalOptions.LocalPackagesFile; log(vlDebug,SLogLoadingPackagesFile,[S]); @@ -673,7 +608,7 @@ var begin if assigned(InstalledRepository) then InstalledRepository.Free; - InstalledRepository:=TFPRepository.Create(Nil); + InstalledRepository:=GetDefaultRepositoryClass.Create(Nil); try ManifestSL:=TStringList.Create; ManifestSL.Add(ManifestFileName); |