Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFileAPICache.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
#include "cmFileAPICache.h"
4
5
#include <algorithm>
6
#include <string>
7
#include <utility>
8
#include <vector>
9
10
#include <cm3p/json/value.h>
11
12
#include "cmFileAPI.h"
13
#include "cmState.h"
14
#include "cmValue.h"
15
#include "cmake.h"
16
17
namespace {
18
19
class Cache
20
{
21
  cmFileAPI& FileAPI;
22
  unsigned int Version;
23
  cmState* State;
24
25
  Json::Value DumpEntries();
26
  Json::Value DumpEntry(std::string const& name);
27
  Json::Value DumpEntryProperties(std::string const& name);
28
  Json::Value DumpEntryProperty(std::string const& name,
29
                                std::string const& prop);
30
31
public:
32
  Cache(cmFileAPI& fileAPI, unsigned int version);
33
  Json::Value Dump();
34
};
35
36
Cache::Cache(cmFileAPI& fileAPI, unsigned int version)
37
0
  : FileAPI(fileAPI)
38
0
  , Version(version)
39
0
  , State(this->FileAPI.GetCMakeInstance()->GetState())
40
0
{
41
0
  static_cast<void>(this->Version);
42
0
}
43
44
Json::Value Cache::Dump()
45
0
{
46
0
  Json::Value cache = Json::objectValue;
47
0
  cache["entries"] = this->DumpEntries();
48
0
  return cache;
49
0
}
50
51
Json::Value Cache::DumpEntries()
52
0
{
53
0
  Json::Value entries = Json::arrayValue;
54
55
0
  std::vector<std::string> names = this->State->GetCacheEntryKeys();
56
0
  std::sort(names.begin(), names.end());
57
58
0
  for (std::string const& name : names) {
59
0
    entries.append(this->DumpEntry(name));
60
0
  }
61
62
0
  return entries;
63
0
}
64
65
Json::Value Cache::DumpEntry(std::string const& name)
66
0
{
67
0
  Json::Value entry = Json::objectValue;
68
0
  entry["name"] = name;
69
0
  entry["type"] =
70
0
    cmState::CacheEntryTypeToString(this->State->GetCacheEntryType(name));
71
0
  entry["value"] = this->State->GetSafeCacheEntryValue(name);
72
73
0
  Json::Value properties = this->DumpEntryProperties(name);
74
0
  if (!properties.empty()) {
75
0
    entry["properties"] = std::move(properties);
76
0
  }
77
78
0
  return entry;
79
0
}
80
81
Json::Value Cache::DumpEntryProperties(std::string const& name)
82
0
{
83
0
  Json::Value properties = Json::arrayValue;
84
0
  std::vector<std::string> props =
85
0
    this->State->GetCacheEntryPropertyList(name);
86
0
  std::sort(props.begin(), props.end());
87
0
  for (std::string const& prop : props) {
88
0
    properties.append(this->DumpEntryProperty(name, prop));
89
0
  }
90
0
  return properties;
91
0
}
92
93
Json::Value Cache::DumpEntryProperty(std::string const& name,
94
                                     std::string const& prop)
95
0
{
96
0
  Json::Value property = Json::objectValue;
97
0
  property["name"] = prop;
98
0
  cmValue p = this->State->GetCacheEntryProperty(name, prop);
99
0
  property["value"] = p ? *p : "";
100
0
  return property;
101
0
}
102
}
103
104
Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned int version)
105
0
{
106
0
  Cache cache(fileAPI, version);
107
0
  return cache.Dump();
108
0
}