def open(self, sourceDirectory, buildDirectory, generatorName, extraGeneratorName="", extraEnv={}): self.sourceDirectory = sourceDirectory self.buildDirectory = buildDirectory self.proc = cmakelib.initServerProc(self.cmakeExecutable, cmakelib.communicationMethods[0], extraEnv) if self.proc is None: raise Exception("Failed starting cmake server") packet = cmakelib.waitForRawMessage(self.proc) if packet == None: raise Exception( "Unknown failure, maybe cmake does not support server mode") if packet['type'] != 'hello': raise Exception("No hello message received from server") self.protocolVersion = [ packet["supportedProtocolVersions"][0]["major"], packet["supportedProtocolVersions"][0]["minor"] ] self.logger.debug("Server Protocol version: %s", self.protocolVersion) sourceDirectory = sourceDirectory.replace('\\', '/') buildDirectory = buildDirectory.replace('\\', '/') cmakelib.writePayload( self.proc, { 'type': 'handshake', 'protocolVersion': { 'major': self.protocolVersion[0], 'minor': self.protocolVersion[1] }, 'cookie': 'OPEN_HANDSHAKE', 'sourceDirectory': sourceDirectory, 'buildDirectory': buildDirectory, 'generator': generatorName, 'extraGenerator': extraGeneratorName }) reply = cmakelib.waitForReply(self.proc, 'handshake', 'OPEN_HANDSHAKE', False) cmakelib.writePayload(self.proc, {"type": "globalSettings"}) packet = cmakelib.waitForReply(self.proc, 'globalSettings', '', False) self.globalSettings = packet self.sourceDirectory = sourceDirectory self.logger.debug( "VERSION: %s" % self.globalSettings["capabilities"]["version"]["string"])
def configure(self, extraArguments=[]): self.logger.info("Configuring ...") cmakelib.writePayload( self.proc, { "type": "configure", "cacheArguments": extraArguments, "cookie": "CONFIGURE" }) self.waitForResult("configure", "CONFIGURE") self.logger.info("Done.") self.logger.info("Generating ...") cmakelib.writePayload(self.proc, { "type": "compute", "cookie": "COMPUTE" }) self.waitForResult("compute", "COMPUTE") cmakelib.writePayload(self.proc, { "type": "codemodel", "cookie": "CODEMODEL" }) payload = cmakelib.waitForRawMessage(self.proc) if not payload or not "cookie" in payload or payload[ "cookie"] != "CODEMODEL": raise Exception( "Something went wrong trying to configure the project. ( Unexpected response from cmake during codemodel request: %s )" % (payload)) self.codeModel = payload
def waitForResult(self, expectedReply, expectedCookie): while 1: payload = cmakelib.waitForRawMessage(self.proc) if payload["inReplyTo"] != expectedReply or payload[ "cookie"] != expectedCookie: raise Exception("Invalid packet received") msgType = payload["type"] if msgType == 'reply': break elif msgType == 'message': print("--", payload["message"]) elif msgType == 'progress': pass elif msgType == 'error': raise Exception("Error occured during configure:", payload["errorMessage"]) else: raise Exception("Invalid response:", payload)
def configure(self, extraArguments=[]): self.logger.info("Configuring ...") cmakelib.writePayload( self.proc, { "type": "configure", "cacheArguments": extraArguments, "cookie": "CONFIGURE" }) self.waitForResult("configure", "CONFIGURE") self.logger.info("Done.") self.logger.info("Generating ...") cmakelib.writePayload(self.proc, { "type": "compute", "cookie": "COMPUTE" }) self.waitForResult("compute", "COMPUTE") cmakelib.writePayload(self.proc, { "type": "codemodel", "cookie": "CODEMODEL" }) payload = cmakelib.waitForRawMessage(self.proc) if not payload or not "cookie" in payload or payload[ "cookie"] != "CODEMODEL": raise Exception( "Something went wrong trying to configure the project. ( Unexpected response from cmake during codemodel request: %s )" % (payload)) self.codeModel = payload for cmakeConfig in self.codeModel['configurations']: for project in cmakeConfig['projects']: if project["sourceDirectory"] == self.sourceDirectory: cmakeConfig['main-project'] = project self.logger.debug("Main project for '%s' : %s" % (cmakeConfig['name'], project['name'])) cmakelib.writePayload(self.proc, {"type": "cache", "cookie": "CACHE"}) payload = cmakelib.waitForRawMessage(self.proc) if not payload or not "cookie" in payload or payload[ "cookie"] != "CACHE": raise Exception( "Something went wrong trying to configure the project. ( Unexpected response from cmake during cache request: %s )" % (payload)) #self.cache = payload self.cache = {} for entry in payload["cache"]: self.cache[entry["key"]] = entry["value"] if self.logger.isEnabledFor(logging.DEBUG): with open( os.path.join(self.sourceDirectory, 'codemodel.debug.json'), 'w') as outfile: json.dump(self.codeModel, outfile, indent=4, sort_keys=True) with open(os.path.join(self.sourceDirectory, 'cache.debug.json'), 'w') as outfile: json.dump(self.cache, outfile, indent=4, sort_keys=True)