diff options
author | Brad King <brad.king@kitware.com> | 2024-01-19 15:54:04 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-01-19 15:54:20 (GMT) |
commit | 0102b25cf898598b28e715054fb58aefdf369f97 (patch) | |
tree | 7771d2d5a2092ee8b94e0b7c6ac139085384654b /Source | |
parent | d07aee97fe16dbac7055fc6d683fc543939c9f71 (diff) | |
parent | 4cd153afe324afb228c9123ace15c5bffcd4fbdf (diff) | |
download | CMake-0102b25cf898598b28e715054fb58aefdf369f97.zip CMake-0102b25cf898598b28e715054fb58aefdf369f97.tar.gz CMake-0102b25cf898598b28e715054fb58aefdf369f97.tar.bz2 |
Merge topic 'cxxmodules-export-file-collisions'
4cd153afe3 Merge branch 'backport-cxxmodules-export-file-collisions'
d791f3a180 cxxmodules: make export trampoline script files unique
2352dcc830 Source: Simplify hasher object construction
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9166
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmExportBuildFileGenerator.cxx | 31 | ||||
-rw-r--r-- | Source/cmExportBuildFileGenerator.h | 6 | ||||
-rw-r--r-- | Source/cmExportFileGenerator.cxx | 9 | ||||
-rw-r--r-- | Source/cmExportFileGenerator.h | 5 | ||||
-rw-r--r-- | Source/cmExportInstallFileGenerator.cxx | 15 | ||||
-rw-r--r-- | Source/cmExportInstallFileGenerator.h | 6 | ||||
-rw-r--r-- | Source/cmExportTryCompileFileGenerator.h | 5 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 6 | ||||
-rw-r--r-- | Source/cmImportedCxxModuleInfo.cxx | 7 | ||||
-rw-r--r-- | Source/cmInstallExportGenerator.cxx | 5 |
10 files changed, 61 insertions, 34 deletions
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 8ba8d97..81e3d54 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -3,6 +3,7 @@ #include "cmExportBuildFileGenerator.h" #include <algorithm> +#include <cstddef> #include <map> #include <memory> #include <set> @@ -12,6 +13,7 @@ #include <cm/string_view> #include <cmext/string_view> +#include "cmCryptoHash.h" #include "cmExportSet.h" #include "cmFileSet.h" #include "cmGeneratedFileStream.h" @@ -156,7 +158,19 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) this->GenerateTargetFileSets(gte, os); } - this->GenerateCxxModuleInformation(os); + std::string cxx_modules_name; + if (this->ExportSet) { + cxx_modules_name = this->ExportSet->GetName(); + } else { + cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512); + constexpr std::size_t HASH_TRUNCATION = 12; + for (auto const& target : this->Targets) { + hasher.Append(target.Name); + } + cxx_modules_name = hasher.FinalizeHex().substr(0, HASH_TRUNCATION); + } + + this->GenerateCxxModuleInformation(cxx_modules_name, os); // Generate import file content for each configuration. for (std::string const& c : this->Configurations) { @@ -165,7 +179,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) // Generate import file content for each configuration. for (std::string const& c : this->Configurations) { - this->GenerateImportCxxModuleConfigTargetInclusion(c); + this->GenerateImportCxxModuleConfigTargetInclusion(cxx_modules_name, c); } this->GenerateMissingTargetsCheckCode(os); @@ -526,7 +540,7 @@ std::string cmExportBuildFileGenerator::GetCxxModulesDirectory() const } void cmExportBuildFileGenerator::GenerateCxxModuleConfigInformation( - std::ostream& os) const + std::string const& name, std::ostream& os) const { const char* opt = ""; if (this->Configurations.size() > 1) { @@ -539,13 +553,13 @@ void cmExportBuildFileGenerator::GenerateCxxModuleConfigInformation( if (c.empty()) { c = "noconfig"; } - os << "include(\"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-" << c << ".cmake\"" - << opt << ")\n"; + os << "include(\"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-" << name << '-' + << c << ".cmake\"" << opt << ")\n"; } } bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion( - std::string config) const + std::string const& name, std::string config) const { auto cxx_modules_dirname = this->GetCxxModulesDirectory(); if (cxx_modules_dirname.empty()) { @@ -556,8 +570,9 @@ bool cmExportBuildFileGenerator::GenerateImportCxxModuleConfigTargetInclusion( config = "noconfig"; } - std::string fileName = cmStrCat(this->FileDir, '/', cxx_modules_dirname, - "/cxx-modules-", config, ".cmake"); + std::string fileName = + cmStrCat(this->FileDir, '/', cxx_modules_dirname, "/cxx-modules-", name, + '-', config, ".cmake"); cmGeneratedFileStream os(fileName, true); if (!os) { diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 9f11d13..ee4779f 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -105,8 +105,10 @@ protected: cmExportSet* GetExportSet() const override { return this->ExportSet; } std::string GetCxxModulesDirectory() const override; - void GenerateCxxModuleConfigInformation(std::ostream&) const override; - bool GenerateImportCxxModuleConfigTargetInclusion(std::string) const; + void GenerateCxxModuleConfigInformation(std::string const&, + std::ostream&) const override; + bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&, + std::string) const; std::pair<std::vector<std::string>, std::string> FindBuildExportInfo( cmGlobalGenerator* gg, const std::string& name); diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index e2c3edd..f332007 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -1587,7 +1587,8 @@ void cmExportFileGenerator::GenerateTargetFileSets(cmGeneratorTarget* gte, } } -void cmExportFileGenerator::GenerateCxxModuleInformation(std::ostream& os) +void cmExportFileGenerator::GenerateCxxModuleInformation( + std::string const& name, std::ostream& os) { auto const cxx_module_dirname = this->GetCxxModulesDirectory(); if (cxx_module_dirname.empty()) { @@ -1597,19 +1598,19 @@ void cmExportFileGenerator::GenerateCxxModuleInformation(std::ostream& os) // Write the include. os << "# Include C++ module properties\n" << "include(\"${CMAKE_CURRENT_LIST_DIR}/" << cxx_module_dirname - << "/cxx-modules.cmake\")\n\n"; + << "/cxx-modules-" << name << ".cmake\")\n\n"; // Get the path to the file we're going to write. std::string path = this->MainImportFile; path = cmSystemTools::GetFilenamePath(path); auto trampoline_path = - cmStrCat(path, '/', cxx_module_dirname, "/cxx-modules.cmake"); + cmStrCat(path, '/', cxx_module_dirname, "/cxx-modules-", name, ".cmake"); // Include all configuration-specific include files. cmGeneratedFileStream ap(trampoline_path, true); ap.SetCopyIfDifferent(true); - this->GenerateCxxModuleConfigInformation(ap); + this->GenerateCxxModuleConfigInformation(name, ap); } void cmExportFileGenerator::SetRequiredCMakeVersion(unsigned int major, diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 554dd4a..f619576 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -192,7 +192,7 @@ protected: void GenerateTargetFileSets(cmGeneratorTarget* gte, std::ostream& os, cmTargetExport* te = nullptr); - void GenerateCxxModuleInformation(std::ostream& os); + void GenerateCxxModuleInformation(std::string const& name, std::ostream& os); virtual std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet, @@ -253,5 +253,6 @@ private: const std::string& config) = 0; virtual std::string GetCxxModulesDirectory() const = 0; - virtual void GenerateCxxModuleConfigInformation(std::ostream& os) const = 0; + virtual void GenerateCxxModuleConfigInformation(std::string const&, + std::ostream& os) const = 0; }; diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 64e694c..c5b9dc9 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -170,10 +170,12 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) bool result = true; - this->GenerateCxxModuleInformation(os); + std::string cxx_modules_name = this->IEGen->GetExportSet()->GetName(); + this->GenerateCxxModuleInformation(cxx_modules_name, os); if (requiresConfigFiles) { for (std::string const& c : this->Configurations) { - if (!this->GenerateImportCxxModuleConfigTargetInclusion(c)) { + if (!this->GenerateImportCxxModuleConfigTargetInclusion(cxx_modules_name, + c)) { result = false; } } @@ -724,12 +726,12 @@ std::string cmExportInstallFileGenerator::GetCxxModulesDirectory() const } void cmExportInstallFileGenerator::GenerateCxxModuleConfigInformation( - std::ostream& os) const + std::string const& name, std::ostream& os) const { // Now load per-configuration properties for them. /* clang-format off */ os << "# Load information for each installed configuration.\n" - "file(GLOB _cmake_cxx_module_includes \"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-*.cmake\")\n" + "file(GLOB _cmake_cxx_module_includes \"${CMAKE_CURRENT_LIST_DIR}/cxx-modules-" << name << "-*.cmake\")\n" "foreach(_cmake_cxx_module_include IN LISTS _cmake_cxx_module_includes)\n" " include(\"${_cmake_cxx_module_include}\")\n" "endforeach()\n" @@ -739,7 +741,8 @@ void cmExportInstallFileGenerator::GenerateCxxModuleConfigInformation( } bool cmExportInstallFileGenerator:: - GenerateImportCxxModuleConfigTargetInclusion(std::string const& config) + GenerateImportCxxModuleConfigTargetInclusion(std::string const& name, + std::string const& config) { auto cxx_modules_dirname = this->GetCxxModulesDirectory(); if (cxx_modules_dirname.empty()) { @@ -754,7 +757,7 @@ bool cmExportInstallFileGenerator:: std::string const dest = cmStrCat(this->FileDir, '/', cxx_modules_dirname, '/'); std::string fileName = - cmStrCat(dest, "cxx-modules-", filename_config, ".cmake"); + cmStrCat(dest, "cxx-modules-", name, '-', filename_config, ".cmake"); cmGeneratedFileStream os(fileName, true); if (!os) { diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 9de0c8e..7a72584 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -119,8 +119,10 @@ protected: cmTargetExport* te) override; std::string GetCxxModulesDirectory() const override; - void GenerateCxxModuleConfigInformation(std::ostream&) const override; - bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&); + void GenerateCxxModuleConfigInformation(std::string const&, + std::ostream&) const override; + bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&, + std::string const&); cmExportSet* GetExportSet() const override { diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index 5c34fad..4c7d287 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -56,7 +56,10 @@ protected: cmTargetExport* te) override; std::string GetCxxModulesDirectory() const override { return {}; } - void GenerateCxxModuleConfigInformation(std::ostream&) const override {} + void GenerateCxxModuleConfigInformation(std::string const&, + std::ostream&) const override + { + } private: std::string FindTargets(const std::string& prop, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 11253db..5b600cb 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -8417,14 +8417,14 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache, } if (gt->HaveCxx20ModuleSources()) { - auto hasher = cmCryptoHash::New("SHA3_512"); + cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512); constexpr size_t HASH_TRUNCATION = 12; - auto dirhash = hasher->HashString( + auto dirhash = hasher.HashString( gt->GetLocalGenerator()->GetCurrentBinaryDirectory()); std::string safeName = gt->GetName(); cmSystemTools::ReplaceString(safeName, ":", "_"); auto targetIdent = - hasher->HashString(cmStrCat("@d_", dirhash, "@u_", usage.GetHash())); + hasher.HashString(cmStrCat("@d_", dirhash, "@u_", usage.GetHash())); std::string targetName = cmStrCat(safeName, "@synth_", targetIdent.substr(0, HASH_TRUNCATION)); diff --git a/Source/cmImportedCxxModuleInfo.cxx b/Source/cmImportedCxxModuleInfo.cxx index 9e3ac9a..c54b265 100644 --- a/Source/cmImportedCxxModuleInfo.cxx +++ b/Source/cmImportedCxxModuleInfo.cxx @@ -4,7 +4,6 @@ #include "cmImportedCxxModuleInfo.h" #include <cstddef> -#include <memory> #include <string> #include <utility> #include <vector> @@ -60,13 +59,13 @@ std::string ImportedCxxModuleLookup::BmiNameForSource(std::string const& path) auto importit = this->ImportedInfo.find(path); std::string bmiName; - auto hasher = cmCryptoHash::New("SHA3_512"); + cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512); constexpr size_t HASH_TRUNCATION = 12; if (importit != this->ImportedInfo.end()) { - auto safename = hasher->HashString(importit->second.Name); + auto safename = hasher.HashString(importit->second.Name); bmiName = cmStrCat(safename.substr(0, HASH_TRUNCATION), ".bmi"); } else { - auto dirhash = hasher->HashString(path); + auto dirhash = hasher.HashString(path); bmiName = cmStrCat(dirhash.substr(0, HASH_TRUNCATION), ".bmi"); } diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index 72f0ac7..2f3da3e 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -160,10 +160,11 @@ void cmInstallExportGenerator::GenerateScriptConfigs(std::ostream& os, // Remove old per-configuration export files if the main changes. std::string installedDir = cmStrCat( "$ENV{DESTDIR}", ConvertToAbsoluteDestination(cxx_module_dest), '/'); - std::string installedFile = cmStrCat(installedDir, "/cxx-modules.cmake"); + std::string installedFile = cmStrCat(installedDir, "/cxx-modules-", + this->ExportSet->GetName(), ".cmake"); std::string toInstallFile = cmStrCat(cmSystemTools::GetFilenamePath(config_file_example), - "/cxx-modules.cmake"); + "/cxx-modules-", this->ExportSet->GetName(), ".cmake"); os << indent << "if(EXISTS \"" << installedFile << "\")\n"; Indent indentN = indent.Next(); Indent indentNN = indentN.Next(); |