Browse Source

* Cleanup build-files in case of an error + test

git-svn-id: trunk@36198 -
joost 8 years ago
parent
commit
49d75902f6

+ 1 - 0
.gitattributes

@@ -3436,6 +3436,7 @@ packages/fppkg/src/pkguninstalledsrcsrepo.pp svneol=native#text/plain
 packages/fppkg/src/pkgwget.pp svneol=native#text/plain
 packages/fppkg/tests/fppkg_tests.pp svneol=native#text/plain
 packages/fppkg/tests/fullfpcinstallationtests.pas svneol=native#text/plain
+packages/fppkg/tests/packages/base/brokenpackage/fpmake.pp svneol=native#text/pascal
 packages/fppkg/tests/packages/base/packagea/fpmake.pp svneol=native#text/plain
 packages/fppkg/tests/packages/base/packagea/src/PackageAUnitA.pas svneol=native#text/plain
 packages/fppkg/tests/packages/base/packageb/fpmake.pp svneol=native#text/plain

+ 26 - 23
packages/fppkg/src/pkgfpmake.pp

@@ -308,29 +308,32 @@ begin
       // Units in a directory for easy cleaning
       DeleteDir(TempBuildDir);
       ForceDirectories(TempBuildDir);
-      // Compile options
-      //   -- default is to optimize, smartlink and strip to reduce
-      //      the executable size (there can be 100's of fpmake's on a system)
-      if llInfo in LogLevels then
-        AddOption('-vi');
-      AddOption('-O2');
-      AddOption('-XXs');
-      // Create fpmkunit.pp if needed
-      if NeedFPMKUnitSource then
-        begin
-          Log(llWarning,SLogUseInternalFpmkunit);
-          CreateFPMKUnitSource(TempBuildDir+PathDelim+'fpmkunit.pp');
-        end;
-      // Call compiler
-      If ExecuteProcess(PackageManager.FPMakeCompilerOptions.Compiler,OOptions+' '+FPmakeSrc)<>0 then
-        begin
-          if not PackageManager.Options.CommandLineSection.RecoveryMode then
-            Error(SErrCompileFailureFPMakeTryRecovery)
-          else
-            Error(SErrCompileFailureFPMake);
-        end;
-      // Cleanup units
-      DeleteDir(TempBuildDir);
+      try
+        // Compile options
+        //   -- default is to optimize, smartlink and strip to reduce
+        //      the executable size (there can be 100's of fpmake's on a system)
+        if llInfo in LogLevels then
+          AddOption('-vi');
+        AddOption('-O2');
+        AddOption('-XXs');
+        // Create fpmkunit.pp if needed
+        if NeedFPMKUnitSource then
+          begin
+            Log(llWarning,SLogUseInternalFpmkunit);
+            CreateFPMKUnitSource(TempBuildDir+PathDelim+'fpmkunit.pp');
+          end;
+        // Call compiler
+        If ExecuteProcess(PackageManager.FPMakeCompilerOptions.Compiler,OOptions+' '+FPmakeSrc)<>0 then
+          begin
+            if not PackageManager.Options.CommandLineSection.RecoveryMode then
+              Error(SErrCompileFailureFPMakeTryRecovery)
+            else
+              Error(SErrCompileFailureFPMake);
+          end;
+      finally
+        // Cleanup units
+        DeleteDir(TempBuildDir);
+      end;
     end
   else
     Log(llCommands,SLogNotCompilingFPMake);

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

@@ -38,6 +38,7 @@ type
     procedure TestPackageVariantPackage;
     procedure TestFPMakeCommandLikePackageVariants;
     procedure TestFpmakePluginDependencies;
+    procedure TestCleanupOfTemporaryBuildpath;
   end;
 
   { TFullFPCInstallationSetup }
@@ -338,6 +339,21 @@ begin
   RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'packageusingplugin', ['install'], 'Install package that depends on plugin');
 end;
 
+procedure TFullFPCInstallationTests.TestCleanupOfTemporaryBuildpath;
+var
+  SR: TSearchRec;
+begin
+  TFullFPCInstallationSetup.SyncPackageIntoCurrentTest('brokenpackage');
+  RunFppkgIndir(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'brokenpackage', ['build'], 'Attempt to build brokenpackage', 1);
+
+  if FindFirst(TFullFPCInstallationSetup.GetCurrentTestBasePackagesPath + 'brokenpackage'+PathDelim+AllFilesMask, faAnyFile, sr) = 0 then
+    begin
+      repeat
+      Check(not ((SR.Name<>'.') and (SR.Name<>'..') and (SR.Name<>'fpmake.pp') and (SR.Name<>'src')), 'Check for garbage-files after build ('+SR.Name+')');
+      until FindNext(SR) <> 0;
+    end;
+end;
+
 procedure TFullFPCInstallationTests.TestListPackages;
 var
   s: String;

+ 25 - 0
packages/fppkg/tests/packages/base/brokenpackage/fpmake.pp

@@ -0,0 +1,25 @@
+{$mode objfpc}{$H+}
+program fpmake;
+
+This will not compile.
+
+uses fpmkunit;
+
+Var
+  P : TPackage;
+  T : TTarget;
+begin
+  With Installer do
+    begin
+    P:=AddPackage('brokenpackage');
+    P.Version:='1.23.3';
+
+    P.Author := 'Joost van der Sluis';
+    P.License := 'GPL';
+    P.HomepageURL := 'www.freepascal.org';
+    P.Email := '';
+    P.Description := 'Package that does not work at all';
+ 
+    Run;
+    end;
+end.