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 | |
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')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmFileAPI.cxx | 94 | ||||
-rw-r--r-- | Source/cmFileAPI.h | 8 | ||||
-rw-r--r-- | Source/cmFileAPIConfigureLog.cxx | 67 | ||||
-rw-r--r-- | Source/cmFileAPIConfigureLog.h | 12 | ||||
-rw-r--r-- | Source/cmTryCompileCommand.cxx | 1 | ||||
-rw-r--r-- | Source/cmTryRunCommand.cxx | 1 | ||||
-rw-r--r-- | Source/cmake.cxx | 2 |
8 files changed, 181 insertions, 6 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index db928fc..e99da49 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -237,6 +237,8 @@ add_library( cmFileAPICache.h cmFileAPICodemodel.cxx cmFileAPICodemodel.h + cmFileAPIConfigureLog.cxx + cmFileAPIConfigureLog.h cmFileAPICMakeFiles.cxx cmFileAPICMakeFiles.h cmFileAPIToolchains.cxx 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)); diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h index 22302b4..6d7678f 100644 --- a/Source/cmFileAPI.h +++ b/Source/cmFileAPI.h @@ -24,6 +24,9 @@ public: /** Read fileapi queries from disk. */ void ReadQueries(); + /** Get the list of configureLog object kind versions requested. */ + std::vector<unsigned long> GetConfigureLogVersions(); + /** Write fileapi replies to disk. */ void WriteReplies(); @@ -54,6 +57,7 @@ private: enum class ObjectKind { CodeModel, + ConfigureLog, Cache, CMakeFiles, Toolchains, @@ -193,6 +197,10 @@ private: ClientRequest& r, std::vector<RequestVersion> const& versions); Json::Value BuildCodeModel(Object const& object); + void BuildClientRequestConfigureLog( + ClientRequest& r, std::vector<RequestVersion> const& versions); + Json::Value BuildConfigureLog(Object const& object); + void BuildClientRequestCache(ClientRequest& r, std::vector<RequestVersion> const& versions); Json::Value BuildCache(Object const& object); diff --git a/Source/cmFileAPIConfigureLog.cxx b/Source/cmFileAPIConfigureLog.cxx new file mode 100644 index 0000000..50189cb --- /dev/null +++ b/Source/cmFileAPIConfigureLog.cxx @@ -0,0 +1,67 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmFileAPIConfigureLog.h" + +#include <cm3p/json/value.h> + +#include "cmFileAPI.h" +#include "cmStringAlgorithms.h" +#include "cmake.h" + +namespace { + +class ConfigureLog +{ + cmFileAPI& FileAPI; + unsigned long Version; + + Json::Value DumpPath(); + Json::Value DumpEventKindNames(); + +public: + ConfigureLog(cmFileAPI& fileAPI, unsigned long version); + Json::Value Dump(); +}; + +ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned long version) + : FileAPI(fileAPI) + , Version(version) +{ + static_cast<void>(this->Version); +} + +Json::Value ConfigureLog::Dump() +{ + Json::Value configureLog = Json::objectValue; + configureLog["path"] = this->DumpPath(); + configureLog["eventKindNames"] = this->DumpEventKindNames(); + return configureLog; +} + +Json::Value ConfigureLog::DumpPath() +{ + return cmStrCat(this->FileAPI.GetCMakeInstance()->GetHomeOutputDirectory(), + "/CMakeFiles/CMakeConfigureLog.yaml"); +} + +Json::Value ConfigureLog::DumpEventKindNames() +{ + // Report at most one version of each event kind. + // If a new event kind is added, increment ConfigureLogV1Minor. + // If a new version of an existing event kind is added, a new + // major version of the configureLog object kind is needed. + Json::Value eventKindNames = Json::arrayValue; + if (this->Version == 1) { + eventKindNames.append("try_compile-v1"); // WriteTryCompileEvent + eventKindNames.append("try_run-v1"); // WriteTryRunEvent + } + return eventKindNames; +} +} + +Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, + unsigned long version) +{ + ConfigureLog configureLog(fileAPI, version); + return configureLog.Dump(); +} diff --git a/Source/cmFileAPIConfigureLog.h b/Source/cmFileAPIConfigureLog.h new file mode 100644 index 0000000..deaa403 --- /dev/null +++ b/Source/cmFileAPIConfigureLog.h @@ -0,0 +1,12 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <cm3p/json/value.h> + +class cmFileAPI; + +extern Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI, + unsigned long version); diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index eff21cc..c70c03e 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -21,6 +21,7 @@ namespace { void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf, cmTryCompileResult const& compileResult) { + // Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. static const std::vector<unsigned long> LogVersionsWithTryCompileV1{ 1 }; if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) { diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 63e4478..86c9679 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -40,6 +40,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf, cmTryCompileResult const& compileResult, cmTryRunResult const& runResult) { + // Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames. static const std::vector<unsigned long> LogVersionsWithTryRunV1{ 1 }; if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ee63909..0d947a5 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2429,7 +2429,7 @@ int cmake::ActualConfigure() this->TruncateOutputLog("CMakeConfigureLog.yaml"); this->ConfigureLog = cm::make_unique<cmConfigureLog>( cmStrCat(this->GetHomeOutputDirectory(), "/CMakeFiles"_s), - std::vector<unsigned long>()); + this->FileAPI->GetConfigureLogVersions()); } #endif |