diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmFileAPI.cxx | 57 | ||||
-rw-r--r-- | Source/cmFileAPI.h | 5 | ||||
-rw-r--r-- | Source/cmFileAPICache.cxx | 105 | ||||
-rw-r--r-- | Source/cmFileAPICache.h | 15 |
5 files changed, 184 insertions, 0 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index e672eab..82fad1c 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -209,6 +209,8 @@ set(SRCS cmExtraSublimeTextGenerator.h cmFileAPI.cxx cmFileAPI.h + cmFileAPICache.cxx + cmFileAPICache.h cmFileAPICodemodel.cxx cmFileAPICodemodel.h cmFileLock.cxx diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index b63349a..ec26268 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -4,6 +4,7 @@ #include "cmAlgorithms.h" #include "cmCryptoHash.h" +#include "cmFileAPICache.h" #include "cmFileAPICodemodel.h" #include "cmGlobalGenerator.h" #include "cmSystemTools.h" @@ -236,6 +237,17 @@ bool cmFileAPI::ReadQuery(std::string const& query, objects.push_back(o); return true; } + if (kindName == ObjectKindName(ObjectKind::Cache)) { + Object o; + o.Kind = ObjectKind::Cache; + if (verStr == "v2") { + o.Version = 2; + } else { + return false; + } + objects.push_back(o); + return true; + } if (kindName == ObjectKindName(ObjectKind::InternalTest)) { Object o; o.Kind = ObjectKind::InternalTest; @@ -374,6 +386,7 @@ const char* cmFileAPI::ObjectKindName(ObjectKind kind) // Keep in sync with ObjectKind enum. static const char* objectKindNames[] = { "codemodel", // + "cache", // "__test" // }; return objectKindNames[size_t(kind)]; @@ -395,6 +408,9 @@ Json::Value cmFileAPI::BuildObject(Object const& object) case ObjectKind::CodeModel: value = this->BuildCodeModel(object); break; + case ObjectKind::Cache: + value = this->BuildCache(object); + break; case ObjectKind::InternalTest: value = this->BuildInternalTest(object); break; @@ -447,6 +463,8 @@ cmFileAPI::ClientRequest cmFileAPI::BuildClientRequest( if (kindName == this->ObjectKindName(ObjectKind::CodeModel)) { r.Kind = ObjectKind::CodeModel; + } else if (kindName == this->ObjectKindName(ObjectKind::Cache)) { + r.Kind = ObjectKind::Cache; } else if (kindName == this->ObjectKindName(ObjectKind::InternalTest)) { r.Kind = ObjectKind::InternalTest; } else { @@ -468,6 +486,9 @@ cmFileAPI::ClientRequest cmFileAPI::BuildClientRequest( case ObjectKind::CodeModel: this->BuildClientRequestCodeModel(r, versions); break; + case ObjectKind::Cache: + this->BuildClientRequestCache(r, versions); + break; case ObjectKind::InternalTest: this->BuildClientRequestInternalTest(r, versions); break; @@ -649,6 +670,42 @@ Json::Value cmFileAPI::BuildCodeModel(Object const& object) return codemodel; } +// The "cache" object kind. + +static unsigned int const CacheV2Minor = 0; + +void cmFileAPI::BuildClientRequestCache( + ClientRequest& r, std::vector<RequestVersion> const& versions) +{ + // Select a known version from those requested. + for (RequestVersion const& v : versions) { + if ((v.Major == 2 && v.Minor <= CacheV2Minor)) { + r.Version = v.Major; + break; + } + } + if (!r.Version) { + r.Error = NoSupportedVersion(versions); + } +} + +Json::Value cmFileAPI::BuildCache(Object const& object) +{ + using namespace std::placeholders; + Json::Value cache = cmFileAPICacheDump(*this, object.Version); + cache["kind"] = this->ObjectKindName(object.Kind); + + Json::Value& version = cache["version"] = Json::objectValue; + if (object.Version == 2) { + version["major"] = 2; + version["minor"] = CacheV2Minor; + } else { + return cache; // should be unreachable + } + + return cache; +} + // The "__test" object kind is for internal testing of CMake. static unsigned int const InternalTestV1Minor = 3; diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h index 5339ba7..20aa011 100644 --- a/Source/cmFileAPI.h +++ b/Source/cmFileAPI.h @@ -52,6 +52,7 @@ private: enum class ObjectKind { CodeModel, + Cache, InternalTest }; @@ -186,6 +187,10 @@ private: ClientRequest& r, std::vector<RequestVersion> const& versions); Json::Value BuildCodeModel(Object const& object); + void BuildClientRequestCache(ClientRequest& r, + std::vector<RequestVersion> const& versions); + Json::Value BuildCache(Object const& object); + void BuildClientRequestInternalTest( ClientRequest& r, std::vector<RequestVersion> const& versions); Json::Value BuildInternalTest(Object const& object); diff --git a/Source/cmFileAPICache.cxx b/Source/cmFileAPICache.cxx new file mode 100644 index 0000000..074994a --- /dev/null +++ b/Source/cmFileAPICache.cxx @@ -0,0 +1,105 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmFileAPICache.h" + +#include "cmFileAPI.h" +#include "cmState.h" +#include "cmake.h" + +#include "cm_jsoncpp_value.h" + +#include <algorithm> +#include <string> +#include <vector> + +namespace { + +class Cache +{ + cmFileAPI& FileAPI; + unsigned long Version; + cmState* State; + + Json::Value DumpEntries(); + Json::Value DumpEntry(std::string const& name); + Json::Value DumpEntryProperties(std::string const& name); + Json::Value DumpEntryProperty(std::string const& name, + std::string const& prop); + +public: + Cache(cmFileAPI& fileAPI, unsigned long version); + Json::Value Dump(); +}; + +Cache::Cache(cmFileAPI& fileAPI, unsigned long version) + : FileAPI(fileAPI) + , Version(version) + , State(this->FileAPI.GetCMakeInstance()->GetState()) +{ + static_cast<void>(this->Version); +} + +Json::Value Cache::Dump() +{ + Json::Value cache = Json::objectValue; + cache["entries"] = DumpEntries(); + return cache; +} + +Json::Value Cache::DumpEntries() +{ + Json::Value entries = Json::arrayValue; + + std::vector<std::string> names = this->State->GetCacheEntryKeys(); + std::sort(names.begin(), names.end()); + + for (std::string const& name : names) { + entries.append(this->DumpEntry(name)); + } + + return entries; +} + +Json::Value Cache::DumpEntry(std::string const& name) +{ + Json::Value entry = Json::objectValue; + entry["name"] = name; + entry["type"] = + cmState::CacheEntryTypeToString(this->State->GetCacheEntryType(name)); + entry["value"] = this->State->GetCacheEntryValue(name); + + Json::Value properties = this->DumpEntryProperties(name); + if (!properties.empty()) { + entry["properties"] = std::move(properties); + } + + return entry; +} + +Json::Value Cache::DumpEntryProperties(std::string const& name) +{ + Json::Value properties = Json::arrayValue; + std::vector<std::string> props = + this->State->GetCacheEntryPropertyList(name); + std::sort(props.begin(), props.end()); + for (std::string const& prop : props) { + properties.append(this->DumpEntryProperty(name, prop)); + } + return properties; +} + +Json::Value Cache::DumpEntryProperty(std::string const& name, + std::string const& prop) +{ + Json::Value property = Json::objectValue; + property["name"] = prop; + property["value"] = this->State->GetCacheEntryProperty(name, prop); + return property; +} +} + +Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, unsigned long version) +{ + Cache cache(fileAPI, version); + return cache.Dump(); +} diff --git a/Source/cmFileAPICache.h b/Source/cmFileAPICache.h new file mode 100644 index 0000000..09d9e1c --- /dev/null +++ b/Source/cmFileAPICache.h @@ -0,0 +1,15 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmFileAPICache_h +#define cmFileAPICache_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cm_jsoncpp_value.h" + +class cmFileAPI; + +extern Json::Value cmFileAPICacheDump(cmFileAPI& fileAPI, + unsigned long version); + +#endif |