Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmImportedCxxModuleInfo.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
4
#include "cmImportedCxxModuleInfo.h"
5
6
#include <cstddef>
7
#include <string>
8
#include <utility>
9
#include <vector>
10
11
#include "cmCryptoHash.h"
12
#include "cmList.h"
13
#include "cmStringAlgorithms.h"
14
#include "cmSystemTools.h"
15
16
bool ImportedCxxModuleLookup::Initialized() const
17
0
{
18
0
  return this->DoneInit;
19
0
}
20
21
void ImportedCxxModuleLookup::Initialize(std::string const& importedModules)
22
0
{
23
0
  for (auto const& entry : cmList{ importedModules }) {
24
0
    auto nameSep = entry.find('=');
25
0
    if (nameSep == std::string::npos) {
26
      // Invalid entry; ignore.
27
0
      continue;
28
0
    }
29
30
0
    auto name = entry.substr(0, nameSep);
31
32
0
    auto sourceSep = entry.find(',', nameSep);
33
0
    std::string source;
34
0
    if (sourceSep == std::string::npos) {
35
0
      source = entry.substr(nameSep + 1);
36
0
    } else {
37
0
      source = entry.substr(nameSep + 1, sourceSep - nameSep - 1);
38
0
    }
39
40
0
    std::vector<std::string> bmis;
41
0
    if (sourceSep != std::string::npos) {
42
0
      auto bmiPaths = entry.substr(sourceSep + 1);
43
0
      bmis = cmSystemTools::SplitString(bmiPaths, ',');
44
0
    }
45
46
0
    this->ImportedInfo.emplace(source,
47
0
                               ImportedCxxModuleInfo{ name, std::move(bmis) });
48
0
  }
49
50
0
  this->DoneInit = true;
51
0
}
52
53
std::string ImportedCxxModuleLookup::BmiNameForSource(std::string const& path)
54
0
{
55
0
  auto genit = this->GeneratorInfo.find(path);
56
0
  if (genit != this->GeneratorInfo.end()) {
57
0
    return genit->second.BmiName;
58
0
  }
59
60
0
  auto importit = this->ImportedInfo.find(path);
61
0
  std::string bmiName;
62
0
  cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512);
63
0
  constexpr size_t HASH_TRUNCATION = 12;
64
0
  if (importit != this->ImportedInfo.end()) {
65
0
    auto safename = hasher.HashString(importit->second.Name);
66
0
    bmiName = cmStrCat(safename.substr(0, HASH_TRUNCATION), ".bmi");
67
0
  } else {
68
0
    auto dirhash = hasher.HashString(path);
69
0
    bmiName = cmStrCat(dirhash.substr(0, HASH_TRUNCATION), ".bmi");
70
0
  }
71
72
0
  this->GeneratorInfo.emplace(path, ImportedCxxModuleGeneratorInfo{ bmiName });
73
0
  return bmiName;
74
0
}