소스 검색

ENH: use a cmake script to do the clean step, this allows for large numbers of files to be removed without making the command line too long

Bill Hoffman 19 년 전
부모
커밋
4c5ba06fa1

+ 32 - 0
Source/cmFileCommand.cxx

@@ -20,6 +20,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <cmsys/Directory.hxx>
 
 // cmLibraryCommand
 bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
@@ -54,6 +55,14 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
     {
     return this->HandleMakeDirectoryCommand(args);
     }
+  else if ( subCommand == "REMOVE" )
+    {
+    return this->HandleRemove(args, false);
+    }
+  else if ( subCommand == "REMOVE_RECURSE" )
+    {
+    return this->HandleRemove(args, true);
+    }
   else if ( subCommand == "INSTALL" )
     {
     return this->HandleInstallCommand(args);
@@ -857,3 +866,26 @@ bool cmFileCommand::HandleRelativePathCommand(
 }
 
 
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleRemove(std::vector<std::string> const& args, 
+                                 bool recurse)
+{
+
+  std::string message;
+  std::vector<std::string>::const_iterator i = args.begin();
+
+  i++; // Get rid of subcommand
+  for(;i != args.end(); ++i)
+    {
+    if(cmSystemTools::FileIsDirectory(i->c_str()) && recurse)
+      {
+      cmSystemTools::RemoveADirectory(i->c_str());
+      }
+    else
+      {
+      cmSystemTools::RemoveFile(i->c_str());
+      }
+    }
+  return true;
+}
+

+ 3 - 0
Source/cmFileCommand.h

@@ -69,6 +69,8 @@ public:
       "  FILE(READ filename variable)\n"
       "  FILE(GLOB variable [globbing expressions]...)\n"
       "  FILE(GLOB_RECURSE variable [globbing expressions]...)\n"
+      "  FILE(REMOVE [directory]...)\n"
+      "  FILE(REMOVE_RECURSE [directory]...)\n"
       "  FILE(MAKE_DIRECTORY [directory]...)\n"
       "  FILE(RELATIVE_PATH variable directory file)\n"
       "WRITE will write a message into a file called 'filename'. It "
@@ -101,6 +103,7 @@ public:
   cmTypeMacro(cmFileCommand, cmCommand);
 
 protected:
+  bool HandleRemove(std::vector<std::string> const& args, bool recurse);
   bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
   bool HandleReadCommand(std::vector<std::string> const& args);
   bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);

+ 24 - 4
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -813,17 +813,37 @@ cmLocalUnixMakefileGenerator3
 void
 cmLocalUnixMakefileGenerator3
 ::AppendCleanCommand(std::vector<std::string>& commands,
-                     const std::vector<std::string>& files)
+                     const std::vector<std::string>& files,
+                     cmTarget& target, const char* filename)
 {
   if(!files.empty())
     {
-    std::string remove = "$(CMAKE_COMMAND) -E remove -f";
+    std::string cleanfile = m_Makefile->GetCurrentOutputDirectory();
+    cleanfile += "/";
+    cleanfile += this->GetTargetDirectory(target);
+    cleanfile += "/cmake_clean";
+    if(filename)
+      {
+      cleanfile += "_";
+      cleanfile += filename;
+      }
+    cleanfile += ".cmake";
+    std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
+    std::ofstream fout(cleanfilePath.c_str());
+    if(!fout)
+      {
+      cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
+      }
+    fout << "FILE(REMOVE\n";
+    std::string remove = "$(CMAKE_COMMAND) -P ";
+    remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
     for(std::vector<std::string>::const_iterator f = files.begin();
         f != files.end(); ++f)
       {
-      remove += " ";
-      remove += this->Convert(f->c_str(),START_OUTPUT,SHELL);
+      fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED) 
+           << "\"\n";
       }
+    fout << ")\n";
     commands.push_back(remove);
     }
 }

+ 2 - 1
Source/cmLocalUnixMakefileGenerator3.h

@@ -272,7 +272,8 @@ protected:
   void AppendCustomCommand(std::vector<std::string>& commands,
                            const cmCustomCommand& cc);
   void AppendCleanCommand(std::vector<std::string>& commands,
-                          const std::vector<std::string>& files);
+                          const std::vector<std::string>& files,
+                          cmTarget& target, const char* filename =0);
 
 private:
   friend class cmMakefileTargetGenerator;

+ 7 - 4
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -225,18 +225,19 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   std::string cleanFullRealName = outpath + cleanRealName;
   exeCleanFiles.push_back(this->Convert(cleanFullName.c_str(),
                                         cmLocalGenerator::START_OUTPUT,
-                                        cmLocalGenerator::MAKEFILE));
+                                        cmLocalGenerator::UNCHANGED));
   if(cleanRealName != cleanName)
     {
     exeCleanFiles.push_back(this->Convert(cleanFullRealName.c_str(),
                                           cmLocalGenerator::START_OUTPUT,
-                                          cmLocalGenerator::MAKEFILE));
+                                          cmLocalGenerator::UNCHANGED));
     }
   } 
 
   // Add a command to remove any existing files for this executable.
   std::vector<std::string> commands1;
-  this->LocalGenerator->AppendCleanCommand(commands1, exeCleanFiles);
+  this->LocalGenerator->AppendCleanCommand(commands1, exeCleanFiles,
+                                           *this->Target, "target");
   this->LocalGenerator->CreateCDCommand(commands1,
                                         this->Makefile->GetStartOutputDirectory(),
                                         this->Makefile->GetHomeOutputDirectory()); 
@@ -352,6 +353,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   this->CleanFiles.insert(this->CleanFiles.end(),
                           exeCleanFiles.begin(),
                           exeCleanFiles.end());
-  this->CleanFiles.push_back(cleanObjs);
+  this->CleanFiles.insert(this->CleanFiles.end(),
+                          this->Objects.begin(),
+                          this->Objects.end());
 }
 

+ 11 - 8
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -283,19 +283,19 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
   std::string cleanFullImportName = outpath + cleanImportName;
   libCleanFiles.push_back
     (this->Convert(cleanFullStaticName.c_str(),cmLocalGenerator::START_OUTPUT,
-                   cmLocalGenerator::MAKEFILE));
+                   cmLocalGenerator::UNCHANGED));
   if(cleanSharedRealName != cleanStaticName)
     {
     libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
                                           cmLocalGenerator::START_OUTPUT,
-                                          cmLocalGenerator::MAKEFILE));
+                                          cmLocalGenerator::UNCHANGED));
     }
   if(cleanSharedSOName != cleanStaticName &&
      cleanSharedSOName != cleanSharedRealName)
     {
     libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
                                           cmLocalGenerator::START_OUTPUT,
-                                          cmLocalGenerator::MAKEFILE));
+                                          cmLocalGenerator::UNCHANGED));
     }
   if(cleanSharedName != cleanStaticName &&
      cleanSharedName != cleanSharedSOName &&
@@ -303,7 +303,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     {
     libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
                                           cmLocalGenerator::START_OUTPUT,
-                                          cmLocalGenerator::MAKEFILE));
+                                          cmLocalGenerator::UNCHANGED));
     }
   if(!cleanImportName.empty() &&
      cleanImportName != cleanStaticName &&
@@ -313,12 +313,13 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
     {
     libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
                                           cmLocalGenerator::START_OUTPUT,
-                                          cmLocalGenerator::MAKEFILE));
+                                          cmLocalGenerator::UNCHANGED));
     }
   }
   // Add a command to remove any existing files for this library.
   std::vector<std::string> commands1;
-  this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles);
+  this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
+                                           *this->Target, "target");
   this->LocalGenerator->CreateCDCommand(commands1,
                                         this->Makefile->GetStartOutputDirectory(),
                                         this->Makefile->GetHomeOutputDirectory());
@@ -487,7 +488,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
 
   // Clean all the possible library names and symlinks and object files.
   this->CleanFiles.insert(this->CleanFiles.end(),
-                          libCleanFiles.begin(),libCleanFiles.end());
-  this->CleanFiles.push_back(cleanObjs);
+                          libCleanFiles.begin(),libCleanFiles.end()); 
+  this->CleanFiles.insert(this->CleanFiles.end(),
+                          this->Objects.begin(),
+                          this->Objects.end());
 }
 

+ 3 - 2
Source/cmMakefileTargetGenerator.cxx

@@ -485,7 +485,8 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules()
   cleanTarget += "/clean";
   
   // Construct the clean command.
-  this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles);
+  this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
+                                           *this->Target);
   this->LocalGenerator->CreateCDCommand(commands,
                                         this->Makefile->GetStartOutputDirectory(),
                                         this->Makefile->GetHomeOutputDirectory());
@@ -605,7 +606,7 @@ void cmMakefileTargetGenerator::WriteCustomCommands()
         this->CleanFiles.push_back
           (this->Convert(cc->GetOutput(),
                          cmLocalGenerator::START_OUTPUT,
-                         cmLocalGenerator::SHELL));
+                         cmLocalGenerator::UNCHANGED));
         }
       }
     }