def upgrade_java(self):
        cocos.Logging.info("Upgrading the java files...")
        proj_java_dirs = ["src", "org", "cocos2dx", "lib"]
        engine_java_dirs = ["cocos", "platform", "android", "java", "src", "org", "cocos2dx", "lib"]
        proj_java_path = self.android_proj_dir
        for dir in proj_java_dirs:
            proj_java_path = os.path.join(proj_java_path, dir)

        engine_java_path = os.path.join(self.get_frameworks_path(), self.target_version)
        for dir in engine_java_dirs:
            engine_java_path = os.path.join(engine_java_path, dir)

        if not os.path.exists(proj_java_path):
            cocos.Logging.warning("Java file path %s is not existed." % proj_java_path)
            return

        if not os.path.exists(engine_java_path):
            cocos.Logging.warning("Java file path %s is not existed." % engine_java_path)
            return

        try:
            shutil.rmtree(proj_java_path)
            cpy_cfg = {"from": engine_java_path, "to": proj_java_path, "include": ["*.java"]}
            cocos.copy_files_with_config(cpy_cfg, engine_java_path, proj_java_path)
        except Exception as e:
            cocos.Logging.warning("Replace the java files failed : %s" % e)
            cocos.Logging.warning(
                "Please replace the java files from %s to %s manually." % (engine_java_path, proj_java_path)
            )
    def upgrade_scripts(self):
        cocos.Logging.info("Upgrading the script files...")
        if self.proj_obj._is_lua_project():
            proj_script_path = os.path.join(self.proj_dir, "src/cocos")
            engine_script_path = os.path.join(
                self.get_frameworks_path(), self.target_version, "cocos/scripting/lua-bindings/script"
            )
            rule = "*.lua"
        else:
            proj_script_path = os.path.join(self.proj_dir, "script")
            engine_script_path = os.path.join(
                self.get_frameworks_path(), self.target_version, "cocos/scripting/js-bindings/script"
            )
            rule = "*.js"

        if not os.path.exists(proj_script_path):
            cocos.Logging.warning("Script file path %s is not existed." % proj_script_path)
            return

        if not os.path.exists(engine_script_path):
            cocos.Logging.warning("Script file path %s is not existed." % engine_script_path)
            return

        try:
            shutil.rmtree(proj_script_path)
            cpy_cfg = {"from": engine_script_path, "to": proj_script_path, "include": [rule]}
            cocos.copy_files_with_config(cpy_cfg, engine_script_path, proj_script_path)
        except Exception as e:
            cocos.Logging.warning("Replace the java files failed : %s" % e)
            cocos.Logging.warning(
                "Please replace the java files from %s to %s manually." % (engine_script_path, proj_script_path)
            )
Exemple #3
0
    def _copy_resources(self, custom_step_args, assets_dir):
        app_android_root = self.app_android_root
        res_files = self.res_files

        # remove app_android_root/assets if it exists
        if os.path.isdir(assets_dir):
            shutil.rmtree(assets_dir)

        # generate parameters for custom steps
        target_platform = cocos_project.Platforms.ANDROID
        cur_custom_step_args = custom_step_args.copy()
        cur_custom_step_args["assets-dir"] = assets_dir

        # make dir
        os.mkdir(assets_dir)

        # invoke custom step : pre copy assets
        self._project.invoke_custom_step_script(
            cocos_project.Project.CUSTOM_STEP_PRE_COPY_ASSETS, target_platform,
            cur_custom_step_args)

        # copy resources
        for cfg in res_files:
            cocos.copy_files_with_config(cfg, app_android_root, assets_dir)

        # invoke custom step : post copy assets
        self._project.invoke_custom_step_script(
            cocos_project.Project.CUSTOM_STEP_POST_COPY_ASSETS,
            target_platform, cur_custom_step_args)
    def _copy_resources(self, custom_step_args):
        app_android_root = self.app_android_root
        res_files = self.res_files

        # remove app_android_root/assets if it exists
        assets_dir = os.path.join(app_android_root, "assets")
        if os.path.isdir(assets_dir):
            shutil.rmtree(assets_dir)

        # generate parameters for custom steps
        target_platform = cocos_project.Platforms.ANDROID
        cur_custom_step_args = custom_step_args.copy()
        cur_custom_step_args["assets-dir"] = assets_dir

        # make dir
        os.mkdir(assets_dir)
 
        # invoke custom step : pre copy assets
        self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_PRE_COPY_ASSETS, target_platform, cur_custom_step_args)

        # copy resources
        for cfg in res_files:
            cocos.copy_files_with_config(cfg, app_android_root, assets_dir)

        # invoke custom step : post copy assets
        self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_POST_COPY_ASSETS, target_platform, cur_custom_step_args)
    def upgrade_full_project(self):
        proj_dir = self.proj_dir
        proj_par_dir, proj_dir_name = os.path.split(proj_dir)
        proj_name = self.proj_name
        proj_lang = self.proj_lang
        package_name = "com.cocos.%s.%s" % (proj_lang, proj_name)

        shutil.rmtree(proj_dir)
        cmd = self.console_dir + "cocos new %s -l %s -p %s -d %s" % (proj_name, proj_lang, package_name, proj_par_dir)
        if proj_lang != "cpp":
            cmd += " -t runtime"
        ecode = run_shell(cmd)
        if ecode:
            raise cocos.CCPluginError("Failed to create new project!")

        if not os.path.exists(proj_dir):
            new_proj_dir = os.path.join(proj_par_dir, proj_name)
            if not os.path.exists(new_proj_dir):
                raise cocos.CCPluginError("Failed to create new project!")
            cpy_cfg = {"from": new_proj_dir, "to": proj_dir}
            cocos.copy_files_with_config(cpy_cfg, new_proj_dir, proj_dir)
            shutil.rmtree(new_proj_dir)

        # copy the backup folder to project folder
        cpy_cfg = {"from": self.backup_proj_path, "to": proj_dir}
        cocos.copy_files_with_config(cpy_cfg, self.backup_proj_path, proj_dir)
        cocos.Logging.warning("Upgrad project finished!")
Exemple #6
0
    def copy_template(self):
        for item in self.config_json[TemplateGenerator.KEY_COPY_FROM_ENGINE]:
            cocos.copy_files_with_config(item, self.engine_path,
                                         self.engine_template_dir)

        for item in self.config_json[TemplateGenerator.KEY_COPY_FROM_BIN_TEMP]:
            cocos.copy_files_with_config(
                item, os.path.join(self.cur_dir, 'bin-templates'),
                self.engine_template_dir)
    def roll_back(self):
        cocos.Logging.warning("Rolling back...")
        # remove the project (it's broken)
        if os.path.exists(self.proj_dir):
            shutil.rmtree(self.proj_dir)

        # copy the backup folder to project folder
        cpy_cfg = {"from": self.backup_proj_path, "to": self.proj_dir}
        cocos.copy_files_with_config(cpy_cfg, self.backup_proj_path, self.proj_dir)
        cocos.Logging.warning("Rolling back finished!")
Exemple #8
0
    def cp_self(self, project_dir, exclude_files):
        cocos.Logging.info(MultiLanguage.get_string('NEW_INFO_STEP_COPY_TEMPLATE_FMT', project_dir))

        if not os.path.exists(self.project_dir):
            os.makedirs(self.project_dir)

        copy_cfg = {
            "from": self.tp_dir,
            "to": self.project_dir,
            "exclude": exclude_files
        }
        cocos.copy_files_with_config(copy_cfg, self.tp_dir, self.project_dir)
Exemple #9
0
    def cp_self(self, project_dir, exclude_files):
        cocos.Logging.info('> Copy template into %s' % project_dir)

        if not os.path.exists(self.project_dir):
            os.makedirs(self.project_dir)

        copy_cfg = {
            "from" : self.tp_dir,
            "to" : self.project_dir,
            "exclude" : exclude_files
        }
        cocos.copy_files_with_config(copy_cfg, self.tp_dir, self.project_dir)
    def _copy_resources(self):
        app_android_root = self.app_android_root
        res_files = self.res_files

        # remove app_android_root/assets if it exists
        assets_dir = os.path.join(app_android_root, "assets")
        if os.path.isdir(assets_dir):
            shutil.rmtree(assets_dir)

        # copy resources
        os.mkdir(assets_dir)
        for cfg in res_files:
            cocos.copy_files_with_config(cfg, app_android_root, assets_dir)
    def _copy_resources(self, dst_path):
        data = self._get_build_cfg()

        if data.has_key(CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES):
            if self._no_res:
                fileList = data[CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES]
            else:
                fileList = data[CCPluginCompile.CFG_KEY_COPY_RESOURCES] + data[
                    CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES]
        else:
            fileList = data[CCPluginCompile.CFG_KEY_COPY_RESOURCES]

        for cfg in fileList:
            cocos.copy_files_with_config(cfg, self._build_cfg_path(), dst_path)
    def backup_project(self):
        self.backup_proj_path = os.path.join(self.backup_dir, self.backup_name)
        if os.path.exists(self.backup_proj_path):
            self.backup_name = "%s-%s" % (self.backup_name, self.get_current_time())
            self.backup_proj_path = os.path.join(self.backup_dir, self.backup_name)

        if not self.no_backup:
            cocos.Logging.info("Backup the project %s to %s" % (self.proj_dir, self.backup_proj_path))

        cpy_cfg = {
            "from": self.proj_dir,
            "to": self.backup_proj_path,
            "exclude": [
                "proj.ios_mac/build",
                "proj.android/bin",
                "proj.android/assets",
                "proj.android/gen",
                "proj.android/obj",
                "proj.win32/[Dd]ebug.win32",
                "proj.win32/[Rr]elease.win32",
            ],
        }
        cocos.copy_files_with_config(cpy_cfg, self.proj_dir, self.backup_proj_path)
 def append_dir(self, v):
     cocos.Logging.info(
         MultiLanguage.get_string('NEW_INFO_STEP_APPEND_DIR'))
     for item in v:
         cocos.copy_files_with_config(item, self.cocos_root,
                                      self.project_dir)
 def append_from_template(self, v):
     cocos.Logging.info(
         MultiLanguage.get_string('NEW_INFO_STEP_APPEND_TEMPLATE'))
     cocos.copy_files_with_config(v, self.tp_dir, self.project_dir)
Exemple #15
0
 def append_dir(self, v):
     cocos.Logging.info(MultiLanguage.get_string('NEW_INFO_STEP_APPEND_DIR'))
     for item in v:
         cocos.copy_files_with_config(
             item, self.cocos_root, self.project_dir)
Exemple #16
0
 def append_from_template(self, v):
     cocos.Logging.info(MultiLanguage.get_string('NEW_INFO_STEP_APPEND_TEMPLATE'))
     cocos.copy_files_with_config(v, self.tp_dir, self.project_dir)
    def build_web(self):
        if not self._platforms.is_web_active():
            return

        project_dir = self._platforms.project_path()

        # store env for run
        cfg_obj = self._platforms.get_current_config()
        if cfg_obj.run_root_dir is not None:
            self.run_root = cfg_obj.run_root_dir
        else:
            self.run_root = project_dir

        if cfg_obj.sub_url is not None:
            self.sub_url = cfg_obj.sub_url
        else:
            self.sub_url = '/'

        output_dir = CCPluginCompile.OUTPUT_DIR_SCRIPT_RELEASE
        if self._is_debug_mode():
            output_dir = CCPluginCompile.OUTPUT_DIR_SCRIPT_DEBUG
            if not self._web_advanced:
                return

        self.sub_url = '%s%s/%s/' % (self.sub_url, output_dir,
                                     CCPluginCompile.WEB_PLATFORM_FOLDER_NAME)

        f = open(os.path.join(project_dir, "project.json"))
        project_json = json.load(f)
        f.close()
        engine_dir = os.path.join(project_json["engineDir"])
        realEngineDir = os.path.normpath(os.path.join(project_dir, engine_dir))
        publish_dir = os.path.normpath(
            os.path.join(project_dir, output_dir,
                         CCPluginCompile.WEB_PLATFORM_FOLDER_NAME))

        # need to config in options of command
        buildOpt = {
            "outputFileName": "game.min.js",
            "debug": "true" if self._is_debug_mode() else "false",
            "compilationLevel": "advanced" if self._web_advanced else "simple",
            "sourceMapOpened": True if self._has_sourcemap else False
        }

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

        # generate build.xml
        build_web.gen_buildxml(project_dir, project_json, publish_dir,
                               buildOpt)

        outputJsPath = os.path.join(publish_dir, buildOpt["outputFileName"])
        if os.path.exists(outputJsPath) == True:
            os.remove(outputJsPath)

        # call closure compiler
        ant_root = cocos.check_environment_variable('ANT_ROOT')
        ant_path = os.path.join(ant_root, 'ant')
        self._run_cmd("%s -f %s" %
                      (ant_path, os.path.join(publish_dir, 'build.xml')))

        # handle sourceMap
        sourceMapPath = os.path.join(publish_dir, "sourcemap")
        if os.path.exists(sourceMapPath):
            smFile = open(sourceMapPath)
            try:
                smContent = smFile.read()
            finally:
                smFile.close()

            dir_to_replace = project_dir
            if cocos.os_is_win32():
                dir_to_replace = project_dir.replace('\\', '\\\\')
            smContent = smContent.replace(
                dir_to_replace, os.path.relpath(project_dir, publish_dir))
            smContent = smContent.replace(
                realEngineDir, os.path.relpath(realEngineDir, publish_dir))
            smContent = smContent.replace('\\\\', '/')
            smContent = smContent.replace('\\', '/')
            smFile = open(sourceMapPath, "w")
            smFile.write(smContent)
            smFile.close()

        # handle project.json
        del project_json["engineDir"]
        del project_json["modules"]
        del project_json["jsList"]
        project_json_output_file = open(
            os.path.join(publish_dir, "project.json"), "w")
        project_json_output_file.write(json.dumps(project_json))
        project_json_output_file.close()

        # handle index.html
        indexHtmlFile = open(os.path.join(project_dir, "index.html"))
        try:
            indexContent = indexHtmlFile.read()
        finally:
            indexHtmlFile.close()
        reg1 = re.compile(
            r'<script\s+src\s*=\s*("|\')[^"\']*CCBoot\.js("|\')\s*><\/script>')
        indexContent = reg1.sub("", indexContent)
        mainJs = project_json.get("main") or "main.js"
        indexContent = indexContent.replace(mainJs, buildOpt["outputFileName"])
        indexHtmlOutputFile = open(os.path.join(publish_dir, "index.html"),
                                   "w")
        indexHtmlOutputFile.write(indexContent)
        indexHtmlOutputFile.close()

        # copy res dir
        if cfg_obj.copy_res is None:
            dst_dir = os.path.join(publish_dir, 'res')
            src_dir = os.path.join(project_dir, 'res')
            if os.path.exists(dst_dir):
                shutil.rmtree(dst_dir)
            shutil.copytree(src_dir, dst_dir)
        else:
            for cfg in cfg_obj.copy_res:
                cocos.copy_files_with_config(cfg, project_dir, publish_dir)

        # copy to the output directory if necessary
        pub_dir = os.path.normcase(publish_dir)
        out_dir = os.path.normcase(os.path.normpath(self._output_dir))
        if pub_dir != out_dir:
            cpy_cfg = {"from": pub_dir, "to": out_dir}
            cocos.copy_files_with_config(cpy_cfg, pub_dir, out_dir)
    def build_win32(self):
        if not self._platforms.is_win32_active():
            return

        if not cocos.os_is_win32():
            raise cocos.CCPluginError("Please build on winodws")

        win32_projectdir = self._platforms.project_path()
        output_dir = self._output_dir

        cocos.Logging.info("building")

        # get the solution file & project name
        cfg_obj = self._platforms.get_current_config()
        if cfg_obj.sln_file is not None:
            sln_name = cfg_obj.sln_file
            if cfg_obj.project_name is None:
                raise cocos.CCPluginError("Must specified \"%s\" when \"%s\" is specified in file \"%s\"") % \
                      (cocos_project.Win32Config.KEY_PROJECT_NAME, cocos_project.Win32Config.KEY_SLN_FILE, cocos_project.Project.CONFIG)
            else:
                name = cfg_obj.project_name
        else:
            name, sln_name = self.checkFileByExtention(".sln",
                                                       win32_projectdir)
            if not sln_name:
                message = "Can't find the \".sln\" file"
                raise cocos.CCPluginError(message)

        self.project_name = name
        projectPath = os.path.join(win32_projectdir, sln_name)

        # get the required VS version
        build_cfg_path = self._build_cfg_path()
        required_vs_version = self._get_required_vs_version(projectPath)
        if required_vs_version is None:
            raise cocos.CCPluginError(
                "Can't parse the sln file to find required VS version")

        cocos.Logging.info("Required VS version : %s" % required_vs_version)

        # get the correct available VS path
        needUpgrade, vsPath = self._get_vs_path(required_vs_version)

        if vsPath is None:
            message = "Can't find correct Visual Studio's path in the regedit"
            raise cocos.CCPluginError(message)

        cocos.Logging.info("Find VS path : %s" % vsPath)

        commandPath = os.path.join(vsPath, "Common7", "IDE", "devenv")
        build_mode = 'Debug' if self._is_debug_mode() else 'Release'

        # upgrade projects
        if needUpgrade:
            commandUpgrade = ' '.join(
                ["\"%s\"" % commandPath,
                 "\"%s\"" % projectPath, "/Upgrade"])
            self._run_cmd(commandUpgrade)

        # build the project
        commands = ' '.join([
            "\"%s\"" % commandPath,
            "\"%s\"" % projectPath,
            "/Build \"%s|Win32\"" % build_mode,
            "/Project \"%s\"" % self.project_name
        ])

        self._run_cmd(commands)

        cocos.Logging.info("build succeeded.")

        # copy files
        build_folder_name = "%s.win32" % build_mode
        build_folder_path = os.path.join(win32_projectdir, build_folder_name)
        if not os.path.isdir(build_folder_path):
            message = "Can not find the %s" % build_folder_path
            raise cocos.CCPluginError(message)

        # remove the files in output dir (keep the exe files)
        if os.path.exists(output_dir):
            output_files = os.listdir(output_dir)
            for element in output_files:
                ele_full_path = os.path.join(output_dir, element)
                if os.path.isfile(ele_full_path):
                    base_name, file_ext = os.path.splitext(element)
                    if not file_ext == ".exe":
                        os.remove(ele_full_path)
                elif os.path.isdir(ele_full_path):
                    shutil.rmtree(ele_full_path)

        # create output dir if it not existed
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        # copy dll & exe
        files = os.listdir(build_folder_path)
        for filename in files:
            name, ext = os.path.splitext(filename)
            proj_exe_name = "%s.exe" % self.project_name
            if ext == '.dll' or filename == proj_exe_name:
                file_path = os.path.join(build_folder_path, filename)
                cocos.Logging.info("Copying %s" % filename)
                shutil.copy(file_path, output_dir)

        # copy lua files & res
        build_cfg = os.path.join(build_cfg_path,
                                 CCPluginCompile.BUILD_CONFIG_FILE)
        if not os.path.exists(build_cfg):
            message = "%s not found" % build_cfg
            raise cocos.CCPluginError(message)
        f = open(build_cfg)
        data = json.load(f)

        if data.has_key(CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES):
            if self._no_res:
                fileList = data[CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES]
            else:
                fileList = data[CCPluginCompile.CFG_KEY_COPY_RESOURCES] + data[
                    CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES]
        else:
            fileList = data[CCPluginCompile.CFG_KEY_COPY_RESOURCES]

        for cfg in fileList:
            cocos.copy_files_with_config(cfg, build_cfg_path, output_dir)

        # check the project config & compile the script files
        self.compile_scripts(output_dir, output_dir)

        self.run_root = output_dir
    def build_win32(self):
        if not self._platforms.is_win32_active():
            return

        if not cocos.os_is_win32():
            raise cocos.CCPluginError("Please build on winodws")

        win32_projectdir = self._platforms.project_path()
        output_dir = self._output_dir

        cocos.Logging.info("building")

        # get the solution file & project name
        cfg_obj = self._platforms.get_current_config()
        if cfg_obj.sln_file is not None:
            sln_name = cfg_obj.sln_file
            if cfg_obj.project_name is None:
                raise cocos.CCPluginError("Must specified \"%s\" when \"%s\" is specified in file \"%s\"") % \
                      (cocos_project.Win32Config.KEY_PROJECT_NAME, cocos_project.Win32Config.KEY_SLN_FILE, cocos_project.Project.CONFIG)
            else:
                name = cfg_obj.project_name
        else:
            name, sln_name = self.checkFileByExtention(".sln", win32_projectdir)
            if not sln_name:
                message = "Can't find the \".sln\" file"
                raise cocos.CCPluginError(message)

        self.project_name = name
        projectPath = os.path.join(win32_projectdir, sln_name)

        # get the required VS version
        build_cfg_path = self._build_cfg_path()
        required_vs_version = self._get_required_vs_version(projectPath)
        if required_vs_version is None:
            raise cocos.CCPluginError("Can't parse the sln file to find required VS version")

        cocos.Logging.info("Required VS version : %s" % required_vs_version)

        # get the correct available VS path
        needUpgrade, vsPath = self._get_vs_path(required_vs_version)

        if vsPath is None:
            message = "Can't find correct Visual Studio's path in the regedit"
            raise cocos.CCPluginError(message)

        cocos.Logging.info("Find VS path : %s" % vsPath)

        commandPath = os.path.join(vsPath, "Common7", "IDE", "devenv")
        build_mode = 'Debug' if self._is_debug_mode() else 'Release'

        # upgrade projects
        if needUpgrade:
            commandUpgrade = ' '.join([
                "\"%s\"" % commandPath,
                "\"%s\"" % projectPath,
                "/Upgrade"
            ])
            self._run_cmd(commandUpgrade)

        # build the project
        commands = ' '.join([
            "\"%s\"" % commandPath,
            "\"%s\"" % projectPath,
            "/Build \"%s|Win32\"" % build_mode,
            "/Project \"%s\"" % self.project_name
        ])

        self._run_cmd(commands)

        cocos.Logging.info("build succeeded.")
        
        # copy files
        build_folder_name = "%s.win32" % build_mode
        build_folder_path = os.path.join(win32_projectdir, build_folder_name)
        if not os.path.isdir(build_folder_path):
            message = "Can not find the %s" % build_folder_path
            raise cocos.CCPluginError(message)

        # remove the files in output dir (keep the exe files)
        if os.path.exists(output_dir):
            output_files = os.listdir(output_dir)
            for element in output_files:
                ele_full_path = os.path.join(output_dir, element)
                if os.path.isfile(ele_full_path):
                    base_name, file_ext = os.path.splitext(element)
                    if not file_ext == ".exe":
                        os.remove(ele_full_path)
                elif os.path.isdir(ele_full_path):
                    shutil.rmtree(ele_full_path)

        # create output dir if it not existed
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        # copy dll & exe
        files = os.listdir(build_folder_path)
        for filename in files:
            name, ext = os.path.splitext(filename)
            proj_exe_name = "%s.exe" % self.project_name
            if ext == '.dll' or filename == proj_exe_name:
                file_path = os.path.join(build_folder_path, filename)
                cocos.Logging.info("Copying %s" % filename)
                shutil.copy(file_path, output_dir)

        # copy lua files & res
        build_cfg = os.path.join(build_cfg_path, CCPluginCompile.BUILD_CONFIG_FILE)
        if not os.path.exists(build_cfg):
            message = "%s not found" % build_cfg
            raise cocos.CCPluginError(message)
        f = open(build_cfg)
        data = json.load(f)

        if data.has_key(CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES):
            if self._no_res:
                fileList = data[CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES]
            else:
                fileList = data[CCPluginCompile.CFG_KEY_COPY_RESOURCES] + data[CCPluginCompile.CFG_KEY_MUST_COPY_RESOURCES]
        else:
            fileList = data[CCPluginCompile.CFG_KEY_COPY_RESOURCES]

        for cfg in fileList:
            cocos.copy_files_with_config(cfg, build_cfg_path, output_dir)

        # check the project config & compile the script files
        self.compile_scripts(output_dir, output_dir)

        self.run_root = output_dir
Exemple #20
0
    def compile_android(self):
        # build .so for android
        CONSOLE_PATH = "tools/cocos2d-console/bin"
        ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"

        android_out_dir = os.path.join(self.lib_dir, "android")
        engine_dir = self.repo_x
        console_dir = os.path.join(engine_dir, CONSOLE_PATH)
        if cocos.os_is_win32():
            cmd_path = os.path.join(console_dir, "cocos.bat")
        else:
            cmd_path = os.path.join(console_dir, "cocos")

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tools/simulator')
        build_cmd = "%s compile -s %s -p android --ndk-mode %s --app-abi %s" % (
            cmd_path, proj_path, self.mode, self.app_abi)

        env_param = ExtendEnv.get_extend_env_str()
        if env_param and len(env_param) > 0:
            build_cmd += (' --env "%s"' % env_param)
        self._run_cmd(build_cmd)

        # copy .a to prebuilt dir
        obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
        copy_cfg = {
            "from": obj_dir,
            "to": android_out_dir,
            "include": ["*.a$"]
        }
        cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = cocos.check_environment_variable("NDK_ROOT")
            if cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = ["", "-x86_64"]
                else:
                    check_bits = ["-x86_64", ""]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(
                        ndk_root,
                        "toolchains/arm-linux-androideabi-4.8/prebuilt/%s" %
                        check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if cocos.os_is_win32():
                strip_execute_name = "strip.exe"
            else:
                strip_execute_name = "strip"

            # strip arm libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/arm-linux-androideabi-4.8/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                armlibs = ["armeabi", "armeabi-v7a"]
                for fold in armlibs:
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, fold))

            # strip x86 libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/x86-4.8/prebuilt/%s/i686-linux-android/bin/%s" %
                (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path) and os.path.exists(
                    os.path.join(android_out_dir, "x86")):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, 'x86'))
Exemple #21
0
    def compile_android(self):
        # build .so for android
        CONSOLE_PATH = "tools/cocos2d-console/bin"
        ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"

        android_out_dir = os.path.join(self.lib_dir, "android")
        engine_dir = self.repo_x
        console_dir = os.path.join(engine_dir, CONSOLE_PATH)
        if cocos.os_is_win32():
            cmd_path = os.path.join(console_dir, "cocos.bat")
        else:
            cmd_path = os.path.join(console_dir, "cocos")

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tools/simulator')
        build_cmd = "%s compile -s %s -p android --ndk-mode %s --app-abi %s" % (cmd_path, proj_path, self.mode, self.app_abi)
        if self.android_platform is not None:
            build_cmd += ' --ap %s' % self.android_platform
        self._run_cmd(build_cmd)

        # copy .a to prebuilt dir
        obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
        copy_cfg = {
            "from": obj_dir,
            "to": android_out_dir,
            "include": [
                "*.a$"
            ]
        }
        cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = os.environ["NDK_ROOT"]
            if cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = [ "", "-x86_64" ]
                else:
                    check_bits = [ "-x86_64", "" ]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(ndk_root, "toolchains/arm-linux-androideabi-4.8/prebuilt/%s" % check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if cocos.os_is_win32():
                strip_execute_name = "strip.exe"
            else:
                strip_execute_name = "strip"

            # strip arm libs
            strip_cmd_path = os.path.join(ndk_root, "toolchains/arm-linux-androideabi-4.8/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                armlibs = ["armeabi", "armeabi-v7a"]
                for fold in armlibs:
                    self.trip_libs(strip_cmd_path, os.path.join(android_out_dir, fold))

            # strip arm64-v8a libs
            strip_cmd_path = os.path.join(ndk_root, "toolchains/aarch64-linux-android-4.9/prebuilt/%s/aarch64-linux-android/bin/%s" % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path) and os.path.exists(os.path.join(android_out_dir, "arm64-v8a")):
                self.trip_libs(strip_cmd_path, os.path.join(android_out_dir, 'arm64-v8a'))

            # strip x86 libs
            strip_cmd_path = os.path.join(ndk_root, "toolchains/x86-4.8/prebuilt/%s/i686-linux-android/bin/%s" % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path) and os.path.exists(os.path.join(android_out_dir, "x86")):
                self.trip_libs(strip_cmd_path, os.path.join(android_out_dir, 'x86'))
Exemple #22
0
 def append_dir(self, v):
     cocos.Logging.info('> Copying directory from cocos root directory...')
     for item in v:
         cocos.copy_files_with_config(item, self.cocos_root, self.project_dir)
Exemple #23
0
    def copy_template(self):
        for item in self.config_json[TemplateGenerator.KEY_COPY_FROM_ENGINE]:
            cocos.copy_files_with_config(item, self.engine_path, self.engine_template_dir)

        for item in self.config_json[TemplateGenerator.KEY_COPY_FROM_BIN_TEMP]:
            cocos.copy_files_with_config(item, os.path.join(self.cur_dir, 'bin-templates'), self.engine_template_dir)
Exemple #24
0
    def compile_android(self):
        # build .so for android
        CONSOLE_PATH = "tools/cocos2d-console/bin"
        ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"
        if self.use_studio is not None:
            ANDROID_A_PATH = "frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/" + self.mode + "/obj/local"

        android_out_dir = os.path.join(self.lib_dir, "android")
        engine_dir = self.repo_x
        console_dir = os.path.join(engine_dir, CONSOLE_PATH)
        cocos_py_path = os.path.join(console_dir, 'cocos.py')

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tools/simulator')
        python_path = cocos.check_environment_variable('COCOS_PYTHON_HOME',
                                                       raise_error=False)
        if python_path is None:
            python_path = 'python'
        else:
            python_path = os.path.join(python_path, 'python')
        build_cmd = "\"%s\" \"%s\" compile -s %s -p android --ndk-mode %s --app-abi %s -m %s" % (
            python_path, cocos_py_path, proj_path, self.mode, self.app_abi,
            self.mode)
        if self.android_platform is not None:
            build_cmd += ' --ap %s' % self.android_platform
        if self.use_studio is not None:
            build_cmd += ' --android-studio'

        env_param = ExtendEnv.get_extend_env_str()
        if env_param and len(env_param) > 0:
            build_cmd += (' --env "%s"' % env_param)
        self._run_cmd(build_cmd)

        # copy .a to prebuilt dir
        obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
        copy_cfg = {
            "from": obj_dir,
            "to": android_out_dir,
            "include": ["*.a$"]
        }
        cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = cocos.check_environment_variable("NDK_ROOT")
            if cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = ["", "-x86_64"]
                else:
                    check_bits = ["-x86_64", ""]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(
                        ndk_root,
                        "toolchains/arm-linux-androideabi-4.9/prebuilt/%s" %
                        check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if cocos.os_is_win32():
                strip_execute_name = "strip.exe"
            else:
                strip_execute_name = "strip"

            # strip arm libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/arm-linux-androideabi-4.9/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                armlibs = ["armeabi", "armeabi-v7a"]
                for fold in armlibs:
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, fold))
            else:
                raise Exception("(%s) wasn't found." % strip_cmd_path)

            # strip arm64-v8a libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/aarch64-linux-android-4.9/prebuilt/%s/aarch64-linux-android/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                if os.path.exists(os.path.join(android_out_dir, "arm64-v8a")):
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, 'arm64-v8a'))
            else:
                raise Exception("(%s) wasn't found." % strip_cmd_path)

            # strip x86 libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/x86-4.9/prebuilt/%s/i686-linux-android/bin/%s" %
                (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                if os.path.exists(os.path.join(android_out_dir, "x86")):
                    self.trip_libs(strip_cmd_path,
                                   os.path.join(android_out_dir, 'x86'))
            else:
                raise Exception("(%s) wasn't found." % strip_cmd_path)
Exemple #25
0
    def compile_android(self):
        # build .so for android
        cmd_path = self._get_cocos_cmd_path()
        engine_dir = self.repo_x

        # build the simulator project
        proj_path = os.path.join(engine_dir, 'tests/cpp-empty-test')
        if self.language == 'lua':
            proj_path = os.path.join(engine_dir, 'tests/lua-empty-test')
        elif self.language == 'js':
            proj_path = os.path.join(engine_dir, 'tests/js-tests')

        build_cmd = "%s compile -s %s -p android --ndk-mode %s --app-abi %s" % (
            cmd_path, proj_path, self.mode, self.app_abi)
        if self.android_platform is not None:
            build_cmd += ' --ap %s' % self.android_platform
        self._run_cmd(build_cmd)

        # copy .a to prebuilt dir
        ANDROID_A_PATH = "proj.android/app/build/intermediates/ndkBuild/%s/obj/local/%s" % (
            self.mode, self.app_abi)
        if self.language != 'cpp':
            ANDROID_A_PATH = 'project/' + ANDROID_A_PATH

        android_out_dir = os.path.join(self.lib_dir, "android")
        obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
        copy_cfg = {
            "from": obj_dir,
            "to": android_out_dir,
            "include": ["*.a$"]
        }
        cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)

        if not self.disable_strip:
            # strip the android libs
            ndk_root = os.environ["NDK_ROOT"]
            if cocos.os_is_win32():
                if cocos.os_is_32bit_windows():
                    check_bits = ["", "-x86_64"]
                else:
                    check_bits = ["-x86_64", ""]

                sys_folder_name = "windows"
                for bit_str in check_bits:
                    check_folder_name = "windows%s" % bit_str
                    check_path = os.path.join(
                        ndk_root,
                        "toolchains/arm-linux-androideabi-4.9/prebuilt/%s" %
                        check_folder_name)
                    if os.path.isdir(check_path):
                        sys_folder_name = check_folder_name
                        break
            elif cocos.os_is_mac():
                sys_folder_name = "darwin-x86_64"
            else:
                sys_folder_name = "linux-x86_64"

            # set strip execute file name
            if cocos.os_is_win32():
                strip_execute_name = "strip.exe"
            else:
                strip_execute_name = "strip"

            # strip arm libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/arm-linux-androideabi-4.9/prebuilt/%s/arm-linux-androideabi/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, "armeabi-v7a"))

            # strip arm64-v8a libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/aarch64-linux-android-4.9/prebuilt/%s/aarch64-linux-android/bin/%s"
                % (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path) and os.path.exists(
                    os.path.join(android_out_dir, "arm64-v8a")):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, 'arm64-v8a'))

            # strip x86 libs
            strip_cmd_path = os.path.join(
                ndk_root,
                "toolchains/x86-4.8/prebuilt/%s/i686-linux-android/bin/%s" %
                (sys_folder_name, strip_execute_name))
            if os.path.exists(strip_cmd_path) and os.path.exists(
                    os.path.join(android_out_dir, "x86")):
                self.trip_libs(strip_cmd_path,
                               os.path.join(android_out_dir, 'x86'))
Exemple #26
0
 def append_from_template(self, v):
     cocos.Logging.info('> Copying files from template directory...')
     cocos.copy_files_with_config(v, self.tp_dir, self.project_dir)