diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-09 08:01:46 (GMT) |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-28 16:32:55 (GMT) |
commit | 7b1e60f26e284e223be8638744ba3a3b0efdee63 (patch) | |
tree | 97ac29662cc89d98bd5d05471ea7d5ba15d8d0ea /Source/cmServerProtocol.cxx | |
parent | 84553a6e709ea810f3e7fc5ece5daa1c53be5cda (diff) | |
download | CMake-7b1e60f26e284e223be8638744ba3a3b0efdee63.zip CMake-7b1e60f26e284e223be8638744ba3a3b0efdee63.tar.gz CMake-7b1e60f26e284e223be8638744ba3a3b0efdee63.tar.bz2 |
server-mode: Report CMakeCache entries
With this it would be possible to implement something like
cmake-gui using server-mode.
Diffstat (limited to 'Source/cmServerProtocol.cxx')
-rw-r--r-- | Source/cmServerProtocol.cxx | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 00a8135..f083e49 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServerProtocol.h" +#include "cmCacheManager.h" #include "cmExternalMakefileProjectGenerator.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -62,6 +63,15 @@ static Json::Value fromStringList(const T& in) return result; } +static std::vector<std::string> toStringList(const Json::Value& in) +{ + std::vector<std::string> result; + for (const auto& it : in) { + result.push_back(it.asString()); + } + return result; +} + static void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, const std::string& buildDir, @@ -360,6 +370,9 @@ const cmServerResponse cmServerProtocol1_0::Process( { assert(this->m_State >= STATE_ACTIVE); + if (request.Type == kCACHE_TYPE) { + return this->ProcessCache(request); + } if (request.Type == kCMAKE_INPUTS_TYPE) { return this->ProcessCMakeInputs(request); } @@ -387,6 +400,57 @@ bool cmServerProtocol1_0::IsExperimental() const return true; } +cmServerResponse cmServerProtocol1_0::ProcessCache( + const cmServerRequest& request) +{ + if (this->m_State < STATE_CONFIGURED) { + return request.ReportError("This project was not configured yet."); + } + + cmState* state = this->CMakeInstance()->GetState(); + + Json::Value result = Json::objectValue; + + std::vector<std::string> allKeys = state->GetCacheEntryKeys(); + + Json::Value list = Json::arrayValue; + std::vector<std::string> keys = toStringList(request.Data[kKEYS_KEY]); + if (keys.empty()) { + keys = allKeys; + } else { + for (auto i : keys) { + if (std::find_if(allKeys.begin(), allKeys.end(), + [i](const std::string& j) { return i == j; }) == + allKeys.end()) { + return request.ReportError("Key \"" + i + "\" not found in cache."); + } + } + } + std::sort(keys.begin(), keys.end()); + for (auto key : keys) { + Json::Value entry = Json::objectValue; + entry[kKEY_KEY] = key; + entry[kTYPE_KEY] = + cmState::CacheEntryTypeToString(state->GetCacheEntryType(key)); + entry[kVALUE_KEY] = state->GetCacheEntryValue(key); + + Json::Value props = Json::objectValue; + bool haveProperties = false; + for (auto prop : state->GetCacheEntryPropertyList(key)) { + haveProperties = true; + props[prop] = state->GetCacheEntryProperty(key, prop); + } + if (haveProperties) { + entry[kPROPERTIES_KEY] = props; + } + + list.append(entry); + } + + result[kCACHE_KEY] = list; + return request.Reply(result); +} + cmServerResponse cmServerProtocol1_0::ProcessCMakeInputs( const cmServerRequest& request) { |