summaryrefslogtreecommitdiffstats
path: root/Source/cmFileAPI.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-11-01 13:37:17 (GMT)
committerBrad King <brad.king@kitware.com>2018-12-12 14:46:13 (GMT)
commit7489e95b8ec35c7faa1f9dcfc3a6962a56969531 (patch)
tree6c14a990c888995e4e696cc8d63780ca89ca80ca /Source/cmFileAPI.cxx
parentea0a0601682af00706cf57f6d3e27d4f0895ecbb (diff)
downloadCMake-7489e95b8ec35c7faa1f9dcfc3a6962a56969531.zip
CMake-7489e95b8ec35c7faa1f9dcfc3a6962a56969531.tar.gz
CMake-7489e95b8ec35c7faa1f9dcfc3a6962a56969531.tar.bz2
fileapi: add cache v2
Start with v2 to distinguish it from server-mode v1. Issue: #18398
Diffstat (limited to 'Source/cmFileAPI.cxx')
-rw-r--r--Source/cmFileAPI.cxx57
1 files changed, 57 insertions, 0 deletions
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;