From 7c8c18b1e61ca717941214c2365ce5c5056bad14 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 13 May 2019 12:54:45 +0200 Subject: Makefiles: Sort clean files by using a std::set container By using a `std::set` container instead of a `std::vector` container, the clean files list becomes sorted and unique. The clean target in Makefiles beomes nicer and better readable this way. Also double clean entries won't appear anymore. --- Source/cmLocalUnixMakefileGenerator3.cxx | 2 +- Source/cmLocalUnixMakefileGenerator3.h | 2 +- Source/cmMakefileExecutableTargetGenerator.cxx | 9 ++++----- Source/cmMakefileLibraryTargetGenerator.cxx | 27 +++++++++++++------------- Source/cmMakefileTargetGenerator.cxx | 17 ++++++++-------- Source/cmMakefileTargetGenerator.h | 2 +- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index bece12e..88966c8 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1040,7 +1040,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( } void cmLocalUnixMakefileGenerator3::AppendCleanCommand( - std::vector& commands, const std::vector& files, + std::vector& commands, const std::set& files, cmGeneratorTarget* target, const char* filename) { std::string currentBinDir = this->GetCurrentBinaryDirectory(); diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 7a0ea98..fed25e1 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -224,7 +224,7 @@ protected: bool echo_comment = false, std::ostream* content = nullptr); void AppendCleanCommand(std::vector& commands, - const std::vector& files, + const std::set& files, cmGeneratorTarget* target, const char* filename = nullptr); diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index ebf5fc2..beabf91 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -4,6 +4,7 @@ #include #include // IWYU pragma: keep +#include #include #include #include @@ -291,8 +292,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( this->WriteTargetDriverRule(targetOutputReal, relink); // Clean all the possible executable names and symlinks. - this->CleanFiles.insert(this->CleanFiles.end(), exeCleanFiles.begin(), - exeCleanFiles.end()); + this->CleanFiles.insert(exeCleanFiles.begin(), exeCleanFiles.end()); #else static_cast(relink); #endif @@ -480,7 +480,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // List the PDB for cleaning only when the whole target is // cleaned. We do not want to delete the .pdb file just before // linking the target. - this->CleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + this->CleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathPDB)); // Add the pre-build and pre-link rules building but not when relinking. @@ -695,6 +695,5 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) this->WriteTargetDriverRule(targetFullPath, relink); // Clean all the possible executable names and symlinks. - this->CleanFiles.insert(this->CleanFiles.end(), exeCleanFiles.begin(), - exeCleanFiles.end()); + this->CleanFiles.insert(exeCleanFiles.begin(), exeCleanFiles.end()); } diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 0393e22..f5d1fc9 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -4,6 +4,7 @@ #include #include // IWYU pragma: keep +#include #include #include #include @@ -304,8 +305,8 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress); } // Clean files associated with this library. - std::vector libCleanFiles; - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + std::set libCleanFiles; + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetOutputReal)); // Determine whether a link script will be used. @@ -412,8 +413,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( this->LocalGenerator->SetLinkScriptShell(false); // Clean all the possible library names and symlinks. - this->CleanFiles.insert(this->CleanFiles.end(), libCleanFiles.begin(), - libCleanFiles.end()); + this->CleanFiles.insert(libCleanFiles.begin(), libCleanFiles.end()); } std::vector commands1; @@ -593,8 +593,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } // Clean files associated with this library. - std::vector libCleanFiles; - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + std::set libCleanFiles; + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal)); std::vector commands1; @@ -611,22 +611,22 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } if (this->TargetNames.Output != this->TargetNames.Real) { - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath)); } if (this->TargetNames.SharedObject != this->TargetNames.Real && this->TargetNames.SharedObject != this->TargetNames.Output) { - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathSO)); } if (!this->TargetNames.ImportLibrary.empty()) { - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathImport)); std::string implib; if (this->GeneratorTarget->GetImplibGNUtoMS( this->ConfigName, targetFullPathImport, implib)) { - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), implib)); } } @@ -634,14 +634,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // List the PDB for cleaning only when the whole target is // cleaned. We do not want to delete the .pdb file just before // linking the target. - this->CleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + this->CleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathPDB)); #ifdef _WIN32 // There may be a manifest file for this target. Add it to the // clean set just in case. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) { - libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath( + libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath + ".manifest")); } @@ -992,6 +992,5 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( this->WriteTargetDriverRule(targetFullPath, relink); // Clean all the possible library names and symlinks. - this->CleanFiles.insert(this->CleanFiles.end(), libCleanFiles.begin(), - libCleanFiles.end()); + this->CleanFiles.insert(libCleanFiles.begin(), libCleanFiles.end()); } diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 340e405..2ea6682 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -158,10 +158,12 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() std::unique_ptr cge = ge.Parse(additional_clean_files); + std::vector additionalFiles; cmSystemTools::ExpandListArgument( cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget, nullptr, nullptr), - this->CleanFiles); + additionalFiles); + this->CleanFiles.insert(additionalFiles.begin(), additionalFiles.end()); } // add custom commands to the clean rules? @@ -181,13 +183,13 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() if (clean) { const std::vector& outputs = ccg.GetOutputs(); for (std::string const& output : outputs) { - this->CleanFiles.push_back( + this->CleanFiles.insert( this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, output)); } const std::vector& byproducts = ccg.GetByproducts(); for (std::string const& byproduct : byproducts) { - this->CleanFiles.push_back( + this->CleanFiles.insert( this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, byproduct)); } @@ -211,7 +213,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() for (const auto& be : buildEventCommands) { const std::vector& byproducts = be.GetByproducts(); for (std::string const& byproduct : byproducts) { - this->CleanFiles.push_back( + this->CleanFiles.insert( this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, byproduct)); } @@ -350,7 +352,7 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()( std::string output = macdir; output += "/"; output += cmSystemTools::GetFilenameName(input); - this->Generator->CleanFiles.push_back( + this->Generator->CleanFiles.insert( this->Generator->LocalGenerator->MaybeConvertToRelativePath( this->Generator->LocalGenerator->GetCurrentBinaryDirectory(), output)); output = this->Generator->LocalGenerator->MaybeConvertToRelativePath( @@ -415,7 +417,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // Save this in the target's list of object files. this->Objects.push_back(obj); - this->CleanFiles.push_back(obj); + this->CleanFiles.insert(obj); // TODO: Remove // std::string relativeObj @@ -804,8 +806,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( if (const char* extra_outputs_str = source.GetProperty("OBJECT_OUTPUTS")) { // Register these as extra files to clean. cmSystemTools::ExpandListArgument(extra_outputs_str, outputs); - this->CleanFiles.insert(this->CleanFiles.end(), outputs.begin() + 1, - outputs.end()); + this->CleanFiles.insert(outputs.begin() + 1, outputs.end()); } // Write the rule. diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index ec58d17..c570a7c 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -210,7 +210,7 @@ protected: cmGeneratedFileStream* InfoFileStream; // files to clean - std::vector CleanFiles; + std::set CleanFiles; // objects used by this target std::vector Objects; -- cgit v0.12