1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmFileAPICache.h"
10 #include <cm3p/json/value.h>
12 #include "cmFileAPI.h"
22 unsigned long Version;
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);
32 Cache(cmFileAPI& fileAPI, unsigned long version);
36 Cache::Cache(cmFileAPI& fileAPI, unsigned long version)
39 , State(this->FileAPI.GetCMakeInstance()->GetState())
41 static_cast<void>(this->Version);
44 Json::Value Cache::Dump()
46 Json::Value cache = Json::objectValue;
47 cache["entries"] = this->DumpEntries();
51 Json::Value Cache::DumpEntries()
53 Json::Value entries = Json::arrayValue;
55 std::vector<std::string> names = this->State->GetCacheEntryKeys();
56 std::sort(names.begin(), names.end());
58 for (std::string const& name : names) {
59 entries.append(this->DumpEntry(name));
65 Json::Value Cache::DumpEntry(std::string const& name)
67 Json::Value entry = Json::objectValue;
70 cmState::CacheEntryTypeToString(this->State->GetCacheEntryType(name));
71 entry["value"] = this->State->GetSafeCacheEntryValue(name);
73 Json::Value properties = this->DumpEntryProperties(name);
74 if (!properties.empty()) {
75 entry["properties"] = std::move(properties);
81 Json::Value Cache::DumpEntryProperties(std::string const& name)
83 Json::Value properties = Json::arrayValue;
84 std::vector<std::string> props =
85 this->State->GetCacheEntryPropertyList(name);
86 std::sort(props.begin(), props.end());
87 for (std::string const& prop : props) {
88 properties.append(this->DumpEntryProperty(name, prop));
93 Json::Value Cache::DumpEntryProperty(std::string const& name,
94 std::string const& prop)
96 Json::Value property = Json::objectValue;
97 property["name"] = prop;
98 cmValue p = this->State->GetCacheEntryProperty(name, prop);
99 property["value"] = p ? *p : "";
104 Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned long version)
106 Cache cache(fileAPI, version);