Преглед изворни кода

server-mode: Add --experimental flag

Allow for experimental cmProtocolVersions, which will only ever get
listed if the server was started with the (undocumented)
"--experimental" flag.

Mark current protocol version 1.0 as experimental.
Tobias Hunger пре 9 година
родитељ
комит
7df8a8f276

+ 15 - 4
Source/cmServer.cxx

@@ -85,7 +85,8 @@ void read_stdin(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf)
     free(buf->base);
 }
 
-cmServer::cmServer()
+cmServer::cmServer(bool supportExperimental)
+  : SupportExperimental(supportExperimental)
 {
   // Register supported protocols:
   this->RegisterProtocol(new cmServerProtocol1_0);
@@ -93,8 +94,9 @@ cmServer::cmServer()
 
 cmServer::~cmServer()
 {
-  if (!this->Protocol) // Daemon was never fully started!
+  if (!this->Protocol) { // Server was never fully started!
     return;
+  }
 
   uv_close(reinterpret_cast<uv_handle_t*>(this->InputStream), NULL);
   uv_close(reinterpret_cast<uv_handle_t*>(this->OutputStream), NULL);
@@ -171,6 +173,9 @@ void cmServer::handleData(const std::string& data)
 
 void cmServer::RegisterProtocol(cmServerProtocol* protocol)
 {
+  if (protocol->IsExperimental() && !this->SupportExperimental) {
+    return;
+  }
   auto version = protocol->ProtocolVersion();
   assert(version.first >= 0);
   assert(version.second >= 0);
@@ -196,6 +201,9 @@ void cmServer::PrintHello() const
     Json::Value tmp = Json::objectValue;
     tmp["major"] = version.first;
     tmp["minor"] = version.second;
+    if (proto->IsExperimental()) {
+      tmp["experimental"] = true;
+    }
     protocolVersions.append(tmp);
   }
 
@@ -245,9 +253,11 @@ cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
   return request.Reply(Json::objectValue);
 }
 
-void cmServer::Serve()
+bool cmServer::Serve()
 {
-  assert(!this->SupportedProtocols.empty());
+  if (this->SupportedProtocols.empty()) {
+    return false;
+  }
   assert(!this->Protocol);
 
   this->Loop = uv_default_loop();
@@ -279,6 +289,7 @@ void cmServer::Serve()
   uv_read_start(this->InputStream, alloc_buffer, read_stdin);
 
   uv_run(this->Loop, UV_RUN_DEFAULT);
+  return true;
 }
 
 void cmServer::WriteJsonObject(const Json::Value& jsonValue) const

+ 4 - 2
Source/cmServer.h

@@ -31,10 +31,10 @@ class cmServerResponse;
 class cmServer
 {
 public:
-  cmServer();
+  cmServer(bool supportExperimental);
   ~cmServer();
 
-  void Serve();
+  bool Serve();
 
   // for callbacks:
   void PopOne();
@@ -59,6 +59,8 @@ private:
   static cmServerProtocol* FindMatchingProtocol(
     const std::vector<cmServerProtocol*>& protocols, int major, int minor);
 
+  const bool SupportExperimental;
+
   cmServerProtocol* Protocol = nullptr;
   std::vector<cmServerProtocol*> SupportedProtocols;
   std::vector<std::string> Queue;

+ 5 - 0
Source/cmServerProtocol.cxx

@@ -262,3 +262,8 @@ const cmServerResponse cmServerProtocol1_0::Process(
 
   return request.ReportError("Unknown command!");
 }
+
+bool cmServerProtocol1_0::IsExperimental() const
+{
+  return true;
+}

+ 2 - 0
Source/cmServerProtocol.h

@@ -82,6 +82,7 @@ public:
   virtual ~cmServerProtocol() {}
 
   virtual std::pair<int, int> ProtocolVersion() const = 0;
+  virtual bool IsExperimental() const = 0;
   virtual const cmServerResponse Process(const cmServerRequest& request) = 0;
 
   bool Activate(const cmServerRequest& request, std::string* errorMessage);
@@ -100,6 +101,7 @@ class cmServerProtocol1_0 : public cmServerProtocol
 {
 public:
   std::pair<int, int> ProtocolVersion() const override;
+  bool IsExperimental() const override;
   const cmServerResponse Process(const cmServerRequest& request) override;
 
 private:

+ 21 - 4
Source/cmcmd.cxx

@@ -913,15 +913,32 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       }
       return 0;
     } else if (args[1] == "server") {
-      if (args.size() > 2) {
+      if (args.size() > 3) {
         cmSystemTools::Error("Too many arguments to start server mode");
         return 1;
       }
+      bool supportExperimental = false;
+      if (args.size() == 3) {
+        if (args[2] == "--experimental") {
+          supportExperimental = true;
+        } else {
+          cmSystemTools::Error("Unknown argument for server mode");
+          return 1;
+        }
+      }
 #if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
-      cmServer server;
-      server.Serve();
-      return 0;
+      cmServer server(supportExperimental);
+      if (server.Serve()) {
+        return 0;
+      } else {
+        cmSystemTools::Error(
+          "CMake server could not find any supported protocol. "
+          "Try with \"--experimental\" to enable "
+          "experimental support.");
+        return 1;
+      }
 #else
+      static_cast<void>(supportExperimental);
       cmSystemTools::Error("CMake was not built with server mode enabled");
       return 1;
 #endif

+ 1 - 1
Tests/RunCMake/CommandLine/E_server-arg-stderr.txt

@@ -1 +1 @@
-^CMake Error: Too many arguments to start server mode$
+^CMake Error: Unknown argument for server mode$

+ 1 - 1
Tests/Server/cmakelib.py

@@ -79,7 +79,7 @@ def writePayload(cmakeCommand, obj):
   writeRawData(cmakeCommand, json.dumps(obj))
 
 def initProc(cmakeCommand):
-  cmakeCommand = subprocess.Popen([cmakeCommand, "-E", "server"],
+  cmakeCommand = subprocess.Popen([cmakeCommand, "-E", "server", "--experimental"],
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE)