summaryrefslogtreecommitdiffstats
path: root/Source/cmServerProtocol.cxx
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2016-09-13 09:39:24 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-19 12:57:57 (GMT)
commitd341d077c5fb5c3df3732210b836a9ba6cb53873 (patch)
tree2235f21ec1ae9ff3c810204f159fc35adb60c45b /Source/cmServerProtocol.cxx
parentb13d3e0d0b3c644242ef8dc4977d35da73398a9d (diff)
downloadCMake-d341d077c5fb5c3df3732210b836a9ba6cb53873.zip
CMake-d341d077c5fb5c3df3732210b836a9ba6cb53873.tar.gz
CMake-d341d077c5fb5c3df3732210b836a9ba6cb53873.tar.bz2
cmake-server: Implement ServerProtocol 1.0
Enable the initial handshake of the client to complete the connection to the server. The handshake sets the protocol version that client and server will use to talk to each other. The only way to change this is to quit the server and start over. CMake specific information is also set during the initial handshake. Since cmake so far never had to change basic information about any project while running, it was decided to keep this information static and require a restart of the cmake server to change any of these.
Diffstat (limited to 'Source/cmServerProtocol.cxx')
-rw-r--r--Source/cmServerProtocol.cxx135
1 files changed, 135 insertions, 0 deletions
diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx
index 659aa0f..c3a4d8e 100644
--- a/Source/cmServerProtocol.cxx
+++ b/Source/cmServerProtocol.cxx
@@ -14,6 +14,7 @@
#include "cmExternalMakefileProjectGenerator.h"
#include "cmServer.h"
+#include "cmSystemTools.h"
#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -24,7 +25,11 @@
namespace {
// Vocabulary:
+const std::string kBUILD_DIRECTORY_KEY = "buildDirectory";
const std::string kCOOKIE_KEY = "cookie";
+const std::string kEXTRA_GENERATOR_KEY = "extraGenerator";
+const std::string kGENERATOR_KEY = "generator";
+const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory";
const std::string kTYPE_KEY = "type";
} // namespace
@@ -127,3 +132,133 @@ bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/,
{
return true;
}
+
+std::pair<int, int> cmServerProtocol1_0::ProtocolVersion() const
+{
+ return std::make_pair(1, 0);
+}
+
+bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
+ std::string* errorMessage)
+{
+ std::string sourceDirectory = request.Data[kSOURCE_DIRECTORY_KEY].asString();
+ const std::string buildDirectory =
+ request.Data[kBUILD_DIRECTORY_KEY].asString();
+ std::string generator = request.Data[kGENERATOR_KEY].asString();
+ std::string extraGenerator = request.Data[kEXTRA_GENERATOR_KEY].asString();
+
+ if (buildDirectory.empty()) {
+ if (errorMessage)
+ *errorMessage =
+ std::string("\"") + kBUILD_DIRECTORY_KEY + "\" is missing.";
+ return false;
+ }
+ cmake* cm = CMakeInstance();
+ if (cmSystemTools::PathExists(buildDirectory)) {
+ if (!cmSystemTools::FileIsDirectory(buildDirectory)) {
+ if (errorMessage)
+ *errorMessage = std::string("\"") + kBUILD_DIRECTORY_KEY +
+ "\" exists but is not a directory.";
+ return false;
+ }
+
+ const std::string cachePath = cm->FindCacheFile(buildDirectory);
+ if (cm->LoadCache(cachePath)) {
+ cmState* state = cm->GetState();
+
+ // Check generator:
+ const std::string cachedGenerator =
+ std::string(state->GetCacheEntryValue("CMAKE_GENERATOR"));
+ if (cachedGenerator.empty() && generator.empty()) {
+ if (errorMessage)
+ *errorMessage =
+ std::string("\"") + kGENERATOR_KEY + "\" is required but unset.";
+ return false;
+ }
+ if (generator.empty()) {
+ generator = cachedGenerator;
+ }
+ if (generator != cachedGenerator) {
+ if (errorMessage)
+ *errorMessage = std::string("\"") + kGENERATOR_KEY +
+ "\" set but incompatible with configured generator.";
+ return false;
+ }
+
+ // check extra generator:
+ const std::string cachedExtraGenerator =
+ std::string(state->GetCacheEntryValue("CMAKE_EXTRA_GENERATOR"));
+ if (!cachedExtraGenerator.empty() && !extraGenerator.empty() &&
+ cachedExtraGenerator != extraGenerator) {
+ if (errorMessage)
+ *errorMessage = std::string("\"") + kEXTRA_GENERATOR_KEY +
+ "\" is set but incompatible with configured extra generator.";
+ return false;
+ }
+ if (extraGenerator.empty()) {
+ extraGenerator = cachedExtraGenerator;
+ }
+
+ // check sourcedir:
+ const std::string cachedSourceDirectory =
+ std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"));
+ if (!cachedSourceDirectory.empty() && !sourceDirectory.empty() &&
+ cachedSourceDirectory != sourceDirectory) {
+ if (errorMessage)
+ *errorMessage = std::string("\"") + kSOURCE_DIRECTORY_KEY +
+ "\" is set but incompatible with configured source directory.";
+ return false;
+ }
+ if (sourceDirectory.empty()) {
+ sourceDirectory = cachedSourceDirectory;
+ }
+ }
+ }
+
+ if (sourceDirectory.empty()) {
+ if (errorMessage)
+ *errorMessage = std::string("\"") + kSOURCE_DIRECTORY_KEY +
+ "\" is unset but required.";
+ return false;
+ }
+ if (!cmSystemTools::FileIsDirectory(sourceDirectory)) {
+ if (errorMessage)
+ *errorMessage =
+ std::string("\"") + kSOURCE_DIRECTORY_KEY + "\" is not a directory.";
+ return false;
+ }
+ if (generator.empty()) {
+ if (errorMessage)
+ *errorMessage =
+ std::string("\"") + kGENERATOR_KEY + "\" is unset but required.";
+ return false;
+ }
+
+ const std::string fullGeneratorName =
+ cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
+ generator, extraGenerator);
+
+ cmGlobalGenerator* gg = cm->CreateGlobalGenerator(fullGeneratorName);
+ if (!gg) {
+ if (errorMessage)
+ *errorMessage =
+ std::string("Could not set up the requested combination of \"") +
+ kGENERATOR_KEY + "\" and \"" + kEXTRA_GENERATOR_KEY + "\"";
+ return false;
+ }
+
+ cm->SetGlobalGenerator(gg);
+ cm->SetHomeDirectory(sourceDirectory);
+ cm->SetHomeOutputDirectory(buildDirectory);
+
+ this->m_State = STATE_ACTIVE;
+ return true;
+}
+
+const cmServerResponse cmServerProtocol1_0::Process(
+ const cmServerRequest& request)
+{
+ assert(this->m_State >= STATE_ACTIVE);
+
+ return request.ReportError("Unknown command!");
+}