Commit fa00a3b2 authored by Brad King's avatar Brad King

Merge branch 'capabilities-fileapi' into release-3.15

Merge-request: !3433
parents 8d3c919a c932f498
...@@ -379,6 +379,8 @@ finds the file missing, that means a concurrent CMake has generated ...@@ -379,6 +379,8 @@ finds the file missing, that means a concurrent CMake has generated
a new reply. The client may simply start again by reading the new a new reply. The client may simply start again by reading the new
reply index file. reply index file.
.. _`file-api object kinds`:
Object Kinds Object Kinds
============ ============
......
...@@ -423,6 +423,22 @@ Available commands are: ...@@ -423,6 +423,22 @@ Available commands are:
A list of strings with all the extra generators compatible with A list of strings with all the extra generators compatible with
the generator. the generator.
``fileApi``
Optional member that is present when the :manual:`cmake-file-api(7)`
is available. The value is a JSON object with one member:
``requests``
A JSON array containing zero or more supported file-api requests.
Each request is a JSON object with members:
``kind``
Specifies one of the supported :ref:`file-api object kinds`.
``version``
A JSON array whose elements are each a JSON object containing
``major`` and ``minor`` members specifying non-negative integer
version components.
``serverMode`` ``serverMode``
``true`` if cmake supports server-mode and ``false`` otherwise. ``true`` if cmake supports server-mode and ``false`` otherwise.
......
...@@ -413,6 +413,14 @@ std::string cmFileAPI::ObjectName(Object const& o) ...@@ -413,6 +413,14 @@ std::string cmFileAPI::ObjectName(Object const& o)
return name; return name;
} }
Json::Value cmFileAPI::BuildVersion(unsigned int major, unsigned int minor)
{
Json::Value version;
version["major"] = major;
version["minor"] = minor;
return version;
}
Json::Value cmFileAPI::BuildObject(Object const& object) Json::Value cmFileAPI::BuildObject(Object const& object)
{ {
Json::Value value; Json::Value value;
...@@ -680,10 +688,9 @@ Json::Value cmFileAPI::BuildCodeModel(Object const& object) ...@@ -680,10 +688,9 @@ Json::Value cmFileAPI::BuildCodeModel(Object const& object)
Json::Value codemodel = cmFileAPICodemodelDump(*this, object.Version); Json::Value codemodel = cmFileAPICodemodelDump(*this, object.Version);
codemodel["kind"] = this->ObjectKindName(object.Kind); codemodel["kind"] = this->ObjectKindName(object.Kind);
Json::Value& version = codemodel["version"] = Json::objectValue; Json::Value& version = codemodel["version"];
if (object.Version == 2) { if (object.Version == 2) {
version["major"] = 2; version = BuildVersion(2, CodeModelV2Minor);
version["minor"] = CodeModelV2Minor;
} else { } else {
return codemodel; // should be unreachable return codemodel; // should be unreachable
} }
...@@ -716,10 +723,9 @@ Json::Value cmFileAPI::BuildCache(Object const& object) ...@@ -716,10 +723,9 @@ Json::Value cmFileAPI::BuildCache(Object const& object)
Json::Value cache = cmFileAPICacheDump(*this, object.Version); Json::Value cache = cmFileAPICacheDump(*this, object.Version);
cache["kind"] = this->ObjectKindName(object.Kind); cache["kind"] = this->ObjectKindName(object.Kind);
Json::Value& version = cache["version"] = Json::objectValue; Json::Value& version = cache["version"];
if (object.Version == 2) { if (object.Version == 2) {
version["major"] = 2; version = BuildVersion(2, CacheV2Minor);
version["minor"] = CacheV2Minor;
} else { } else {
return cache; // should be unreachable return cache; // should be unreachable
} }
...@@ -752,10 +758,9 @@ Json::Value cmFileAPI::BuildCMakeFiles(Object const& object) ...@@ -752,10 +758,9 @@ Json::Value cmFileAPI::BuildCMakeFiles(Object const& object)
Json::Value cmakeFiles = cmFileAPICMakeFilesDump(*this, object.Version); Json::Value cmakeFiles = cmFileAPICMakeFilesDump(*this, object.Version);
cmakeFiles["kind"] = this->ObjectKindName(object.Kind); cmakeFiles["kind"] = this->ObjectKindName(object.Kind);
Json::Value& version = cmakeFiles["version"] = Json::objectValue; Json::Value& version = cmakeFiles["version"];
if (object.Version == 1) { if (object.Version == 1) {
version["major"] = 1; version = BuildVersion(1, CMakeFilesV1Minor);
version["minor"] = CMakeFilesV1Minor;
} else { } else {
return cmakeFiles; // should be unreachable return cmakeFiles; // should be unreachable
} }
...@@ -788,13 +793,43 @@ Json::Value cmFileAPI::BuildInternalTest(Object const& object) ...@@ -788,13 +793,43 @@ Json::Value cmFileAPI::BuildInternalTest(Object const& object)
{ {
Json::Value test = Json::objectValue; Json::Value test = Json::objectValue;
test["kind"] = this->ObjectKindName(object.Kind); test["kind"] = this->ObjectKindName(object.Kind);
Json::Value& version = test["version"] = Json::objectValue; Json::Value& version = test["version"];
if (object.Version == 2) { if (object.Version == 2) {
version["major"] = 2; version = BuildVersion(2, InternalTestV2Minor);
version["minor"] = InternalTestV2Minor;
} else { } else {
version["major"] = 1; version = BuildVersion(1, InternalTestV1Minor);
version["minor"] = InternalTestV1Minor;
} }
return test; return test;
} }
Json::Value cmFileAPI::ReportCapabilities()
{
Json::Value capabilities = Json::objectValue;
Json::Value& requests = capabilities["requests"] = Json::arrayValue;
{
Json::Value request = Json::objectValue;
request["kind"] = ObjectKindName(ObjectKind::CodeModel);
Json::Value& versions = request["version"] = Json::arrayValue;
versions.append(BuildVersion(2, CodeModelV2Minor));
requests.append(std::move(request));
}
{
Json::Value request = Json::objectValue;
request["kind"] = ObjectKindName(ObjectKind::Cache);
Json::Value& versions = request["version"] = Json::arrayValue;
versions.append(BuildVersion(2, CacheV2Minor));
requests.append(std::move(request));
}
{
Json::Value request = Json::objectValue;
request["kind"] = ObjectKindName(ObjectKind::CMakeFiles);
Json::Value& versions = request["version"] = Json::arrayValue;
versions.append(BuildVersion(1, CMakeFilesV1Minor));
requests.append(std::move(request));
}
return capabilities;
}
...@@ -36,6 +36,9 @@ public: ...@@ -36,6 +36,9 @@ public:
and holding the original object. Other JSON types are unchanged. */ and holding the original object. Other JSON types are unchanged. */
Json::Value MaybeJsonFile(Json::Value in, std::string const& prefix); Json::Value MaybeJsonFile(Json::Value in, std::string const& prefix);
/** Report file-api capabilities for cmake -E capabilities. */
static Json::Value ReportCapabilities();
private: private:
cmake* CMakeInstance; cmake* CMakeInstance;
...@@ -162,6 +165,8 @@ private: ...@@ -162,6 +165,8 @@ private:
static const char* ObjectKindName(ObjectKind kind); static const char* ObjectKindName(ObjectKind kind);
static std::string ObjectName(Object const& o); static std::string ObjectName(Object const& o);
static Json::Value BuildVersion(unsigned int major, unsigned int minor);
Json::Value BuildObject(Object const& object); Json::Value BuildObject(Object const& object);
ClientRequests BuildClientRequests(Json::Value const& requests); ClientRequests BuildClientRequests(Json::Value const& requests);
......
...@@ -630,7 +630,7 @@ cmServerResponse cmServerProtocol1::ProcessGlobalSettings( ...@@ -630,7 +630,7 @@ cmServerResponse cmServerProtocol1::ProcessGlobalSettings(
Json::Value obj = Json::objectValue; Json::Value obj = Json::objectValue;
// Capabilities information: // Capabilities information:
obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson(true); obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson();
obj[kDEBUG_OUTPUT_KEY] = cm->GetDebugOutput(); obj[kDEBUG_OUTPUT_KEY] = cm->GetDebugOutput();
obj[kTRACE_KEY] = cm->GetTrace(); obj[kTRACE_KEY] = cm->GetTrace();
......
...@@ -248,7 +248,7 @@ Json::Value cmake::ReportVersionJson() const ...@@ -248,7 +248,7 @@ Json::Value cmake::ReportVersionJson() const
return version; return version;
} }
Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const Json::Value cmake::ReportCapabilitiesJson() const
{ {
Json::Value obj = Json::objectValue; Json::Value obj = Json::objectValue;
...@@ -284,18 +284,19 @@ Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const ...@@ -284,18 +284,19 @@ Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const
generators.append(i.second); generators.append(i.second);
} }
obj["generators"] = generators; obj["generators"] = generators;
obj["serverMode"] = haveServerMode; obj["fileApi"] = cmFileAPI::ReportCapabilities();
obj["serverMode"] = true;
return obj; return obj;
} }
#endif #endif
std::string cmake::ReportCapabilities(bool haveServerMode) const std::string cmake::ReportCapabilities() const
{ {
std::string result; std::string result;
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
Json::FastWriter writer; Json::FastWriter writer;
result = writer.write(this->ReportCapabilitiesJson(haveServerMode)); result = writer.write(this->ReportCapabilitiesJson());
#else #else
result = "Not supported"; result = "Not supported";
#endif #endif
......
...@@ -136,9 +136,9 @@ public: ...@@ -136,9 +136,9 @@ public:
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
Json::Value ReportVersionJson() const; Json::Value ReportVersionJson() const;
Json::Value ReportCapabilitiesJson(bool haveServerMode) const; Json::Value ReportCapabilitiesJson() const;
#endif #endif
std::string ReportCapabilities(bool haveServerMode) const; std::string ReportCapabilities() const;
//@{ //@{
/** /**
......
...@@ -734,11 +734,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) ...@@ -734,11 +734,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
return 1; return 1;
} }
cmake cm(cmake::RoleInternal, cmState::Unknown); cmake cm(cmake::RoleInternal, cmState::Unknown);
#if defined(CMAKE_BUILD_WITH_CMAKE) std::cout << cm.ReportCapabilities();
std::cout << cm.ReportCapabilities(true);
#else
std::cout << cm.ReportCapabilities(false);
#endif
return 0; return 0;
} }
......
^{.*}$ ^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":0}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":true,"version":{.*}}$
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment