diff options
author | Brad King <brad.king@kitware.com> | 2022-12-12 22:59:41 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-12-17 13:52:04 (GMT) |
commit | d811d86fd7f9644876e9d3605937edffa5c8a9d8 (patch) | |
tree | 7359c796a0ec5bf273eedd924a2753980176cc8d /Source/cmFileAPI.cxx | |
parent | 02599da236fd22db0dcfb6503194e5bad086aea9 (diff) | |
download | CMake-d811d86fd7f9644876e9d3605937edffa5c8a9d8.zip CMake-d811d86fd7f9644876e9d3605937edffa5c8a9d8.tar.gz CMake-d811d86fd7f9644876e9d3605937edffa5c8a9d8.tar.bz2 |
FileAPI: Add "configureLog" object kind
Provide clients with a way to get a known set of configure log event
versions.
Issue: #23200
Diffstat (limited to 'Source/cmFileAPI.cxx')
-rw-r--r-- | Source/cmFileAPI.cxx | 94 |
1 files changed, 89 insertions, 5 deletions
diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index 3fc2179..d1d3d25 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -18,6 +18,7 @@ #include "cmFileAPICMakeFiles.h" #include "cmFileAPICache.h" #include "cmFileAPICodemodel.h" +#include "cmFileAPIConfigureLog.h" #include "cmFileAPIToolchains.h" #include "cmGlobalGenerator.h" #include "cmStringAlgorithms.h" @@ -66,6 +67,26 @@ void cmFileAPI::ReadQueries() } } +std::vector<unsigned long> cmFileAPI::GetConfigureLogVersions() +{ + std::vector<unsigned long> versions; + auto getConfigureLogVersions = [&versions](Query const& q) { + for (Object const& o : q.Known) { + if (o.Kind == ObjectKind::ConfigureLog) { + versions.emplace_back(o.Version); + } + } + }; + getConfigureLogVersions(this->TopQuery); + for (auto const& client : this->ClientQueries) { + getConfigureLogVersions(client.second.DirQuery); + } + std::sort(versions.begin(), versions.end()); + versions.erase(std::unique(versions.begin(), versions.end()), + versions.end()); + return versions; +} + void cmFileAPI::WriteReplies() { if (this->QueryExists) { @@ -241,6 +262,17 @@ bool cmFileAPI::ReadQuery(std::string const& query, objects.push_back(o); return true; } + if (kindName == ObjectKindName(ObjectKind::ConfigureLog)) { + Object o; + o.Kind = ObjectKind::ConfigureLog; + if (verStr == "v1") { + o.Version = 1; + } else { + return false; + } + objects.push_back(o); + return true; + } if (kindName == ObjectKindName(ObjectKind::Cache)) { Object o; o.Kind = ObjectKind::Cache; @@ -411,11 +443,12 @@ const char* cmFileAPI::ObjectKindName(ObjectKind kind) { // Keep in sync with ObjectKind enum. static const char* objectKindNames[] = { - "codemodel", // - "cache", // - "cmakeFiles", // - "toolchains", // - "__test" // + "codemodel", // + "configureLog", // + "cache", // + "cmakeFiles", // + "toolchains", // + "__test" // }; return objectKindNames[static_cast<size_t>(kind)]; } @@ -442,6 +475,9 @@ Json::Value cmFileAPI::BuildObject(Object const& object) case ObjectKind::CodeModel: value = this->BuildCodeModel(object); break; + case ObjectKind::ConfigureLog: + value = this->BuildConfigureLog(object); + break; case ObjectKind::Cache: value = this->BuildCache(object); break; @@ -503,6 +539,8 @@ cmFileAPI::ClientRequest cmFileAPI::BuildClientRequest( if (kindName == this->ObjectKindName(ObjectKind::CodeModel)) { r.Kind = ObjectKind::CodeModel; + } else if (kindName == this->ObjectKindName(ObjectKind::ConfigureLog)) { + r.Kind = ObjectKind::ConfigureLog; } else if (kindName == this->ObjectKindName(ObjectKind::Cache)) { r.Kind = ObjectKind::Cache; } else if (kindName == this->ObjectKindName(ObjectKind::CMakeFiles)) { @@ -530,6 +568,9 @@ cmFileAPI::ClientRequest cmFileAPI::BuildClientRequest( case ObjectKind::CodeModel: this->BuildClientRequestCodeModel(r, versions); break; + case ObjectKind::ConfigureLog: + this->BuildClientRequestConfigureLog(r, versions); + break; case ObjectKind::Cache: this->BuildClientRequestCache(r, versions); break; @@ -719,6 +760,41 @@ Json::Value cmFileAPI::BuildCodeModel(Object const& object) return codemodel; } +// The "configureLog" object kind. + +// Update Help/manual/cmake-file-api.7.rst when updating this constant. +static unsigned int const ConfigureLogV1Minor = 0; + +void cmFileAPI::BuildClientRequestConfigureLog( + ClientRequest& r, std::vector<RequestVersion> const& versions) +{ + // Select a known version from those requested. + for (RequestVersion const& v : versions) { + if ((v.Major == 1 && v.Minor <= ConfigureLogV1Minor)) { + r.Version = v.Major; + break; + } + } + if (!r.Version) { + r.Error = NoSupportedVersion(versions); + } +} + +Json::Value cmFileAPI::BuildConfigureLog(Object const& object) +{ + Json::Value configureLog = cmFileAPIConfigureLogDump(*this, object.Version); + configureLog["kind"] = this->ObjectKindName(object.Kind); + + Json::Value& version = configureLog["version"]; + if (object.Version == 1) { + version = BuildVersion(1, ConfigureLogV1Minor); + } else { + return configureLog; // should be unreachable + } + + return configureLog; +} + // The "cache" object kind. static unsigned int const CacheV2Minor = 0; @@ -870,6 +946,14 @@ Json::Value cmFileAPI::ReportCapabilities() { Json::Value request = Json::objectValue; + request["kind"] = ObjectKindName(ObjectKind::ConfigureLog); + Json::Value& versions = request["version"] = Json::arrayValue; + versions.append(BuildVersion(1, ConfigureLogV1Minor)); + requests.append(std::move(request)); // NOLINT(*) + } + + { + Json::Value request = Json::objectValue; request["kind"] = ObjectKindName(ObjectKind::Cache); Json::Value& versions = request["version"] = Json::arrayValue; versions.append(BuildVersion(2, CacheV2Minor)); |