1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
4 #include "cmImportedCxxModuleInfo.h"
11 #include "cmCryptoHash.h"
13 #include "cmStringAlgorithms.h"
14 #include "cmSystemTools.h"
16 bool ImportedCxxModuleLookup::Initialized() const
18 return this->DoneInit
;
21 void ImportedCxxModuleLookup::Initialize(std::string
const& importedModules
)
23 for (auto const& entry
: cmList
{ importedModules
}) {
24 auto nameSep
= entry
.find('=');
25 if (nameSep
== std::string::npos
) {
26 // Invalid entry; ignore.
30 auto name
= entry
.substr(0, nameSep
);
32 auto sourceSep
= entry
.find(',', nameSep
);
34 if (sourceSep
== std::string::npos
) {
35 source
= entry
.substr(nameSep
+ 1);
37 source
= entry
.substr(nameSep
+ 1, sourceSep
- nameSep
- 1);
40 std::vector
<std::string
> bmis
;
41 if (sourceSep
!= std::string::npos
) {
42 auto bmiPaths
= entry
.substr(sourceSep
+ 1);
43 bmis
= cmSystemTools::SplitString(bmiPaths
, ',');
46 this->ImportedInfo
.emplace(source
,
47 ImportedCxxModuleInfo
{ name
, std::move(bmis
) });
50 this->DoneInit
= true;
53 std::string
ImportedCxxModuleLookup::BmiNameForSource(std::string
const& path
)
55 auto genit
= this->GeneratorInfo
.find(path
);
56 if (genit
!= this->GeneratorInfo
.end()) {
57 return genit
->second
.BmiName
;
60 auto importit
= this->ImportedInfo
.find(path
);
62 cmCryptoHash
hasher(cmCryptoHash::AlgoSHA3_512
);
63 constexpr size_t HASH_TRUNCATION
= 12;
64 if (importit
!= this->ImportedInfo
.end()) {
65 auto safename
= hasher
.HashString(importit
->second
.Name
);
66 bmiName
= cmStrCat(safename
.substr(0, HASH_TRUNCATION
), ".bmi");
68 auto dirhash
= hasher
.HashString(path
);
69 bmiName
= cmStrCat(dirhash
.substr(0, HASH_TRUNCATION
), ".bmi");
72 this->GeneratorInfo
.emplace(path
, ImportedCxxModuleGeneratorInfo
{ bmiName
});