diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-02-02 20:53:28 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-08-17 18:42:53 (GMT) |
commit | 7b069510c5440f0193f1626be5000cf5efe90442 (patch) | |
tree | c7096e5c35d7cb8586579e67165a4c5b48061ae3 /Source | |
parent | 249cd3efad6967ec3195b7e24d031eecfc42eba7 (diff) | |
download | CMake-7b069510c5440f0193f1626be5000cf5efe90442.zip CMake-7b069510c5440f0193f1626be5000cf5efe90442.tar.gz CMake-7b069510c5440f0193f1626be5000cf5efe90442.tar.bz2 |
cmImportedCxxModuleInfo: introduce code to parse exported BMI properties
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmImportedCxxModuleInfo.cxx | 76 | ||||
-rw-r--r-- | Source/cmImportedCxxModuleInfo.h | 37 |
3 files changed, 115 insertions, 0 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 3690357..12af5d0 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -298,6 +298,8 @@ add_library( cmGraphAdjacencyList.h cmGraphVizWriter.cxx cmGraphVizWriter.h + cmImportedCxxModuleInfo.cxx + cmImportedCxxModuleInfo.h cmInstallGenerator.h cmInstallGenerator.cxx cmInstallGetRuntimeDependenciesGenerator.h diff --git a/Source/cmImportedCxxModuleInfo.cxx b/Source/cmImportedCxxModuleInfo.cxx new file mode 100644 index 0000000..9e3ac9a --- /dev/null +++ b/Source/cmImportedCxxModuleInfo.cxx @@ -0,0 +1,76 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#include "cmImportedCxxModuleInfo.h" + +#include <cstddef> +#include <memory> +#include <string> +#include <utility> +#include <vector> + +#include "cmCryptoHash.h" +#include "cmList.h" +#include "cmStringAlgorithms.h" +#include "cmSystemTools.h" + +bool ImportedCxxModuleLookup::Initialized() const +{ + return this->DoneInit; +} + +void ImportedCxxModuleLookup::Initialize(std::string const& importedModules) +{ + for (auto const& entry : cmList{ importedModules }) { + auto nameSep = entry.find('='); + if (nameSep == std::string::npos) { + // Invalid entry; ignore. + continue; + } + + auto name = entry.substr(0, nameSep); + + auto sourceSep = entry.find(',', nameSep); + std::string source; + if (sourceSep == std::string::npos) { + source = entry.substr(nameSep + 1); + } else { + source = entry.substr(nameSep + 1, sourceSep - nameSep - 1); + } + + std::vector<std::string> bmis; + if (sourceSep != std::string::npos) { + auto bmiPaths = entry.substr(sourceSep + 1); + bmis = cmSystemTools::SplitString(bmiPaths, ','); + } + + this->ImportedInfo.emplace(source, + ImportedCxxModuleInfo{ name, std::move(bmis) }); + } + + this->DoneInit = true; +} + +std::string ImportedCxxModuleLookup::BmiNameForSource(std::string const& path) +{ + auto genit = this->GeneratorInfo.find(path); + if (genit != this->GeneratorInfo.end()) { + return genit->second.BmiName; + } + + auto importit = this->ImportedInfo.find(path); + std::string bmiName; + auto hasher = cmCryptoHash::New("SHA3_512"); + constexpr size_t HASH_TRUNCATION = 12; + if (importit != this->ImportedInfo.end()) { + auto safename = hasher->HashString(importit->second.Name); + bmiName = cmStrCat(safename.substr(0, HASH_TRUNCATION), ".bmi"); + } else { + auto dirhash = hasher->HashString(path); + bmiName = cmStrCat(dirhash.substr(0, HASH_TRUNCATION), ".bmi"); + } + + this->GeneratorInfo.emplace( + path, ImportedCxxModuleGeneratorInfo{ &importit->second, bmiName }); + return bmiName; +} diff --git a/Source/cmImportedCxxModuleInfo.h b/Source/cmImportedCxxModuleInfo.h new file mode 100644 index 0000000..e052283 --- /dev/null +++ b/Source/cmImportedCxxModuleInfo.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <map> +#include <string> +#include <vector> + +struct ImportedCxxModuleInfo +{ + std::string const Name; + std::vector<std::string> const AvailableBmis; +}; + +struct ImportedCxxModuleGeneratorInfo +{ + ImportedCxxModuleInfo const* ImportedInfo; + std::string const BmiName; +}; + +struct ImportedCxxModuleLookup +{ + ImportedCxxModuleLookup() = default; + ~ImportedCxxModuleLookup() = default; + + bool Initialized() const; + void Initialize(std::string const& importedModules); + + std::string BmiNameForSource(std::string const& path); + +private: + bool DoneInit = false; + std::map<std::string, ImportedCxxModuleInfo> ImportedInfo; + std::map<std::string, ImportedCxxModuleGeneratorInfo> GeneratorInfo; +}; |