Пример #1
0
    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"])
Пример #2
0
    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
Пример #3
0
    shutil.rmtree(buildDir)

proc = cmakelib.initProc(cmakeCommand)

with open(testFile) as f:
    testData = json.loads(f.read())

for obj in testData:
    if 'sendRaw' in obj:
        data = obj['sendRaw']
        if debug: print("Sending raw:", data)
        cmakelib.writeRawData(proc, data)
    elif 'send' in obj:
        data = obj['send']
        if debug: print("Sending:", json.dumps(data))
        cmakelib.writePayload(proc, data)
    elif 'recv' in obj:
        data = obj['recv']
        if debug: print("Waiting for:", json.dumps(data))
        cmakelib.waitForMessage(proc, data)
    elif 'reply' in obj:
        data = obj['reply']
        if debug: print("Waiting for reply:", json.dumps(data))
        originalType = ""
        cookie = ""
        skipProgress = False;
        if 'cookie' in data: cookie = data['cookie']
        if 'type' in data: originalType = data['type']
        if 'skipProgress' in data: skipProgress = data['skipProgress']
        cmakelib.waitForReply(proc, originalType, cookie, skipProgress)
    elif 'error' in obj:
Пример #4
0
    shutil.rmtree(buildDir)

proc = cmakelib.initProc(cmakeCommand)

with open(testFile) as f:
    testData = json.loads(f.read())

for obj in testData:
    if 'sendRaw' in obj:
        data = obj['sendRaw']
        if debug: print("Sending raw:", data)
        cmakelib.writeRawData(proc, data)
    elif 'send' in obj:
        data = obj['send']
        if debug: print("Sending:", json.dumps(data))
        cmakelib.writePayload(proc, data)
    elif 'recv' in obj:
        data = obj['recv']
        if debug: print("Waiting for:", json.dumps(data))
        cmakelib.waitForMessage(proc, data)
    elif 'reply' in obj:
        data = obj['reply']
        if debug: print("Waiting for reply:", json.dumps(data))
        originalType = ""
        cookie = ""
        skipProgress = False
        if 'cookie' in data: cookie = data['cookie']
        if 'type' in data: originalType = data['type']
        if 'skipProgress' in data: skipProgress = data['skipProgress']
        cmakelib.waitForReply(proc, originalType, cookie, skipProgress)
    elif 'error' in obj:
Пример #5
0
    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)