server-mode: Query global configuration of cmake via a command
Add "globalSettings" command that returns: * Return capability information * Return currently used generator/extra generator * Return a range of flags for debug/trace/etc.
This commit is contained in:
parent
1a5fddfe6d
commit
82104cc7a8
|
@ -248,3 +248,57 @@ which will result in a response type "reply"::
|
||||||
]== CMake Server ==]
|
]== CMake Server ==]
|
||||||
|
|
||||||
indicating that the server is ready for action.
|
indicating that the server is ready for action.
|
||||||
|
|
||||||
|
|
||||||
|
Type "globalSettings"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This request can be sent after the initial handshake. It will return a
|
||||||
|
JSON structure with information on cmake state.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
[== CMake Server ==[
|
||||||
|
{"type":"globalSettings"}
|
||||||
|
]== CMake Server ==]
|
||||||
|
|
||||||
|
which will result in a response type "reply"::
|
||||||
|
|
||||||
|
[== CMake Server ==[
|
||||||
|
{
|
||||||
|
"buildDirectory": "/tmp/test-build",
|
||||||
|
"capabilities": {
|
||||||
|
"generators": [
|
||||||
|
{
|
||||||
|
"extraGenerators": [],
|
||||||
|
"name": "Watcom WMake",
|
||||||
|
"platformSupport": false,
|
||||||
|
"toolsetSupport": false
|
||||||
|
},
|
||||||
|
<...>
|
||||||
|
],
|
||||||
|
"serverMode": false,
|
||||||
|
"version": {
|
||||||
|
"isDirty": false,
|
||||||
|
"major": 3,
|
||||||
|
"minor": 6,
|
||||||
|
"patch": 20160830,
|
||||||
|
"string": "3.6.20160830-gd6abad",
|
||||||
|
"suffix": "gd6abad"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"checkSystemVars": false,
|
||||||
|
"cookie": "",
|
||||||
|
"extraGenerator": "",
|
||||||
|
"generator": "Ninja",
|
||||||
|
"debugOutput": false,
|
||||||
|
"inReplyTo": "globalSettings",
|
||||||
|
"sourceDirectory": "/home/code/cmake",
|
||||||
|
"trace": false,
|
||||||
|
"traceExpand": false,
|
||||||
|
"type": "reply",
|
||||||
|
"warnUninitialized": false,
|
||||||
|
"warnUnused": false,
|
||||||
|
"warnUnusedCli": true
|
||||||
|
}
|
||||||
|
]== CMake Server ==]
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Vocabulary:
|
// Vocabulary:
|
||||||
|
|
||||||
static const std::string kERROR_TYPE = "error";
|
static const std::string kERROR_TYPE = "error";
|
||||||
|
static const std::string kGLOBAL_SETTINGS_TYPE = "globalSettings";
|
||||||
static const std::string kHANDSHAKE_TYPE = "handshake";
|
static const std::string kHANDSHAKE_TYPE = "handshake";
|
||||||
static const std::string kMESSAGE_TYPE = "message";
|
static const std::string kMESSAGE_TYPE = "message";
|
||||||
static const std::string kPROGRESS_TYPE = "progress";
|
static const std::string kPROGRESS_TYPE = "progress";
|
||||||
|
@ -24,7 +25,10 @@ static const std::string kREPLY_TYPE = "reply";
|
||||||
static const std::string kSIGNAL_TYPE = "signal";
|
static const std::string kSIGNAL_TYPE = "signal";
|
||||||
|
|
||||||
static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory";
|
static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory";
|
||||||
|
static const std::string kCAPABILITIES_KEY = "capabilities";
|
||||||
|
static const std::string kCHECK_SYSTEM_VARS_KEY = "checkSystemVars";
|
||||||
static const std::string kCOOKIE_KEY = "cookie";
|
static const std::string kCOOKIE_KEY = "cookie";
|
||||||
|
static const std::string kDEBUG_OUTPUT_KEY = "debugOutput";
|
||||||
static const std::string kERROR_MESSAGE_KEY = "errorMessage";
|
static const std::string kERROR_MESSAGE_KEY = "errorMessage";
|
||||||
static const std::string kEXTRA_GENERATOR_KEY = "extraGenerator";
|
static const std::string kEXTRA_GENERATOR_KEY = "extraGenerator";
|
||||||
static const std::string kGENERATOR_KEY = "generator";
|
static const std::string kGENERATOR_KEY = "generator";
|
||||||
|
@ -43,7 +47,12 @@ static const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory";
|
||||||
static const std::string kSUPPORTED_PROTOCOL_VERSIONS =
|
static const std::string kSUPPORTED_PROTOCOL_VERSIONS =
|
||||||
"supportedProtocolVersions";
|
"supportedProtocolVersions";
|
||||||
static const std::string kTITLE_KEY = "title";
|
static const std::string kTITLE_KEY = "title";
|
||||||
|
static const std::string kTRACE_EXPAND_KEY = "traceExpand";
|
||||||
|
static const std::string kTRACE_KEY = "trace";
|
||||||
static const std::string kTYPE_KEY = "type";
|
static const std::string kTYPE_KEY = "type";
|
||||||
|
static const std::string kWARN_UNINITIALIZED_KEY = "warnUninitialized";
|
||||||
|
static const std::string kWARN_UNUSED_CLI_KEY = "warnUnusedCli";
|
||||||
|
static const std::string kWARN_UNUSED_KEY = "warnUnused";
|
||||||
|
|
||||||
static const std::string kSTART_MAGIC = "[== CMake Server ==[";
|
static const std::string kSTART_MAGIC = "[== CMake Server ==[";
|
||||||
static const std::string kEND_MAGIC = "]== CMake Server ==]";
|
static const std::string kEND_MAGIC = "]== CMake Server ==]";
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "cmServerProtocol.h"
|
#include "cmServerProtocol.h"
|
||||||
|
|
||||||
#include "cmExternalMakefileProjectGenerator.h"
|
#include "cmExternalMakefileProjectGenerator.h"
|
||||||
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmServer.h"
|
#include "cmServer.h"
|
||||||
#include "cmServerDictionary.h"
|
#include "cmServerDictionary.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
@ -279,6 +280,10 @@ const cmServerResponse cmServerProtocol1_0::Process(
|
||||||
{
|
{
|
||||||
assert(this->m_State >= STATE_ACTIVE);
|
assert(this->m_State >= STATE_ACTIVE);
|
||||||
|
|
||||||
|
if (request.Type == kGLOBAL_SETTINGS_TYPE) {
|
||||||
|
return this->ProcessGlobalSettings(request);
|
||||||
|
}
|
||||||
|
|
||||||
return request.ReportError("Unknown command!");
|
return request.ReportError("Unknown command!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,3 +291,32 @@ bool cmServerProtocol1_0::IsExperimental() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmServerResponse cmServerProtocol1_0::ProcessGlobalSettings(
|
||||||
|
const cmServerRequest& request)
|
||||||
|
{
|
||||||
|
cmake* cm = this->CMakeInstance();
|
||||||
|
Json::Value obj = Json::objectValue;
|
||||||
|
|
||||||
|
// Capabilities information:
|
||||||
|
obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson(true);
|
||||||
|
|
||||||
|
obj[kDEBUG_OUTPUT_KEY] = cm->GetDebugOutput();
|
||||||
|
obj[kTRACE_KEY] = cm->GetTrace();
|
||||||
|
obj[kTRACE_EXPAND_KEY] = cm->GetTraceExpand();
|
||||||
|
obj[kWARN_UNINITIALIZED_KEY] = cm->GetWarnUninitialized();
|
||||||
|
obj[kWARN_UNUSED_KEY] = cm->GetWarnUnused();
|
||||||
|
obj[kWARN_UNUSED_CLI_KEY] = cm->GetWarnUnusedCli();
|
||||||
|
obj[kCHECK_SYSTEM_VARS_KEY] = cm->GetCheckSystemVars();
|
||||||
|
|
||||||
|
obj[kSOURCE_DIRECTORY_KEY] = cm->GetHomeDirectory();
|
||||||
|
obj[kBUILD_DIRECTORY_KEY] = cm->GetHomeOutputDirectory();
|
||||||
|
|
||||||
|
// Currently used generator:
|
||||||
|
cmGlobalGenerator* gen = cm->GetGlobalGenerator();
|
||||||
|
obj[kGENERATOR_KEY] = gen ? gen->GetName() : std::string();
|
||||||
|
obj[kEXTRA_GENERATOR_KEY] =
|
||||||
|
gen ? gen->GetExtraGeneratorName() : std::string();
|
||||||
|
|
||||||
|
return request.Reply(obj);
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
|
#include "cmake.h"
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#include "cm_jsoncpp_writer.h"
|
#include "cm_jsoncpp_writer.h"
|
||||||
|
@ -116,6 +117,9 @@ private:
|
||||||
bool DoActivate(const cmServerRequest& request,
|
bool DoActivate(const cmServerRequest& request,
|
||||||
std::string* errorMessage) override;
|
std::string* errorMessage) override;
|
||||||
|
|
||||||
|
// Handle requests:
|
||||||
|
cmServerResponse ProcessGlobalSettings(const cmServerRequest& request);
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
STATE_INACTIVE,
|
STATE_INACTIVE,
|
||||||
|
|
|
@ -19,5 +19,6 @@ macro(do_test bsname file)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
do_test("test_handshake" "tc_handshake.json")
|
do_test("test_handshake" "tc_handshake.json")
|
||||||
|
do_test("test_globalSettings" "tc_globalSettings.json")
|
||||||
|
|
||||||
add_executable(Server empty.cpp)
|
add_executable(Server empty.cpp)
|
||||||
|
|
|
@ -106,6 +106,7 @@ def waitForReply(cmakeCommand, originalType, cookie):
|
||||||
packet = waitForRawMessage(cmakeCommand)
|
packet = waitForRawMessage(cmakeCommand)
|
||||||
if packet['cookie'] != cookie or packet['type'] != 'reply' or packet['inReplyTo'] != originalType:
|
if packet['cookie'] != cookie or packet['type'] != 'reply' or packet['inReplyTo'] != originalType:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
return packet
|
||||||
|
|
||||||
def waitForError(cmakeCommand, originalType, cookie, message):
|
def waitForError(cmakeCommand, originalType, cookie, message):
|
||||||
packet = waitForRawMessage(cmakeCommand)
|
packet = waitForRawMessage(cmakeCommand)
|
||||||
|
@ -117,10 +118,66 @@ def waitForProgress(cmakeCommand, originalType, cookie, current, message):
|
||||||
if packet['cookie'] != cookie or packet['type'] != 'progress' or packet['inReplyTo'] != originalType or packet['progressCurrent'] != current or packet['progressMessage'] != message:
|
if packet['cookie'] != cookie or packet['type'] != 'progress' or packet['inReplyTo'] != originalType or packet['progressCurrent'] != current or packet['progressMessage'] != message:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def handshake(cmakeCommand, major, minor):
|
def handshake(cmakeCommand, major, minor, source, build, generator, extraGenerator):
|
||||||
version = { 'major': major }
|
version = { 'major': major }
|
||||||
if minor >= 0:
|
if minor >= 0:
|
||||||
version['minor'] = minor
|
version['minor'] = minor
|
||||||
|
|
||||||
writePayload(cmakeCommand, { 'type': 'handshake', 'protocolVersion': version, 'cookie': 'TEST_HANDSHAKE' })
|
writePayload(cmakeCommand, { 'type': 'handshake', 'protocolVersion': version,
|
||||||
|
'cookie': 'TEST_HANDSHAKE', 'sourceDirectory': source, 'buildDirectory': build,
|
||||||
|
'generator': generator, 'extraGenerator': extraGenerator })
|
||||||
waitForReply(cmakeCommand, 'handshake', 'TEST_HANDSHAKE')
|
waitForReply(cmakeCommand, 'handshake', 'TEST_HANDSHAKE')
|
||||||
|
|
||||||
|
def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
|
||||||
|
packet = waitForReply(cmakeCommand, 'globalSettings', '')
|
||||||
|
|
||||||
|
capabilities = packet['capabilities']
|
||||||
|
|
||||||
|
# validate version:
|
||||||
|
cmakeoutput = subprocess.check_output([ cmakeCommandPath, "--version" ], universal_newlines=True)
|
||||||
|
cmakeVersion = cmakeoutput.splitlines()[0][14:]
|
||||||
|
|
||||||
|
version = capabilities['version']
|
||||||
|
versionString = version['string']
|
||||||
|
vs = str(version['major']) + '.' + str(version['minor']) + '.' + str(version['patch'])
|
||||||
|
if (versionString != vs and not versionString.startswith(vs + '-')):
|
||||||
|
sys.exit(1)
|
||||||
|
if (versionString != cmakeVersion):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# validate generators:
|
||||||
|
generatorObjects = capabilities['generators']
|
||||||
|
|
||||||
|
cmakeoutput = subprocess.check_output([ cmakeCommandPath, "--help" ], universal_newlines=True)
|
||||||
|
index = cmakeoutput.index('\nGenerators\n\n')
|
||||||
|
cmakeGenerators = []
|
||||||
|
for line in cmakeoutput[index + 12:].splitlines():
|
||||||
|
if not line.startswith(' '):
|
||||||
|
continue
|
||||||
|
equalPos = line.find('=')
|
||||||
|
tmp = ''
|
||||||
|
if (equalPos > 0):
|
||||||
|
tmp = line[2:equalPos].strip()
|
||||||
|
else:
|
||||||
|
tmp = line.strip()
|
||||||
|
if (len(tmp) > 0) and (" - " not in tmp) and (tmp != 'KDevelop3'):
|
||||||
|
cmakeGenerators.append(tmp)
|
||||||
|
|
||||||
|
generators = []
|
||||||
|
for genObj in generatorObjects:
|
||||||
|
generators.append(genObj['name'])
|
||||||
|
|
||||||
|
generators.sort()
|
||||||
|
cmakeGenerators.sort()
|
||||||
|
|
||||||
|
if (generators != cmakeGenerators):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
gen = packet['generator']
|
||||||
|
if (gen != '' and not (gen in generators)):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for i in data:
|
||||||
|
print("Validating", i)
|
||||||
|
if (packet[i] != data[i]):
|
||||||
|
sys.exit(1)
|
||||||
|
|
|
@ -68,9 +68,25 @@ for obj in testData:
|
||||||
if debug: print("Doing handshake:", json.dumps(data))
|
if debug: print("Doing handshake:", json.dumps(data))
|
||||||
major = -1
|
major = -1
|
||||||
minor = -1
|
minor = -1
|
||||||
|
generator = 'Ninja'
|
||||||
|
extraGenerator = 'CodeBlocks'
|
||||||
|
sourceDirectory = sourceDir
|
||||||
|
buildDirectory = buildDir
|
||||||
if 'major' in data: major = data['major']
|
if 'major' in data: major = data['major']
|
||||||
if 'minor' in data: minor = data['minor']
|
if 'minor' in data: minor = data['minor']
|
||||||
cmakelib.handshake(proc, major, minor)
|
if 'buildDirectory' in data: buildDirectory = data['buildDirectory']
|
||||||
|
if 'sourceDirectory' in data: sourceDirectory = data['sourceDirectory']
|
||||||
|
if 'generator' in data: generator = data['generator']
|
||||||
|
if 'extraGenerator' in data: extraGenerator = data['extraGenerator']
|
||||||
|
cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory,
|
||||||
|
generator, extraGenerator)
|
||||||
|
elif 'validateGlobalSettings' in obj:
|
||||||
|
data = obj['validateGlobalSettings']
|
||||||
|
if not 'buildDirectory' in data: data['buildDirectory'] = buildDir
|
||||||
|
if not 'sourceDirectory' in data: data['sourceDirectory'] = sourceDir
|
||||||
|
if not 'generator' in data: data['generator'] = 'Ninja'
|
||||||
|
if not 'extraGenerator' in data: data['extraGenerator'] = 'CodeBlocks'
|
||||||
|
cmakelib.validateGlobalSettings(proc, cmakeCommand, data)
|
||||||
elif 'message' in obj:
|
elif 'message' in obj:
|
||||||
print("MESSAGE:", obj["message"])
|
print("MESSAGE:", obj["message"])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
[
|
||||||
|
{ "message": "Testing globalSettings" },
|
||||||
|
|
||||||
|
{ "handshake": {"major": 1} },
|
||||||
|
|
||||||
|
{ "send": {"type": "globalSettings"} },
|
||||||
|
{ "validateGlobalSettings": { } },
|
||||||
|
|
||||||
|
{ "message": "Everything ok." }
|
||||||
|
]
|
Loading…
Reference in New Issue