Browse Source

* Unified determination of source-package
* Scan installed packages for their sources in the same order as they are
used
* Added test for both points

git-svn-id: trunk@36338 -

joost 8 năm trước cách đây
mục cha
commit
f5d17b2884

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

@@ -421,7 +421,7 @@ begin
     begin
       ExecuteAction(PackageName,'build');
 
-      AvailPackage := PackageManager.FindPackage(PackageName, pkgpkAvailable);
+      AvailPackage := PackageManager.DetermineSourcePackage(PackageName);
       InstallRepo := PackageManager.GetInstallRepository(AvailPackage);
       case InstallRepo.DefaultPackagesStructure.IsInstallationNeeded(AvailPackage) of
         fpinInstallationNeeded:

+ 1 - 15
packages/fppkg/src/pkgfpmake.pp

@@ -140,22 +140,8 @@ end;
 { TFPMakeCompiler }
 
 function TFPMakeCompiler.DeterminePackage: TFPPackage;
-var
-  PA, PI: TFPPackage;
 begin
-  PA:=PackageManager.FindPackage(PackageName, pkgpkAvailable);
-  PI:=PackageManager.FindPackage(PackageName, pkgpkInstalled);
-  if Assigned(PA) and Assigned(PI) then
-    begin
-    if PA.Version.CompareVersion(PI.Version) > 0 then
-      Result := PA
-    else
-      Result := PI;
-    end
-  else if Assigned(PI) then
-    Result := PI
-  else
-    Result := PA;
+  Result := PackageManager.DetermineSourcePackage(PackageName);
 
   if not Assigned(Result) then
     Raise EPackage.CreateFmt(SErrMissingPackage,[PackageName]);

+ 7 - 1
packages/fppkg/src/pkgfppkg.pp

@@ -62,6 +62,7 @@ type
     function RepositoryByName(ARepositoryName: string): TFPRepository;
 
     function GetInstallRepository(ASourcePackage: TFPPackage): TFPRepository;
+    function DetermineSourcePackage(APackageName: String): TFPPackage;
     function PackageLocalArchive(APackage:TFPPackage): String;
     function PackageBuildPath(APackage:TFPPackage):String;
 
@@ -602,6 +603,11 @@ begin
   Result := RepositoryByName(RepoName);
 end;
 
+function TpkgFPpkg.DetermineSourcePackage(APackageName: String): TFPPackage;
+begin
+  Result := FindPackage(APackageName, pkgpkAvailable);
+end;
+
 function TpkgFPpkg.PackageLocalArchive(APackage: TFPPackage): String;
 begin
   if APackage.Name=CurrentDirPackageName then
@@ -618,7 +624,7 @@ var
   Repo, AvailableRepo: TFPRepository;
   AvailStruc: TFPOriginalSourcePackagesStructure;
 begin
-  for i := FRepositoryList.Count-1 downto 0 do
+  for i := 0 to FRepositoryList.Count-1 do
     begin
       Repo := FRepositoryList.Items[i] as TFPRepository;
       if Repo.RepositoryType = fprtInstalled then

+ 74 - 0
packages/fppkg/tests/fullfpcinstallationtests.pas

@@ -43,6 +43,7 @@ type
     procedure TestDefaultInstallLocation;
     procedure TestSourceRepositoryInstallLocation;
     procedure TestConfiguredInstallLocation;
+    procedure TestInstallationLocationOriginalSource;
   end;
 
   { TFullFPCInstallationSetup }
@@ -343,6 +344,79 @@ begin
   RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageusingplugin', ['install'], 'Install package that depends on plugin');
 end;
 
+procedure TFullFPCInstallationTests.TestInstallationLocationOriginalSource;
+var
+  SL: TStringList;
+  Checksum: Int64;
+  FPMFilename, S: string;
+
+  procedure CheckBrokenPackages(ExpectBrokenPackages: Boolean);
+  var
+    FPpkg: TpkgFPpkg;
+  begin
+    FPpkg := TpkgFPpkg.Create(nil);
+    try
+      FPpkg.InitializeGlobalOptions(ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath,'etc','fppkg.cfg']));
+      FPpkg.Options.GlobalSection.Downloader := 'FPC';
+      FPpkg.InitializeCompilerOptions;
+
+      FPpkg.CompilerOptions.InitCompilerDefaults;
+      FPpkg.FpmakeCompilerOptions.InitCompilerDefaults;
+      FPpkg.CompilerOptions.CheckCompilerValues;
+      FPpkg.FpmakeCompilerOptions.CheckCompilerValues;
+      FPpkg.LoadLocalAvailableMirrors;
+
+      FPpkg.ScanAvailablePackages;
+      FPpkg.ScanPackages;
+
+      SL := TStringList.Create;
+      try
+        FPpkg.FindBrokenPackages(SL);
+        if ExpectBrokenPackages then
+          check(SL.Count>0, 'There should be broken packages')
+        else
+          check(SL.Count=0, 'There should not be any broken packages');
+      finally
+        SL.Free;
+      end;
+    finally
+      FPpkg.Free;
+    end;
+  end;
+
+begin
+  // Test whether a once installed package on a re-install is installed into the
+  // right (original) location.
+  TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packagea');
+  TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('packageb');
+
+  RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packagea', ['install'], 'Install package A');
+  RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['install'], 'Install package B');
+  RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageb', ['install', '-i', 'fpc'], 'Install package B');
+
+  CheckBrokenPackages(False);
+
+  // Break packageb on purpose, by changing the checksum of packagea
+  SL := TStringList.Create;
+  try
+    FPMFilename := ConcatPaths([TFullFPCInstallationSetup.GetCurrentTestPath, 'user', 'lib', 'fpc', TFullFPCInstallationSetup.GetCompilerVersion, 'fpmkinst', TFullFPCInstallationSetup.GetTargetString, 'packagea.fpm']);
+    SL.LoadFromFile(FPMFilename);
+    Checksum := StrToInt64Def(SL.Values['Checksum'], -1);
+    Check(Checksum>-1, 'Determine checksum packagea');
+    SL.Values['Checksum'] := IntToStr(Checksum+1);
+    SL.SaveToFile(FPMFilename);
+  finally
+    SL.Free;
+  end;
+
+  CheckBrokenPackages(True);
+
+  S := RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestPath, ['fixbroken'], 'Fix broken packages');
+  Check(pos('broken',s) = 0, 'Fix broken command should not give any warning that packages are still broken');
+
+  CheckBrokenPackages(False);
+end;
+
 procedure TFullFPCInstallationTests.TestCleanupOfTemporaryBuildpath;
 var
   SR: TSearchRec;