Bläddra i källkod

* Generate fpunits.conf on compilation, not installation. So that dependencies
on compiled but not yet installed packages are handled properly.
* Moved all logic to determine unit-directory to the GetUnitDirectory method

git-svn-id: trunk@17921 -

joost 14 år sedan
förälder
incheckning
359b1c0a59
1 ändrade filer med 73 tillägg och 40 borttagningar
  1. 73 40
      packages/fpmkunit/src/fpmkunit.pp

+ 73 - 40
packages/fpmkunit/src/fpmkunit.pp

@@ -798,6 +798,7 @@ Type
     Procedure EnterDir(ADir : String);
     Procedure EnterDir(ADir : String);
     Function GetCompiler : String;
     Function GetCompiler : String;
     Function InstallPackageFiles(APAckage : TPackage; tt : TTargetType; Const Dest : String):Boolean;
     Function InstallPackageFiles(APAckage : TPackage; tt : TTargetType; Const Dest : String):Boolean;
+    Procedure InstallUnitConfigFile(APAckage : TPackage; Const Dest : String);
     Function InstallPackageSourceFiles(APAckage : TPackage; tt : TSourceType; Const Dest : String):Boolean;
     Function InstallPackageSourceFiles(APAckage : TPackage; tt : TSourceType; Const Dest : String):Boolean;
     Function FileNewer(const Src,Dest : String) : Boolean;
     Function FileNewer(const Src,Dest : String) : Boolean;
     Procedure LogSearchPath(const ASearchPathName:string;Path:TConditionalStrings; ACPU:TCPU;AOS:TOS);
     Procedure LogSearchPath(const ASearchPathName:string;Path:TConditionalStrings; ACPU:TCPU;AOS:TOS);
@@ -4084,29 +4085,53 @@ end;
 
 
 function TBuildEngine.GetUnitDir(APackage:TPackage):String;
 function TBuildEngine.GetUnitDir(APackage:TPackage):String;
 begin
 begin
-  // Retrieve Full directory name where to find the units.
-  // The search order is:
-  //  - Package in this fpmake.pp
-  //  - LocalUnitDir
-  //  - GlobalUnitDir
-  if (APackage.UnitDir='') and
-     (APackage.State in [tsCompiled, tsNoCompile]) then
-    begin
-      APackage.UnitDir:=IncludeTrailingPathDelimiter(FStartDir)+IncludeTrailingPathDelimiter(APackage.Directory)+APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS);
-    end;
-  if (APackage.UnitDir='') and
-     (Defaults.LocalUnitDir<>'') then
-    begin
-      APackage.UnitDir:=IncludeTrailingPathDelimiter(Defaults.LocalUnitDir)+APackage.Name;
-      if not SysDirectoryExists(APackage.UnitDir) then
-        APackage.UnitDir:='';
-    end;
   if APackage.UnitDir='' then
   if APackage.UnitDir='' then
     begin
     begin
-      APackage.UnitDir:=IncludeTrailingPathDelimiter(Defaults.GlobalUnitDir)+APackage.Name;
-      if not SysDirectoryExists(APackage.UnitDir) then
-        APackage.UnitDir:=DirNotFound;
+      // Retrieve Full directory name where to find the units.
+      // The search order is:
+      //  - Package in this fpmake.pp
+      //  - LocalUnitDir
+      //  - GlobalUnitDir
+      if (APackage.State in [tsCompiled, tsNoCompile]) then
+        begin
+          APackage.UnitDir:=IncludeTrailingPathDelimiter(FStartDir)+IncludeTrailingPathDelimiter(APackage.Directory)+APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS);
+        end;
+      if (APackage.UnitDir='') and
+         (Defaults.LocalUnitDir<>'') then
+        begin
+          APackage.UnitDir:=IncludeTrailingPathDelimiter(Defaults.LocalUnitDir)+APackage.Name;
+          if not SysDirectoryExists(APackage.UnitDir) then
+            APackage.UnitDir:='';
+        end;
+      if APackage.UnitDir='' then
+        begin
+          APackage.UnitDir:=IncludeTrailingPathDelimiter(Defaults.GlobalUnitDir)+APackage.Name;
+          if not SysDirectoryExists(APackage.UnitDir) then
+            APackage.UnitDir:=DirNotFound;
+        end;
+
+      if (APackage.UnitDir<>DirNotFound) then
+        begin
+          if FileExists(IncludeTrailingPathDelimiter(APackage.UnitDir)+FPMakePPFile) then
+            begin
+              // The package is not installed, but the source-path is detected.
+              // It is an external package so it is impossible to compile it, so
+              // assume that it has been compiled earlier.
+              APackage.UnitDir := IncludeTrailingPathDelimiter(APackage.UnitDir) + APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS);
+              // If the unit-directory does not exist, you know for sure that
+              // the package is not compiled
+              if not DirectoryExists(APackage.UnitDir) then
+                APackage.UnitDir:=DirNotFound
+              else
+                APackage.FTargetState:=tsCompiled;
+            end
+          else
+            begin
+              APackage.FTargetState:=tsInstalled;
+            end;
+        end;
     end;
     end;
+
   // Special error marker to prevent searches in case of error
   // Special error marker to prevent searches in case of error
   if APackage.UnitDir=DirNotFound then
   if APackage.UnitDir=DirNotFound then
     Result:=''
     Result:=''
@@ -4560,27 +4585,12 @@ begin
   if S<>'' then
   if S<>'' then
     begin
     begin
       Log(vldebug, SDbgExternalDependency, [APackageName,S]);
       Log(vldebug, SDbgExternalDependency, [APackageName,S]);
-      Result.FTargetState:=tsInstalled;
       // Load unit config if it exists
       // Load unit config if it exists
       F:=IncludeTrailingPathDelimiter(S)+UnitConfigFile;
       F:=IncludeTrailingPathDelimiter(S)+UnitConfigFile;
       if FileExists(F) then
       if FileExists(F) then
         begin
         begin
           Log(vlDebug, Format(SDbgLoading, [F]));
           Log(vlDebug, Format(SDbgLoading, [F]));
           Result.LoadUnitConfigFromFile(F);
           Result.LoadUnitConfigFromFile(F);
-        end
-      else if FileExists(IncludeTrailingPathDelimiter(S)+FPMakePPFile) then
-        begin
-          // The package is not installed, but the source-path is given.
-          // It is an external package so it is impossible to compile it, so
-          // assume that it has been compiled earlier.
-          F := IncludeTrailingPathDelimiter(Result.UnitDir) + Result.GetUnitsOutputDir(Defaults.CPU,Defaults.OS);
-          // If the unit-directory does not exist, you know for sure that
-          // the package is not compiled
-          if DirectoryExists(F) then
-            begin
-              Result.UnitDir := F;
-              Result.FTargetState:=tsCompiled;
-            end;
         end;
         end;
       // Check recursive implicit dependencies
       // Check recursive implicit dependencies
       CompileDependencies(Result);
       CompileDependencies(Result);
@@ -4640,7 +4650,9 @@ Var
   sFPDocFormat: string;
   sFPDocFormat: string;
   IFPDocFormat: TFPDocFormat;
   IFPDocFormat: TFPDocFormat;
   d: integer;
   d: integer;
+  UC: string;
   dep: TDependency;
   dep: TDependency;
+  RegenerateUnitconfigFile: boolean;
 begin
 begin
   cmdOpts := '';
   cmdOpts := '';
 
 
@@ -4652,6 +4664,7 @@ begin
     Dictionary.AddVariable('UNITSOUTPUTDIR',APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS));
     Dictionary.AddVariable('UNITSOUTPUTDIR',APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS));
     Dictionary.AddVariable('BINOUTPUTDIR',APackage.GetBinOutputDir(Defaults.CPU,Defaults.OS));
     Dictionary.AddVariable('BINOUTPUTDIR',APackage.GetBinOutputDir(Defaults.CPU,Defaults.OS));
     DoBeforeCompile(APackage);
     DoBeforeCompile(APackage);
+    RegenerateUnitconfigFile:=False;
     For I:=0 to APackage.Targets.Count-1 do
     For I:=0 to APackage.Targets.Count-1 do
       begin
       begin
         T:=APackage.Targets.TargetItems[i];
         T:=APackage.Targets.TargetItems[i];
@@ -4663,6 +4676,9 @@ begin
               begin
               begin
                 if T.State=tsNeutral then
                 if T.State=tsNeutral then
                   MaybeCompile(APackage,T);
                   MaybeCompile(APackage,T);
+                // If a target is compiled, re-generate the UnitConfigFile
+                if T.FTargetState<>tsNoCompile then
+                  RegenerateUnitconfigFile:= True;
               end
               end
             else
             else
               begin
               begin
@@ -4691,6 +4707,13 @@ begin
         end;
         end;
       end;
       end;
 
 
+    if RegenerateUnitconfigFile then
+      begin
+        UC:=IncludeTrailingPathDelimiter(APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS))+UnitConfigFile;
+        Log(vlInfo, Format(SDbgGenerating, [UC]));
+        APackage.SaveUnitConfigToFile(UC,Defaults.CPU,Defaults.OS);
+      end;
+
     //compile documentation, because options were found
     //compile documentation, because options were found
     if cmdOpts <> '' then
     if cmdOpts <> '' then
     begin
     begin
@@ -4771,6 +4794,19 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TBuildEngine.InstallUnitConfigFile(APAckage: TPackage; const Dest: String);
+Var
+  List : TStringList;
+begin
+  List:=TStringList.Create;
+  Try
+    List.add(IncludeTrailingPathDelimiter(APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS))+UnitConfigFile);
+    CmdCopyFiles(List,Dest);
+  Finally
+    List.Free;
+  end;
+end;
+
 function TBuildEngine.InstallPackageSourceFiles(APAckage: TPackage; tt: TSourceType; const Dest: String): Boolean;
 function TBuildEngine.InstallPackageSourceFiles(APAckage: TPackage; tt: TSourceType; const Dest: String): Boolean;
 Var
 Var
   List : TStringList;
   List : TStringList;
@@ -4830,11 +4866,7 @@ begin
     //  B:=true;
     //  B:=true;
     // Unit (dependency) configuration if there were units installed
     // Unit (dependency) configuration if there were units installed
     if B then
     if B then
-      begin
-        UC:=IncludeTrailingPathDelimiter(D)+UnitConfigFile;
-        Log(vlInfo, Format(SDbgGenerating, [UC]));
-        APackage.SaveUnitConfigToFile(UC,Defaults.CPU,Defaults.OS);
-      end;
+      InstallUnitConfigFile(APackage,D);
     // Programs
     // Programs
     D:=IncludeTrailingPathDelimiter(Defaults.BinInstallDir);
     D:=IncludeTrailingPathDelimiter(Defaults.BinInstallDir);
     InstallPackageFiles(APAckage,ttProgram,D);
     InstallPackageFiles(APAckage,ttProgram,D);
@@ -4960,6 +4992,7 @@ begin
     DoBeforeClean(Apackage);
     DoBeforeClean(Apackage);
     List:=TStringList.Create;
     List:=TStringList.Create;
     try
     try
+      List.Add(APackage.GetUnitsOutputDir(Defaults.CPU,Defaults.OS) + PathDelim + UnitConfigFile);
       APackage.GetCleanFiles(List,Defaults.CPU,Defaults.OS);
       APackage.GetCleanFiles(List,Defaults.CPU,Defaults.OS);
       if (List.Count>0) then
       if (List.Count>0) then
         begin
         begin