예제 #1
0
    def build_android(self):
        if not self._platforms.is_android_active():
            return
        if not self._ap:
            cocos.Logging.info(
                'Android platform not specified, searching a default one...')
            self._ap = cocos.select_default_android_platform()
            if self._ap is None:
                cocos.Logging.warning(
                    'No valid android platform found, will not generate apk.')

        project_dir = self._platforms.project_path()

        # for debug reason, depart 2 step here:
        # 1. build native 2. build apk
        # only build native code if -p not specified, otherwise build apk also.
        cocos.Logging.info("building native")
        with cocos.pushd(project_dir):
            self._run_cmd("python build_native.py -b %s -n \"-j %s\"" %
                          (self._mode, self._jobs))

        cocos.Logging.info("building apk")
        with cocos.pushd(project_dir):
            self._run_cmd("python build_native.py -b %s -p %s -n \"-j %s\"" %
                          (self._mode, self._ap, self._jobs))
예제 #2
0
    def build_linux(self):
        if not self._platforms.is_linux_active():
            return

        #if not cocos.os_is_linux():
        #    raise cocos.CCPluginError("Please build on linux")

        project_dir = self._project.get_project_dir()
        cfg_obj = self._platforms.get_current_config()
        if cfg_obj.cmake_path is not None:
            cmakefile_dir = os.path.join(project_dir, cfg_obj.cmake_path)
        else:
            cmakefile_dir = project_dir
            if self._project._is_lua_project():
                cmakefile_dir = os.path.join(project_dir, 'frameworks')

        # get the project name
        if cfg_obj.project_name is not None:
            self.project_name = cfg_obj.project_name
        else:
            f = open(os.path.join(cmakefile_dir, 'CMakeLists.txt'), 'r')
            for line in f.readlines():
                if "set(APP_NAME " in line:
                    self.project_name = re.search('APP_NAME ([^\)]+)\)', line).group(1)
                    break

        if cfg_obj.build_dir is not None:
            build_dir = os.path.join(project_dir, cfg_obj.build_dir)
        else:
            build_dir = os.path.join(project_dir, 'linux-build')

        if not os.path.exists(build_dir):
            os.makedirs(build_dir)

        with cocos.pushd(build_dir):
            self._run_cmd('cmake %s' % os.path.relpath(cmakefile_dir, build_dir))

        with cocos.pushd(build_dir):
            self._run_cmd('make -j%s' % self._jobs)

        # move file
        output_dir = self._output_dir

        if os.path.exists(output_dir):
            shutil.rmtree(output_dir)
        os.makedirs(output_dir)

        if cfg_obj.build_result_dir is not None:
            result_dir = os.path.join(build_dir, 'bin', cfg_obj.build_result_dir)
        else:
            result_dir = os.path.join(build_dir, 'bin')
        cocos.copy_files_in_dir(result_dir, output_dir)

        self.run_root = output_dir

        if self._no_res:
            res_dir = os.path.join(output_dir, "Resources")
            self._remove_res(res_dir)

        cocos.Logging.info('Build successed!')
예제 #3
0
    def build_linux(self):
        if not self._platforms.is_linux_active():
            return

        #if not cocos.os_is_linux():
        #    raise cocos.CCPluginError("Please build on linux")

        project_dir = self._project.get_project_dir()
        cmakefile_dir = project_dir
        if self._project._is_lua_project():
            cmakefile_dir = os.path.join(project_dir, 'frameworks')

        # get the project name
        f = open(os.path.join(cmakefile_dir, 'CMakeLists.txt'), 'r')
        for line in f.readlines():
            if "set(APP_NAME " in line:
                self.project_name = re.search('APP_NAME ([^\)]+)\)', line).group(1)
                break
        
        build_dir = os.path.join(project_dir, 'build')
        if not os.path.exists(build_dir):
            os.makedirs(build_dir)

        with cocos.pushd(build_dir):
            self._run_cmd('cmake %s' % os.path.relpath(cmakefile_dir, build_dir))

        with cocos.pushd(build_dir):
            self._run_cmd('make')

        # move file
        build_mode = self._mode
        if self._project._is_script_project():
            if build_mode == 'debug':
                output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_DEBUG, 'linux')
            else:
                output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_RELEASE, 'linux')
        else:
            output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_NATIVE, build_mode, 'linux')

        if os.path.exists(output_dir):
            shutil.rmtree(output_dir)
        os.makedirs(output_dir)
       
        copy_files_in_dir(os.path.join(build_dir, 'bin'), output_dir)

        self.run_root = output_dir

        if self._no_res:
            linux_proj_path = self._platforms.project_path()
            res_dir = os.path.join(output_dir, "Resources")
            self._remove_res(linux_proj_path, res_dir)

        cocos.Logging.info('Build successed!')
예제 #4
0
    def build_android(self):
        if not self._platforms.is_android_active():
            return
        project_dir = self._platforms.project_path()

        # for debug reason, depart 2 step here:
        # 1. build native 2. build apk
        # only build native code if -p not specified, otherwise build apk also.
        cocos.Logging.info("building native")
        with cocos.pushd(project_dir):
            self._run_cmd('python build_native.py -b %s -n "-j %s"' % (self._mode, self._jobs))

        cocos.Logging.info("building apk")
        with cocos.pushd(project_dir):
            self._run_cmd('python build_native.py -b %s -p %s -n "-j %s"' % (self._mode, self._ap, self._jobs))
예제 #5
0
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler
        HandlerClass = SimpleHTTPRequestHandler
        ServerClass = BaseHTTPServer.HTTPServer
        Protocol = "HTTP/1.0"

        port = int(self._port)
        server_address = ('127.0.0.1', port)

        HandlerClass.protocol_version = Protocol
        httpd = ServerClass(server_address, HandlerClass)

        sa = httpd.socket.getsockname()

        from threading import Thread
        deploy_dep = dependencies['deploy']
        sub_url = deploy_dep.sub_url
        url = 'http://127.0.0.1:%s%s' % (port, sub_url)
        thread = Thread(target=open_webbrowser, args=(url, ))
        thread.start()

        run_root = deploy_dep.run_root
        with cocos.pushd(run_root):
            cocos.Logging.info("Serving HTTP on %s, port %s ..." %
                               (sa[0], sa[1]))
            httpd.serve_forever()
예제 #6
0
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler
        HandlerClass = SimpleHTTPRequestHandler
        ServerClass  = BaseHTTPServer.HTTPServer
        Protocol     = "HTTP/1.0"
        
        host = self._host
        port = int(self._port)
        deploy_dep = dependencies['deploy']
        server_address = (host, port)

        from threading import Thread
        sub_url = deploy_dep.sub_url
        url = 'http://%s:%s%s' % (host, port, sub_url)
        thread = Thread(target = self.open_webbrowser, args = (url,))
        thread.start()

        try:
            HandlerClass.protocol_version = Protocol
            httpd = ServerClass(server_address, HandlerClass)

            sa = httpd.socket.getsockname()

            run_root = deploy_dep.run_root
            with cocos.pushd(run_root):
                cocos.Logging.info("Serving HTTP on %s, port %s ..." % (sa[0], sa[1]))
                httpd.serve_forever()
        except Exception as e:
            cocos.Logging.warning("Start server error ({0}): {1}".format(e.errno, e.strerror))
예제 #7
0
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler
        HandlerClass = SimpleHTTPRequestHandler
        ServerClass = BaseHTTPServer.HTTPServer
        Protocol = "HTTP/1.0"

        host = self._host
        port = int(self._port)
        deploy_dep = dependencies['deploy']
        server_address = (host, port)

        from threading import Thread
        sub_url = deploy_dep.sub_url
        url = 'http://%s:%s%s' % (host, port, sub_url)
        thread = Thread(target=self.open_webbrowser, args=(url, ))
        thread.start()

        try:
            HandlerClass.protocol_version = Protocol
            httpd = ServerClass(server_address, HandlerClass)

            sa = httpd.socket.getsockname()

            run_root = deploy_dep.run_root
            with cocos.pushd(run_root):
                cocos.Logging.info("Serving HTTP on %s, port %s ..." %
                                   (sa[0], sa[1]))
                httpd.serve_forever()
        except Exception as e:
            cocos.Logging.warning("Start server error ({0}): {1}".format(
                e.errno, e.strerror))
예제 #8
0
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler
        HandlerClass = SimpleHTTPRequestHandler
        ServerClass  = BaseHTTPServer.HTTPServer
        Protocol     = "HTTP/1.0"

        port = int(self._port)
        server_address = ('127.0.0.1', port)

        HandlerClass.protocol_version = Protocol
        httpd = ServerClass(server_address, HandlerClass)

        sa = httpd.socket.getsockname()

        from threading import Thread
        deploy_dep = dependencies['deploy']
        sub_url = deploy_dep.sub_url
        url = 'http://127.0.0.1:%s%s' % (port, sub_url)
        thread = Thread(target = open_webbrowser, args = (url,))
        thread.start()

        run_root = deploy_dep.run_root
        with cocos.pushd(run_root):
            cocos.Logging.info("Serving HTTP on %s, port %s ..." % (sa[0], sa[1]))
            httpd.serve_forever()
예제 #9
0
    def compile_lua(self, lua_file, output_file):
        """
        Compiles lua file
        """
        cocos.Logging.debug("compiling lua (%s) to bytecode..." % lua_file)

        with cocos.pushd(self._luajit_dir):
            self._run_cmd(self._luajit_exe_path + " -b " + lua_file+ " " + output_file)
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler
        HandlerClass = SimpleHTTPRequestHandler
        ServerClass = BaseHTTPServer.HTTPServer
        Protocol = "HTTP/1.0"
        HandlerClass.protocol_version = Protocol

        host = self._host
        if self._port is None:
            port = 8000
            port_max_add = 2000
        else:
            port = int(self._port)
            port_max_add = 0

        deploy_dep = dependencies['deploy']
        run_root = deploy_dep.run_root

        i = 0
        httpd = None
        while (i <= port_max_add):
            port += i
            i += 1
            server_address = (host, port)
            try:
                cocos.Logging.info(
                    MultiLanguage.get_string('RUN_INFO_HOST_PORT_FMT',
                                             (host, port)))
                httpd = ServerClass(server_address, HandlerClass)
            except Exception as e:
                httpd = None
                cocos.Logging.warning(
                    MultiLanguage.get_string('RUN_WARNING_SERVER_FAILED_FMT',
                                             (host, port, e)))

            if httpd is not None:
                break

        if httpd is None:
            raise cocos.CCPluginError(
                MultiLanguage.get_string('RUN_ERROR_START_SERVER_FAILED'),
                cocos.CCPluginError.ERROR_OTHERS)

        from threading import Thread
        sub_url = deploy_dep.sub_url
        url = 'http://%s:%s%s' % (host, port, sub_url)
        thread = Thread(target=self.open_webbrowser, args=(url, ))
        thread.start()

        sa = httpd.socket.getsockname()
        with cocos.pushd(run_root):
            cocos.Logging.info(
                MultiLanguage.get_string('RUN_INFO_SERVING_FMT',
                                         (sa[0], sa[1])))
            httpd.serve_forever()
예제 #11
0
    def run_win32(self, dependencies):
        if not self._platforms.is_win32_active():
            return

        deploy_dep = dependencies['deploy']
        run_root = deploy_dep.run_root
        exe = deploy_dep.project_name
        with cocos.pushd(run_root):
            self._run_with_desktop_options(os.path.join(run_root, exe))
예제 #12
0
    def compile_lua(self, lua_file, output_file):
        """
        Compiles lua file
        """
        cocos.Logging.debug(MultiLanguage.get_string("LUACOMPILE_DEBUG_COMPILE_FILE_FMT", lua_file))

        with cocos.pushd(self._luajit_dir):
            cmd_str = '"%s" -b "%s" "%s"' % (self._luajit_exe_path, lua_file, output_file)
            self._run_cmd(cmd_str)
예제 #13
0
    def compile_lua(self, lua_file, output_file):
        """
        Compiles lua file
        """
        cocos.Logging.debug("compiling lua (%s) to bytecode..." % lua_file)

        with cocos.pushd(self._luajit_dir):
            cmd_str = "\"%s\" -b \"%s\" \"%s\"" % (self._luajit_exe_path, lua_file, output_file)
            self._run_cmd(cmd_str)
예제 #14
0
    def run_linux(self, dependencies):
        if not self._platforms.is_linux_active():
            return

        deploy_dep = dependencies["deploy"]
        run_root = deploy_dep.run_root
        exe = deploy_dep.project_name
        with cocos.pushd(run_root):
            self._run_cmd(os.path.join(run_root, exe))
    def compile_lua(self, lua_file, output_file):
        """
        Compiles lua file
        """
        cocos.Logging.debug("compiling lua (%s) to bytecode..." % lua_file)

        with cocos.pushd(self._luajit_dir):
            cmd_str = "\"%s\" -b \"%s\" \"%s\"" % (self._luajit_exe_path, lua_file, output_file)
            self._run_cmd(cmd_str)
예제 #16
0
    def compile_lua(self, lua_file, output_file):
        """
        Compiles lua file
        """
        cocos.Logging.debug(cocos.MultiLanguage.get_string('LUACOMPILE_DEBUG_COMPILE_FILE_FMT') % lua_file)

        with cocos.pushd(self._luajit_dir):
            cmd_str = "\"%s\" -b \"%s\" \"%s\"" % (self._luajit_exe_path, lua_file, output_file)
            self._run_cmd(cmd_str)
예제 #17
0
    def compile_lua(self, lua_file, output_file):
        """
        Compiles lua file
        """
        cocos.Logging.debug(cocos.MultiLanguage.get_string('LUACOMPILE_DEBUG_COMPILE_FILE_FMT') % lua_file)

        with cocos.pushd(self._luajit_dir):
            cmd_str = "\"%s\" -b \"%s\" \"%s\"" % (self._luajit_exe_path, lua_file, output_file)
            self._run_cmd(cmd_str)
    def run_linux(self, dependencies):
        if not self._platforms.is_linux_active():
            return

        deploy_dep = dependencies['deploy']
        run_root = deploy_dep.run_root
        exe = deploy_dep.project_name
        with cocos.pushd(run_root):
            self._run_with_desktop_options(os.path.join(run_root, exe))
예제 #19
0
    def run_win32(self, dependencies):
        if not self._platforms.is_win32_active():
            return

        deploy_dep = dependencies['deploy']
        run_root = deploy_dep.run_root
        exe = deploy_dep.project_name
        with cocos.pushd(run_root):
            self._run_cmd(os.path.join(run_root, exe))
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler
        HandlerClass = SimpleHTTPRequestHandler
        ServerClass = BaseHTTPServer.HTTPServer
        Protocol = "HTTP/1.0"
        HandlerClass.protocol_version = Protocol

        host = self._host
        if self._port is None:
            port = 8000
            port_max_add = 2000
        else:
            port = int(self._port)
            port_max_add = 0

        deploy_dep = dependencies['deploy']
        run_root = deploy_dep.run_root

        i = 0
        httpd = None
        while (i <= port_max_add):
            port += i
            i += 1
            server_address = (host, port)
            try:
                cocos.Logging.info("Try start server on {0}:{1}".format(
                    host, port))
                httpd = ServerClass(server_address, HandlerClass)
            except Exception as e:
                httpd = None
                cocos.Logging.warning(
                    "Start server {0}:{1} error : {2}".format(host, port, e))

            if httpd is not None:
                break

        if httpd is None:
            raise cocos.CCPluginError("Start server failed.")

        from threading import Thread
        sub_url = deploy_dep.sub_url
        url = 'http://%s:%s%s' % (host, port, sub_url)
        thread = Thread(target=self.open_webbrowser, args=(url, ))
        thread.start()

        sa = httpd.socket.getsockname()
        with cocos.pushd(run_root):
            cocos.Logging.info("Serving HTTP on %s, port %s ..." %
                               (sa[0], sa[1]))
            httpd.serve_forever()
예제 #21
0
    def build_android(self):
        if not self._platforms.is_android_active():
            return
        if not self._ap:
            cocos.Logging.info('Android platform not specified, searching a default one...')
            self._ap = cocos.select_default_android_platform()
            if self._ap is None:
                 cocos.Logging.warning('No valid android platform found, will not generate apk.')

        project_dir = self._platforms.project_path()

        # for debug reason, depart 2 step here:
        # 1. build native 2. build apk
        # only build native code if -p not specified, otherwise build apk also.
        cocos.Logging.info("building native")
        with cocos.pushd(project_dir):
            self._run_cmd("python build_native.py -b %s -n \"-j %s\"" % (self._mode, self._jobs))

        cocos.Logging.info("building apk")
        with cocos.pushd(project_dir):
            self._run_cmd("python build_native.py -b %s -p %s -n \"-j %s\"" % (self._mode, self._ap, self._jobs))
예제 #22
0
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler

        HandlerClass = SimpleHTTPRequestHandler
        ServerClass = BaseHTTPServer.HTTPServer
        Protocol = "HTTP/1.0"
        HandlerClass.protocol_version = Protocol

        host = self._host
        if self._port is None:
            port = 8000
            port_max_add = 2000
        else:
            port = int(self._port)
            port_max_add = 0

        deploy_dep = dependencies["deploy"]
        run_root = deploy_dep.run_root

        i = 0
        httpd = None
        while i <= port_max_add:
            port += i
            i += 1
            server_address = (host, port)
            try:
                cocos.Logging.info("Try start server on {0}:{1}".format(host, port))
                httpd = ServerClass(server_address, HandlerClass)
            except Exception as e:
                httpd = None
                cocos.Logging.warning("Start server {0}:{1} error : {2}".format(host, port, e))

            if httpd is not None:
                break

        if httpd is None:
            raise cocos.CCPluginError("Start server failed.")

        from threading import Thread

        sub_url = deploy_dep.sub_url
        url = "http://%s:%s%s" % (host, port, sub_url)
        thread = Thread(target=self.open_webbrowser, args=(url,))
        thread.start()

        sa = httpd.socket.getsockname()
        with cocos.pushd(run_root):
            cocos.Logging.info("Serving HTTP on %s, port %s ..." % (sa[0], sa[1]))
            httpd.serve_forever()
예제 #23
0
    def run_web(self, dependencies):
        if not self._platforms.is_web_active():
            return

        from SimpleHTTPServer import SimpleHTTPRequestHandler

        HandlerClass = SimpleHTTPRequestHandler
        ServerClass = BaseHTTPServer.HTTPServer
        Protocol = "HTTP/1.0"
        HandlerClass.protocol_version = Protocol

        host = self._host
        if self._port is None:
            port = 8000
            port_max_add = 2000
        else:
            port = int(self._port)
            port_max_add = 0

        deploy_dep = dependencies["deploy"]
        run_root = deploy_dep.run_root

        i = 0
        httpd = None
        while i <= port_max_add:
            port += i
            i += 1
            server_address = (host, port)
            try:
                cocos.Logging.info(cocos.MultiLanguage.get_string("RUN_INFO_HOST_PORT_FMT") % (host, port))
                httpd = ServerClass(server_address, HandlerClass)
            except Exception as e:
                httpd = None
                cocos.Logging.warning(cocos.MultiLanguage.get_string("RUN_WARNING_SERVER_FAILED_FMT") % (host, port, e))

            if httpd is not None:
                break

        if httpd is None:
            raise cocos.CCPluginError(cocos.MultiLanguage.get_string("RUN_ERROR_START_SERVER_FAILED"))

        from threading import Thread

        sub_url = deploy_dep.sub_url
        url = "http://%s:%s%s" % (host, port, sub_url)
        thread = Thread(target=self.open_webbrowser, args=(url,))
        thread.start()

        sa = httpd.socket.getsockname()
        with cocos.pushd(run_root):
            cocos.Logging.info(cocos.MultiLanguage.get_string("RUN_INFO_SERVING_FMT") % (sa[0], sa[1]))
            httpd.serve_forever()
    def build_linux(self):
        if not self._platforms.is_linux_active():
            return

        #if not cocos.os_is_linux():
        #    raise cocos.CCPluginError("Please build on linux")

        project_dir = self._project.get_project_dir()
        cmakefile_dir = project_dir
        if self._project._is_lua_project():
            cmakefile_dir = os.path.join(project_dir, 'frameworks')

        # get the project name
        f = open(os.path.join(cmakefile_dir, 'CMakeLists.txt'), 'r')
        for line in f.readlines():
            if "set(APP_NAME " in line:
                self.project_name = re.search('APP_NAME ([^\)]+)\)',
                                              line).group(1)
                break

        build_dir = os.path.join(project_dir, 'build')
        if not os.path.exists(build_dir):
            os.makedirs(build_dir)

        with cocos.pushd(build_dir):
            self._run_cmd('cmake %s' %
                          os.path.relpath(cmakefile_dir, build_dir))

        with cocos.pushd(build_dir):
            self._run_cmd('make')

        # move file
        build_mode = self._mode
        if self._project._is_script_project():
            if build_mode == 'debug':
                output_dir = os.path.join(
                    project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_DEBUG,
                    'linux')
            else:
                output_dir = os.path.join(
                    project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_RELEASE,
                    'linux')
        else:
            output_dir = os.path.join(project_dir,
                                      CCPluginCompile.OUTPUT_DIR_NATIVE,
                                      build_mode, 'linux')

        if os.path.exists(output_dir):
            shutil.rmtree(output_dir)
        os.makedirs(output_dir)

        copy_files_in_dir(os.path.join(build_dir, 'bin'), output_dir)

        self.run_root = output_dir

        if self._no_res:
            linux_proj_path = self._platforms.project_path()
            res_dir = os.path.join(output_dir, "Resources")
            self._remove_res(linux_proj_path, res_dir)

        cocos.Logging.info('Build successed!')
예제 #25
0
    def build_linux(self):
        if not self._platforms.is_linux_active():
            return

        #if not cocos.os_is_linux():
        #    raise cocos.CCPluginError("Please build on linux")

        project_dir = self._project.get_project_dir()
        cfg_obj = self._platforms.get_current_config()
        if cfg_obj.cmake_path is not None:
            cmakefile_dir = os.path.join(project_dir, cfg_obj.cmake_path)
        else:
            cmakefile_dir = project_dir
            if self._project._is_lua_project():
                cmakefile_dir = os.path.join(project_dir, 'frameworks')

        # get the project name
        if cfg_obj.project_name is not None:
            self.project_name = cfg_obj.project_name
        else:
            f = open(os.path.join(cmakefile_dir, 'CMakeLists.txt'), 'r')
            for line in f.readlines():
                if "set(APP_NAME " in line:
                    self.project_name = re.search('APP_NAME ([^\)]+)\)',
                                                  line).group(1)
                    break

        if cfg_obj.build_dir is not None:
            build_dir = os.path.join(project_dir, cfg_obj.build_dir)
        else:
            build_dir = os.path.join(project_dir, 'linux-build')

        if not os.path.exists(build_dir):
            os.makedirs(build_dir)

        with cocos.pushd(build_dir):
            self._run_cmd('cmake %s' %
                          os.path.relpath(cmakefile_dir, build_dir))

        with cocos.pushd(build_dir):
            self._run_cmd('make -j%s' % self._jobs)

        # move file
        output_dir = self._output_dir

        if os.path.exists(output_dir):
            shutil.rmtree(output_dir)
        os.makedirs(output_dir)

        if cfg_obj.build_result_dir is not None:
            result_dir = os.path.join(build_dir, 'bin',
                                      cfg_obj.build_result_dir)
        else:
            result_dir = os.path.join(build_dir, 'bin')
        cocos.copy_files_in_dir(result_dir, output_dir)

        self.run_root = output_dir

        if self._no_res:
            res_dir = os.path.join(output_dir, "Resources")
            self._remove_res(res_dir)

        if self._project._is_script_project() and self._compile_script:
            cocos.Logging.warning(
                "Warning: Now script compiling is not supported for linux.")

        cocos.Logging.info('Build successed!')
    def build(self, platform):
        if self._platforms.is_android_active():
            self.build_android()
            return

        self.check_platform(platform)

        project_dir = self._project.get_project_dir()
        cfg_obj = self._platforms.get_current_config()
        if cfg_obj.cmake_path is not None:
            cmakefile_dir = os.path.join(project_dir, cfg_obj.cmake_path)
        else:
            cmakefile_dir = project_dir

        # get the project name
        if cfg_obj.project_name is not None:
            self.project_name = cfg_obj.project_name
        else:
            f = open(os.path.join(cmakefile_dir, 'CMakeLists.txt'), 'r')
            regexp_set_app_name = re.compile(r'\s*set\s*\(\s*APP_NAME',
                                             re.IGNORECASE)
            for line in f.readlines():
                if regexp_set_app_name.search(line):
                    self.project_name = re.search('APP_NAME ([^\)]+)\)', line,
                                                  re.IGNORECASE).group(1)
                    break
            if hasattr(self, 'project_name') == False:
                raise cocos.CCPluginError(
                    "Couldn't find APP_NAME in CMakeLists.txt")

        if cfg_obj.build_dir is not None:
            build_dir = os.path.join(project_dir, cfg_obj.build_dir)
        else:
            build_dir = os.path.join(project_dir, '%s-build' % platform)

        if not os.path.exists(build_dir):
            os.makedirs(build_dir)

        # compile codes
        build_mode = 'Debug' if self._is_debug_mode() else 'Release'
        with cocos.pushd(build_dir):
            # iOS need to generate Xcode project file first
            if platform == 'ios':
                engine_dir = self.get_engine_dir()
                self._run_cmd(
                    'cmake %s -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=%s'
                    %
                    (os.path.relpath(cmakefile_dir, build_dir), self._use_sdk))
            elif platform == 'mac':
                self._run_cmd('cmake -GXcode %s' %
                              os.path.relpath(cmakefile_dir, build_dir))
            elif platform == "win32":
                ret = utils.get_newest_devenv(self.vs_version)
                if ret is not None:
                    ver_num = int(float(ret[2]))
                    generator = self.CMAKE_VS_GENERATOR_MAP[str(ver_num)]
                    if generator is not None:
                        if ver_num >= 16:
                            # for vs2019 x64 is the default target
                            self._run_cmd(
                                'cmake %s -G "%s" -A win32' % (os.path.relpath(
                                    cmakefile_dir, build_dir), generator))
                        else:
                            self._run_cmd(
                                'cmake %s -G "%s"' % (os.path.relpath(
                                    cmakefile_dir, build_dir), generator))
                    else:
                        cocos.Logging.warning(
                            MultiLanguage.get_string(
                                "COMPILE_VS_VERSION_NOT_REGISTER") % (ret[2]))
                        self._run_cmd(
                            'cmake %s' %
                            os.path.relpath(cmakefile_dir, build_dir))
                else:
                    cocos.Logging.warning(
                        MultiLanguage.get_string("COMPILE_VS_VERSION"))
                    self._run_cmd('cmake %s' %
                                  os.path.relpath(cmakefile_dir, build_dir))
            else:
                self._run_cmd('cmake %s' %
                              os.path.relpath(cmakefile_dir, build_dir))

            self._run_cmd('cmake --build . --config %s' % build_mode)

        # move file
        output_dir = self._output_dir

        if os.path.exists(output_dir):
            shutil.rmtree(output_dir)
        os.makedirs(output_dir)

        if cfg_obj.build_result_dir is not None:
            result_dir = os.path.join(build_dir, 'bin',
                                      cfg_obj.build_result_dir,
                                      self.project_name)
        else:
            result_dir = os.path.join(build_dir, 'bin', self.project_name)

        if os.path.exists(os.path.join(result_dir, build_mode)):
            result_dir = os.path.join(result_dir, build_mode)

        cocos.copy_files_in_dir(result_dir, output_dir)

        self.run_root = output_dir

        # set application path and application name
        if platform == 'mac' or platform == 'ios':
            self.app_path = os.path.join(output_dir,
                                         self.project_name + '.app')
        else:
            self.app_path = output_dir

        self.app_name = self.project_name
        if platform == 'win32':
            self.app_name = self.app_name + '.exe'

        script_resource_path = os.path.join(self.app_path, 'src')
        if platform == 'mac':
            script_resource_path = os.path.join(self.app_path,
                                                'Contents/Resources/src')

        cocos.Logging.info(
            MultiLanguage.get_string('COMPILE_INFO_BUILD_SUCCEED'))