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
This commit is contained in:
parent
d253baab99
commit
4c5ba06fa1
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <cmsys/Directory.hxx>
|
||||||
|
|
||||||
// cmLibraryCommand
|
// cmLibraryCommand
|
||||||
bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
|
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);
|
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" )
|
else if ( subCommand == "INSTALL" )
|
||||||
{
|
{
|
||||||
return this->HandleInstallCommand(args);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
" FILE(READ filename variable)\n"
|
" FILE(READ filename variable)\n"
|
||||||
" FILE(GLOB variable [globbing expressions]...)\n"
|
" FILE(GLOB variable [globbing expressions]...)\n"
|
||||||
" FILE(GLOB_RECURSE 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(MAKE_DIRECTORY [directory]...)\n"
|
||||||
" FILE(RELATIVE_PATH variable directory file)\n"
|
" FILE(RELATIVE_PATH variable directory file)\n"
|
||||||
"WRITE will write a message into a file called 'filename'. It "
|
"WRITE will write a message into a file called 'filename'. It "
|
||||||
|
@ -101,6 +103,7 @@ public:
|
||||||
cmTypeMacro(cmFileCommand, cmCommand);
|
cmTypeMacro(cmFileCommand, cmCommand);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool HandleRemove(std::vector<std::string> const& args, bool recurse);
|
||||||
bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
|
bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
|
||||||
bool HandleReadCommand(std::vector<std::string> const& args);
|
bool HandleReadCommand(std::vector<std::string> const& args);
|
||||||
bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
|
bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
|
||||||
|
|
|
@ -813,17 +813,37 @@ cmLocalUnixMakefileGenerator3
|
||||||
void
|
void
|
||||||
cmLocalUnixMakefileGenerator3
|
cmLocalUnixMakefileGenerator3
|
||||||
::AppendCleanCommand(std::vector<std::string>& commands,
|
::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())
|
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();
|
for(std::vector<std::string>::const_iterator f = files.begin();
|
||||||
f != files.end(); ++f)
|
f != files.end(); ++f)
|
||||||
{
|
{
|
||||||
remove += " ";
|
fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED)
|
||||||
remove += this->Convert(f->c_str(),START_OUTPUT,SHELL);
|
<< "\"\n";
|
||||||
}
|
}
|
||||||
|
fout << ")\n";
|
||||||
commands.push_back(remove);
|
commands.push_back(remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,8 @@ protected:
|
||||||
void AppendCustomCommand(std::vector<std::string>& commands,
|
void AppendCustomCommand(std::vector<std::string>& commands,
|
||||||
const cmCustomCommand& cc);
|
const cmCustomCommand& cc);
|
||||||
void AppendCleanCommand(std::vector<std::string>& commands,
|
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:
|
private:
|
||||||
friend class cmMakefileTargetGenerator;
|
friend class cmMakefileTargetGenerator;
|
||||||
|
|
|
@ -225,18 +225,19 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
||||||
std::string cleanFullRealName = outpath + cleanRealName;
|
std::string cleanFullRealName = outpath + cleanRealName;
|
||||||
exeCleanFiles.push_back(this->Convert(cleanFullName.c_str(),
|
exeCleanFiles.push_back(this->Convert(cleanFullName.c_str(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
if(cleanRealName != cleanName)
|
if(cleanRealName != cleanName)
|
||||||
{
|
{
|
||||||
exeCleanFiles.push_back(this->Convert(cleanFullRealName.c_str(),
|
exeCleanFiles.push_back(this->Convert(cleanFullRealName.c_str(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a command to remove any existing files for this executable.
|
// Add a command to remove any existing files for this executable.
|
||||||
std::vector<std::string> commands1;
|
std::vector<std::string> commands1;
|
||||||
this->LocalGenerator->AppendCleanCommand(commands1, exeCleanFiles);
|
this->LocalGenerator->AppendCleanCommand(commands1, exeCleanFiles,
|
||||||
|
*this->Target, "target");
|
||||||
this->LocalGenerator->CreateCDCommand(commands1,
|
this->LocalGenerator->CreateCDCommand(commands1,
|
||||||
this->Makefile->GetStartOutputDirectory(),
|
this->Makefile->GetStartOutputDirectory(),
|
||||||
this->Makefile->GetHomeOutputDirectory());
|
this->Makefile->GetHomeOutputDirectory());
|
||||||
|
@ -352,6 +353,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
||||||
this->CleanFiles.insert(this->CleanFiles.end(),
|
this->CleanFiles.insert(this->CleanFiles.end(),
|
||||||
exeCleanFiles.begin(),
|
exeCleanFiles.begin(),
|
||||||
exeCleanFiles.end());
|
exeCleanFiles.end());
|
||||||
this->CleanFiles.push_back(cleanObjs);
|
this->CleanFiles.insert(this->CleanFiles.end(),
|
||||||
|
this->Objects.begin(),
|
||||||
|
this->Objects.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,19 +283,19 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
||||||
std::string cleanFullImportName = outpath + cleanImportName;
|
std::string cleanFullImportName = outpath + cleanImportName;
|
||||||
libCleanFiles.push_back
|
libCleanFiles.push_back
|
||||||
(this->Convert(cleanFullStaticName.c_str(),cmLocalGenerator::START_OUTPUT,
|
(this->Convert(cleanFullStaticName.c_str(),cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
if(cleanSharedRealName != cleanStaticName)
|
if(cleanSharedRealName != cleanStaticName)
|
||||||
{
|
{
|
||||||
libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
|
libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
}
|
}
|
||||||
if(cleanSharedSOName != cleanStaticName &&
|
if(cleanSharedSOName != cleanStaticName &&
|
||||||
cleanSharedSOName != cleanSharedRealName)
|
cleanSharedSOName != cleanSharedRealName)
|
||||||
{
|
{
|
||||||
libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
|
libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
}
|
}
|
||||||
if(cleanSharedName != cleanStaticName &&
|
if(cleanSharedName != cleanStaticName &&
|
||||||
cleanSharedName != cleanSharedSOName &&
|
cleanSharedName != cleanSharedSOName &&
|
||||||
|
@ -303,7 +303,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
||||||
{
|
{
|
||||||
libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
|
libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
}
|
}
|
||||||
if(!cleanImportName.empty() &&
|
if(!cleanImportName.empty() &&
|
||||||
cleanImportName != cleanStaticName &&
|
cleanImportName != cleanStaticName &&
|
||||||
|
@ -313,12 +313,13 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
||||||
{
|
{
|
||||||
libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
|
libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::MAKEFILE));
|
cmLocalGenerator::UNCHANGED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add a command to remove any existing files for this library.
|
// Add a command to remove any existing files for this library.
|
||||||
std::vector<std::string> commands1;
|
std::vector<std::string> commands1;
|
||||||
this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles);
|
this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
|
||||||
|
*this->Target, "target");
|
||||||
this->LocalGenerator->CreateCDCommand(commands1,
|
this->LocalGenerator->CreateCDCommand(commands1,
|
||||||
this->Makefile->GetStartOutputDirectory(),
|
this->Makefile->GetStartOutputDirectory(),
|
||||||
this->Makefile->GetHomeOutputDirectory());
|
this->Makefile->GetHomeOutputDirectory());
|
||||||
|
@ -487,7 +488,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
||||||
|
|
||||||
// Clean all the possible library names and symlinks and object files.
|
// Clean all the possible library names and symlinks and object files.
|
||||||
this->CleanFiles.insert(this->CleanFiles.end(),
|
this->CleanFiles.insert(this->CleanFiles.end(),
|
||||||
libCleanFiles.begin(),libCleanFiles.end());
|
libCleanFiles.begin(),libCleanFiles.end());
|
||||||
this->CleanFiles.push_back(cleanObjs);
|
this->CleanFiles.insert(this->CleanFiles.end(),
|
||||||
|
this->Objects.begin(),
|
||||||
|
this->Objects.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -485,7 +485,8 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules()
|
||||||
cleanTarget += "/clean";
|
cleanTarget += "/clean";
|
||||||
|
|
||||||
// Construct the clean command.
|
// Construct the clean command.
|
||||||
this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles);
|
this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
|
||||||
|
*this->Target);
|
||||||
this->LocalGenerator->CreateCDCommand(commands,
|
this->LocalGenerator->CreateCDCommand(commands,
|
||||||
this->Makefile->GetStartOutputDirectory(),
|
this->Makefile->GetStartOutputDirectory(),
|
||||||
this->Makefile->GetHomeOutputDirectory());
|
this->Makefile->GetHomeOutputDirectory());
|
||||||
|
@ -605,7 +606,7 @@ void cmMakefileTargetGenerator::WriteCustomCommands()
|
||||||
this->CleanFiles.push_back
|
this->CleanFiles.push_back
|
||||||
(this->Convert(cc->GetOutput(),
|
(this->Convert(cc->GetOutput(),
|
||||||
cmLocalGenerator::START_OUTPUT,
|
cmLocalGenerator::START_OUTPUT,
|
||||||
cmLocalGenerator::SHELL));
|
cmLocalGenerator::UNCHANGED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue