示例#1
0
 def run(self, argv, dependencies):
     self.parse_args(argv)
     self.generate()
     Logging.info('')
     Logging.info(
         MultiLanguage.get_string('GEN_TEMP_SUCCESS_FMT',
                                  self.engine_template_dir))
示例#2
0
    def modify_binary_mk(self):
        android_libs = os.path.join(self.lib_dir, "android")
        android_mks = self.cfg_info[LibsCompiler.KEY_ANDROID_MKS]
        for mk_file in android_mks:
            mk_file_path = os.path.normpath(os.path.join(self.repo_x, mk_file))
            if not os.path.isfile(mk_file_path):
                Logging.warning(MultiLanguage.get_string('COMPILE_ERROR_GRALEW_NOT_EXIST_FMT', mk_file_path))
                continue

            dst_file_path = os.path.join(os.path.dirname(mk_file_path), "prebuilt-mk", os.path.basename(mk_file_path))
            tmp_obj = gen_prebuilt_mk.MKGenerator(mk_file_path, android_libs, dst_file_path)
            tmp_obj.do_generate()
示例#3
0
    def modify_binary_mk(self):
        android_libs = os.path.join(self.lib_dir, "android")
        android_mks = self.cfg_info[LibsCompiler.KEY_ANDROID_MKS]
        for mk_file in android_mks:
            mk_file_path = os.path.normpath(os.path.join(self.repo_x, mk_file))
            if not os.path.isfile(mk_file_path):
                Logging.warning(MultiLanguage.get_string('COMPILE_ERROR_GRALEW_NOT_EXIST_FMT', mk_file_path))
                continue

            dst_file_path = os.path.join(os.path.dirname(mk_file_path), "prebuilt-mk", os.path.basename(mk_file_path))
            tmp_obj = gen_prebuilt_mk.MKGenerator(mk_file_path, android_libs, dst_file_path)
            tmp_obj.do_generate()
示例#4
0
    def rollback_files(self, files):
        for f in files:
            full_path = os.path.abspath(f)
            backup_file_path = '%s.bak' % full_path
            if not os.path.isfile(backup_file_path):
                continue

            try:
                shutil.copyfile(backup_file_path, full_path)
                os.remove(backup_file_path)
            except:
                Logging.warning(MultiLanguage.get_string('GEN_SIM_ROLL_BACK_FAIL_FMT',
                                                         (full_path, backup_file_path, full_path)))
                pass
示例#5
0
    def run(self, argv, dependencies):
        self.parse_args(argv)
        if self.is_clean_before_build:
            utils.rmdir(self.simulator_output_dir)

        # backup some files
        modify_files = self.get_depend_project_file_list()
        if cocos.os_is_mac() and self.build_mac:
            modify_files.append(os.path.join(self.simulator_abs_path, 'frameworks/runtime-src/proj.ios_mac/mac/Info.plist'))

        if cocos.os_is_win32() and self.build_win:
            modify_files.append(os.path.join(self.simulator_abs_path, 'frameworks/runtime-src/proj.win32/game.rc'))

        self.backup_files(modify_files)

        try:
            # modify bundle version
            self.update_bundle_version()

            # modify project config files
            self.change_cocos2d_debug_macro_to_1(modify_files)

            # compile simulator
            self.do_compile()
        except Exception as e:
            raise e
        finally:
            # roll back modified files
            self.rollback_files(modify_files)
            Logging.info("")
            Logging.info(self.build_log)
            Logging.info("")

        return 0
示例#6
0
    def compile_win(self):
        if self.mode == 'debug':
            mode_str = 'Debug'
        else:
            mode_str = 'Release'

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[
            LibsCompiler.KEY_SUPPORT_VS_VERSIONS]
        compile_vs_versions = support_vs_versions
        if self.vs_version is not None:
            if self.vs_version not in support_vs_versions:
                raise CCPluginError(
                    MultiLanguage.get_string(
                        'GEN_LIBS_ERROR_NOT_SUPPORT_VS_FMT', self.vs_version),
                    CCPluginError.ERROR_WRONG_ARGS)
            else:
                compile_vs_versions = [self.vs_version]

        vs_cmd_info = {}
        for vs_version in compile_vs_versions:
            # get the vs command with specified version
            vs_command = utils.get_msbuild_path(vs_version)
            if vs_command is None:
                Logging.warning(
                    MultiLanguage.get_string(
                        'GEN_LIBS_WARNING_VS_NOT_FOUND_FMT', vs_version))
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CCPluginError(
                MultiLanguage.get_string('GEN_LIBS_ERROR_VS_NOT_FOUND'),
                CCPluginError.ERROR_TOOLS_NOT_FOUND)

        cocos2d_proj_file = os.path.join(self.repo_x,
                                         'cocos/2d/libcocos2d.vcxproj')

        # get the VS projects info
        win32_proj_info = self.cfg_info[LibsCompiler.KEY_VS_PROJS_INFO]
        proj_path = win32_proj_info['proj_path']
        for vs_version in compile_vs_versions:
            if not vs_version in vs_cmd_info.keys():
                continue

            try:
                vs_command = vs_cmd_info[vs_version]
                # clean solutions
                full_proj_path = os.path.join(self.repo_x, proj_path)
                clean_cmd = " ".join([
                    "\"%s\"" % vs_command,
                    "\"%s\"" % full_proj_path,
                    "/t:Clean /p:Configuration=%s" % mode_str
                ])
                self._run_cmd(clean_cmd)

                output_dir = os.path.join(self.lib_dir, "win32")

                # get the build folder & win32 output folder
                build_folder_path = os.path.join(os.path.dirname(proj_path),
                                                 "%s.win32" % mode_str)
                win32_output_dir = os.path.join(self.repo_x, output_dir)
                if not os.path.exists(win32_output_dir):
                    os.makedirs(win32_output_dir)

                # build project
                if self.use_incredibuild:
                    # use incredibuild, build whole sln
                    build_cmd = " ".join([
                        "BuildConsole",
                        "%s" % proj_path, "/build",
                        "/cfg=\"%s|Win32\"" % mode_str
                    ])
                    self._run_cmd(build_cmd)
                else:
                    for proj_name in win32_proj_info[self.language][
                            LibsCompiler.KEY_VS_BUILD_TARGETS]:
                        # build the projects
                        self.build_win32_proj(vs_command, proj_path, proj_name,
                                              mode_str)

                # copy the libs into prebuilt dir
                for file_name in os.listdir(build_folder_path):
                    name, ext = os.path.splitext(file_name)
                    if ext != ".lib" and ext != ".dll":
                        continue

                    file_path = os.path.join(build_folder_path, file_name)
                    shutil.copy(file_path, win32_output_dir)

            except Exception as e:
                raise e
示例#7
0
    def compile_win(self):
        if self.mode == 'debug':
            mode_str = 'Debug'
        else:
            mode_str = 'Release'

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[
            LibsCompiler.KEY_SUPPORT_VS_VERSIONS]
        compile_vs_versions = support_vs_versions
        if self.vs_version is not None:
            if self.vs_version not in support_vs_versions:
                raise CCPluginError(
                    MultiLanguage.get_string(
                        'GEN_LIBS_ERROR_NOT_SUPPORT_VS_FMT', self.vs_version),
                    CCPluginError.ERROR_WRONG_ARGS)
            else:
                compile_vs_versions = [self.vs_version]

        vs_cmd_info = {}
        for vs_version in compile_vs_versions:
            # get the vs command with specified version
            vs_command = utils.get_msbuild_path(vs_version)
            if vs_command is None:
                Logging.warning(
                    MultiLanguage.get_string(
                        'GEN_LIBS_WARNING_VS_NOT_FOUND_FMT', vs_version))
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CCPluginError(
                MultiLanguage.get_string('GEN_LIBS_ERROR_VS_NOT_FOUND'),
                CCPluginError.ERROR_TOOLS_NOT_FOUND)

        cocos2d_proj_file = os.path.join(self.repo_x,
                                         'cocos/2d/libcocos2d.vcxproj')

        # get the VS projects info
        win32_proj_info = self.cfg_info[LibsCompiler.KEY_VS_PROJS_INFO]
        for vs_version in compile_vs_versions:
            if not vs_version in vs_cmd_info.keys():
                continue

            # rename the cocos2d project out dll name
            f = open(cocos2d_proj_file, 'r')
            old_file_content = f.read()
            f.close()

            new_file_content = old_file_content.replace(
                '$(OutDir)$(ProjectName).dll',
                '$(OutDir)$(ProjectName)_%d.dll' % vs_version)
            f = open(cocos2d_proj_file, 'w')
            f.write(new_file_content)
            f.close()

            try:
                vs_command = vs_cmd_info[vs_version]
                for key in win32_proj_info.keys():
                    # clean solutions
                    proj_path = os.path.join(self.repo_x, key)
                    clean_cmd = " ".join([
                        "\"%s\"" % vs_command,
                        "\"%s\"" % proj_path,
                        "/t:Clean /p:Configuration=%s" % mode_str
                    ])
                    self._run_cmd(clean_cmd)

                for key in win32_proj_info.keys():
                    output_dir = os.path.join(self.lib_dir, "win32")
                    proj_path = os.path.join(self.repo_x, key)

                    # get the build folder & win32 output folder
                    build_folder_path = os.path.join(
                        os.path.dirname(proj_path), "%s.win32" % mode_str)
                    win32_output_dir = os.path.join(self.repo_x, output_dir)
                    if not os.path.exists(win32_output_dir):
                        os.makedirs(win32_output_dir)

                    # build project
                    if self.use_incredibuild:
                        # use incredibuild, build whole sln
                        build_cmd = " ".join([
                            "BuildConsole",
                            "%s" % proj_path, "/build",
                            "/cfg=\"%s|Win32\"" % mode_str
                        ])
                        self._run_cmd(build_cmd)
                    else:
                        for proj_name in win32_proj_info[key][
                                LibsCompiler.KEY_VS_BUILD_TARGETS]:
                            # build the projects
                            self.build_win32_proj(vs_command, proj_path,
                                                  proj_name, mode_str)

                    # copy the libs into prebuilt dir
                    for file_name in os.listdir(build_folder_path):
                        name, ext = os.path.splitext(file_name)
                        if ext != ".lib" and ext != ".dll":
                            continue

                        file_path = os.path.join(build_folder_path, file_name)
                        shutil.copy(file_path, win32_output_dir)

                    # rename the specified libs
                    suffix = "_%d" % vs_version
                    for proj_name in win32_proj_info[key][
                            LibsCompiler.KEY_VS_RENAME_TARGETS]:
                        src_name = os.path.join(win32_output_dir,
                                                "%s.lib" % proj_name)
                        dst_name = os.path.join(
                            win32_output_dir, "%s%s.lib" % (proj_name, suffix))
                        if not os.path.exists(src_name):
                            raise CCPluginError(
                                MultiLanguage.get_string(
                                    'GEN_LIBS_ERROR_LIB_NOT_GEN_FMT',
                                    src_name),
                                CCPluginError.ERROR_PATH_NOT_FOUND)

                        if os.path.exists(dst_name):
                            os.remove(dst_name)
                        os.rename(src_name, dst_name)
            except Exception as e:
                raise e
            finally:
                f = open(cocos2d_proj_file, 'w')
                f.write(old_file_content)
                f.close()
示例#8
0
    def compile_win(self):
        if self.mode == 'debug':
            mode_str = 'Debug'
        else:
            mode_str = 'Release'

        # get the VS versions will be used for compiling
        support_vs_versions = self.cfg_info[LibsCompiler.KEY_SUPPORT_VS_VERSIONS]
        compile_vs_versions = support_vs_versions
        if self.vs_version is not None:
            if self.vs_version not in support_vs_versions:
                raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_NOT_SUPPORT_VS_FMT', self.vs_version),
                                    CCPluginError.ERROR_WRONG_ARGS)
            else:
                compile_vs_versions = [ self.vs_version ]

        vs_cmd_info = {}
        for vs_version in compile_vs_versions:
            # get the vs command with specified version
            vs_command = utils.get_msbuild_path(vs_version)
            if vs_command is None:
                Logging.warning(MultiLanguage.get_string('GEN_LIBS_WARNING_VS_NOT_FOUND_FMT', vs_version))
            else:
                vs_cmd_info[vs_version] = vs_command

        if len(vs_cmd_info) == 0:
            raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_VS_NOT_FOUND'),
                                CCPluginError.ERROR_TOOLS_NOT_FOUND)

        cocos2d_proj_file = os.path.join(self.repo_x, 'cocos/2d/libcocos2d.vcxproj')

        # get the VS projects info
        win32_proj_info = self.cfg_info[LibsCompiler.KEY_VS_PROJS_INFO]
        for vs_version in compile_vs_versions:
            if not vs_version in vs_cmd_info.keys():
                continue

            # rename the cocos2d project out dll name
            f = open(cocos2d_proj_file, 'r')
            old_file_content = f.read()
            f.close()

            new_file_content = old_file_content.replace('$(OutDir)$(ProjectName).dll', '$(OutDir)$(ProjectName)_%d.dll' % vs_version)
            f = open(cocos2d_proj_file, 'w')
            f.write(new_file_content)
            f.close()

            try:
                vs_command = vs_cmd_info[vs_version]
                for key in win32_proj_info.keys():
                    # clean solutions
                    proj_path = os.path.join(self.repo_x, key)
                    clean_cmd = " ".join([
                        "\"%s\"" % vs_command,
                        "\"%s\"" % proj_path,
                        "/t:Clean /p:Configuration=%s" % mode_str
                    ])
                    self._run_cmd(clean_cmd)

                for key in win32_proj_info.keys():
                    output_dir = os.path.join(self.lib_dir, "win32")
                    proj_path = os.path.join(self.repo_x, key)

                    # get the build folder & win32 output folder
                    build_folder_path = os.path.join(os.path.dirname(proj_path), "%s.win32" % mode_str)
                    win32_output_dir = os.path.join(self.repo_x, output_dir)
                    if not os.path.exists(win32_output_dir):
                        os.makedirs(win32_output_dir)

                    # build project
                    if self.use_incredibuild:
                        # use incredibuild, build whole sln
                        build_cmd = " ".join([
                            "BuildConsole",
                            "%s" % proj_path,
                            "/build",
                            "/cfg=\"%s|Win32\"" % mode_str
                        ])
                        self._run_cmd(build_cmd)
                    else:
                        for proj_name in win32_proj_info[key][LibsCompiler.KEY_VS_BUILD_TARGETS]:
                            # build the projects
                            self.build_win32_proj(vs_command, proj_path, proj_name, mode_str)

                    # copy the libs into prebuilt dir
                    for file_name in os.listdir(build_folder_path):
                        name, ext = os.path.splitext(file_name)
                        if ext != ".lib" and ext != ".dll":
                            continue

                        file_path = os.path.join(build_folder_path, file_name)
                        shutil.copy(file_path, win32_output_dir)

                    # rename the specified libs
                    suffix = "_%d" % vs_version
                    for proj_name in win32_proj_info[key][LibsCompiler.KEY_VS_RENAME_TARGETS]:
                        src_name = os.path.join(win32_output_dir, "%s.lib" % proj_name)
                        dst_name = os.path.join(win32_output_dir, "%s%s.lib" % (proj_name, suffix))
                        if not os.path.exists(src_name):
                            raise CCPluginError(MultiLanguage.get_string('GEN_LIBS_ERROR_LIB_NOT_GEN_FMT', src_name),
                                                CCPluginError.ERROR_PATH_NOT_FOUND)

                        if os.path.exists(dst_name):
                            os.remove(dst_name)
                        os.rename(src_name, dst_name)
            except Exception as e:
                raise e
            finally:
                f = open(cocos2d_proj_file, 'w')
                f.write(old_file_content)
                f.close()
示例#9
0
    def modify_xcode_proj(self, proj_file_path):
        if proj_file_path.find('cpp-template') >= 0:
            language = 'cpp'
        elif proj_file_path.find('lua-template') >= 0:
            language = 'lua'
        elif proj_file_path.find('js-template') >= 0:
            language = 'js'
        else:
            Logging.warning(MultiLanguage.get_string('GEN_TEMP_UNKNOWN_LANGUAGE_FMT', proj_file_path))
            return

        import modify_pbxproj
        pbx_proj = modify_pbxproj.XcodeProject.Load(proj_file_path)

        replace_engine_strs = []
        if language == "cpp":
            targetName = "HelloCpp"
            link_libs = XCODE_LINK_CPP_LIBS
            replace_engine_strs.append("$(SRCROOT)/../cocos2d")
        elif language == "lua":
            targetName = "HelloLua"
            link_libs = XCODE_LINK_CPP_LIBS + XCODE_LINK_LUA_LIBS
            replace_engine_strs.append("$(SRCROOT)/../../cocos2d-x")
        else:
            targetName = "HelloJavascript"
            link_libs = XCODE_LINK_CPP_LIBS + XCODE_LINK_JS_LIBS
            replace_engine_strs.append("$(SRCROOT)/../../cocos2d-x")
            replace_engine_strs.append("../../cocos2d-x")
        ios_target_name = "%s-mobile" % targetName
        mac_target_name = "%s-desktop" % targetName

        # remove the target dependencies
        pbx_proj.remove_proj_reference("cocos2d_libs.xcodeproj")
        if language == "lua":
            pbx_proj.remove_proj_reference("cocos2d_lua_bindings.xcodeproj")
            pbx_proj.remove_proj_reference("libsimulator.xcodeproj")

        if language == "js":
            pbx_proj.remove_proj_reference("cocos2d_js_bindings.xcodeproj")
            pbx_proj.remove_proj_reference("libsimulator.xcodeproj")
            pbx_proj.remove_file_by_path("../../cocos2d-x/cocos/scripting/js-bindings/script")

            common_group = pbx_proj.get_or_create_group("JS Common")
            pbx_proj.add_file_if_doesnt_exist("../../../script", common_group, tree="<group>")
            # pbx_proj.remove_group_by_name("JS Common")

        # add libraries search path
        libs_path = "/Applications/Cocos/Cocos2d-x/%s/prebuilt" % self.version
        ios_template_prebuilt_path = "%s/%s" % (libs_path, "ios")
        pbx_proj.add_library_search_paths(ios_template_prebuilt_path, target_name=ios_target_name, recursive=False)
        mac_template_prebuilt_path = "%s/%s" % (libs_path, "mac")
        pbx_proj.add_library_search_paths(mac_template_prebuilt_path, target_name=mac_target_name, recursive=False)

        # add libraries for targets
        ios_lib_group = pbx_proj.get_or_create_group("ios-libs")
        mac_lib_group = pbx_proj.get_or_create_group("mac-libs")
        for lib in link_libs:
            ios_lib_name = "%s iOS.a" % lib
            mac_lib_name = "%s Mac.a" % lib
            ios_lib_path = "%s/%s" % (ios_template_prebuilt_path, ios_lib_name)
            pbx_proj.add_file_if_doesnt_exist(ios_lib_path, ios_lib_group, tree="<group>", target=ios_target_name)

            mac_lib_path = "%s/%s" % (mac_template_prebuilt_path, mac_lib_name)
            pbx_proj.add_file_if_doesnt_exist(mac_lib_path, mac_lib_group, tree="<group>", target=mac_target_name)

        # add studio resources to the xcode project of cpp template
        if language == "cpp":
            pbx_proj.remove_file_by_path("CloseNormal.png")
            pbx_proj.remove_file_by_path("CloseSelected.png")
            pbx_proj.remove_file_by_path("HelloWorld.png")
            pbx_proj.remove_file_by_path("Marker Felt.ttf")
            pbx_proj.remove_file_by_path("fonts")
            pbx_proj.remove_file_by_path("res")

            res_group = pbx_proj.get_or_create_group("Resources")
            pbx_proj.add_file_if_doesnt_exist("../Resources/res", res_group, tree="<group>")

        if pbx_proj.modified:
            Logging.info(MultiLanguage.get_string('GEN_TEMP_SAVE_XCODE_PROJ_FMT', proj_file_path))
            pbx_proj.save()

        # modify the engine path
        f = open(proj_file_path)
        file_content = f.read()
        f.close()

        install_path = "/Applications/Cocos/Cocos2d-x/%s" % self.version
        for old_engine_path in replace_engine_strs:
            file_content = file_content.replace(old_engine_path, install_path)

        f = open(proj_file_path, "w")
        f.write(file_content)
        f.close()
示例#10
0
    def modify_vs_proj(self, proj_file_path):
        if proj_file_path.find('cpp-template') >= 0:
            language = 'cpp'
        elif proj_file_path.find('lua-template') >= 0:
            language = 'lua'
        elif proj_file_path.find('js-template') >= 0:
            language = 'js'
        else:
            Logging.warning(MultiLanguage.get_string('GEN_TEMP_UNKNOWN_LANGUAGE_FMT', proj_file_path))
            return

        import modify_vcxproj
        vcx_proj = modify_vcxproj.VCXProject(proj_file_path)

        # remove the project references
        vcx_proj.remove_proj_reference()

        install_path = "$(COCOS_X_ROOT)\\%s\\" % self.version

        copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \
                        "xcopy /Y /Q \"$(EngineRoot)\\prebuilt\\win32\\*.*\" \"$(OutDir)\"\n"
        vcx_proj.set_event_command('PreLinkEvent', copy_libs_cmd, 'debug')
        vcx_proj.set_event_command('PreLinkEvent', copy_libs_cmd, 'release')

        if language == "js":
            custom_step_event = vcx_proj.get_event_command('CustomBuildStep')
            custom_step_event.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script",
                                      "$(ProjectDir)..\\..\\..\\script")
            vcx_proj.set_event_command("CustomBuildStep", custom_step_event, create_new=False)

        vcx_proj.remove_predefine_macro("_DEBUG", 'debug')

        Logging.info(MultiLanguage.get_string('GEN_TEMP_SAVE_VS_PROJ_FMT', proj_file_path))
        vcx_proj.save()

        replace_strs = []
        replace_strs.append("$(EngineRoot)")
        if language == "cpp":
            # link_libs = WIN32_LINK_CPP_LIBS
            replace_strs.append("$(ProjectDir)..\\cocos2d")
            replace_strs.append("..\\cocos2d")
        elif language == "lua":
            # link_libs = WIN32_LINK_CPP_LIBS + WIN32_LINK_LUA_LIBS
            replace_strs.append("$(ProjectDir)..\\..\\cocos2d-x")
            replace_strs.append("..\\..\\cocos2d-x")
        else:
            # link_libs = WIN32_LINK_CPP_LIBS + WIN32_LINK_JS_LIBS
            replace_strs.append("$(ProjectDir)..\\..\\cocos2d-x")
            replace_strs.append("..\\..\\cocos2d-x")

        # modify the Runtime.cpp
        vcx_proj_path = os.path.dirname(proj_file_path)
        cpp_path = os.path.join(vcx_proj_path, os.path.pardir, "Classes/runtime/Runtime.cpp")
        if os.path.exists(cpp_path):
            f = open(cpp_path)
            file_content = f.read()
            f.close()

            file_content = file_content.replace("#ifndef _DEBUG", "#ifndef COCOS2D_DEBUG")
            f = open(cpp_path, "w")
            f.write(file_content)
            f.close()

        f = open(proj_file_path)
        file_content = f.read()
        f.close()

        if language == "lua":
            # replace the "lua\lua;" to "lua\luajit;"
            file_content = file_content.replace("lua\\lua;", "lua\\luajit\\include;")

        file_content = file_content.replace("MultiThreadedDebugDLL", "MultiThreadedDLL")
        for str in replace_strs:
            file_content = file_content.replace(str, install_path)
        file_content = file_content.replace('%s\\' % install_path, install_path)

        file_content = file_content.replace("%scocos\\2d\\cocos2dx.props" % install_path, "cocos2dx.props")
        
        f = open(proj_file_path, "w")
        f.write(file_content)
        f.close()
示例#11
0
 def run(self, argv, dependencies):
     self.parse_args(argv)
     self.generate()
     Logging.info('')
     Logging.info(MultiLanguage.get_string('GEN_TEMP_SUCCESS_FMT', self.engine_template_dir))
    def modify_xcode_proj(self, proj_file_path):
        if proj_file_path.find('cpp-template') >= 0:
            language = 'cpp'
        elif proj_file_path.find('lua-template') >= 0:
            language = 'lua'
        elif proj_file_path.find('js-template') >= 0:
            language = 'js'
        else:
            Logging.warning(MultiLanguage.get_string('GEN_TEMP_UNKNOWN_LANGUAGE_FMT', proj_file_path))
            return

        import modify_pbxproj
        pbx_proj = modify_pbxproj.XcodeProject.Load(proj_file_path)

        replace_engine_strs = []
        if language == "cpp":
            targetName = "HelloCpp"
            link_libs = XCODE_LINK_CPP_LIBS
            replace_engine_strs.append("$(SRCROOT)/../cocos2d")
        elif language == "lua":
            targetName = "HelloLua"
            link_libs = XCODE_LINK_CPP_LIBS + XCODE_LINK_LUA_LIBS
            replace_engine_strs.append("$(SRCROOT)/../../cocos2d-x")
        else:
            targetName = "HelloJavascript"
            link_libs = XCODE_LINK_CPP_LIBS + XCODE_LINK_JS_LIBS
            replace_engine_strs.append("$(SRCROOT)/../../cocos2d-x")
            replace_engine_strs.append("../../cocos2d-x")
        ios_target_name = "%s-mobile" % targetName
        mac_target_name = "%s-desktop" % targetName

        # remove the target dependencies
        pbx_proj.remove_proj_reference("cocos2d_libs.xcodeproj")
        if language == "lua":
            pbx_proj.remove_proj_reference("cocos2d_lua_bindings.xcodeproj")
            pbx_proj.remove_proj_reference("libsimulator.xcodeproj")

        if language == "js":
            pbx_proj.remove_proj_reference("cocos2d_js_bindings.xcodeproj")
            pbx_proj.remove_proj_reference("libsimulator.xcodeproj")
            pbx_proj.remove_file_by_path("../../cocos2d-x/cocos/scripting/js-bindings/script")

            common_group = pbx_proj.get_or_create_group("JS Common")
            pbx_proj.add_file_if_doesnt_exist("../../../script", common_group, tree="<group>")
            # pbx_proj.remove_group_by_name("JS Common")

        # add libraries search path
        libs_path = "/Applications/Cocos/frameworks/%s/prebuilt" % self.version
        ios_template_prebuilt_path = "%s/%s" % (libs_path, "ios")
        pbx_proj.add_library_search_paths(ios_template_prebuilt_path, target_name=ios_target_name, recursive=False)
        mac_template_prebuilt_path = "%s/%s" % (libs_path, "mac")
        pbx_proj.add_library_search_paths(mac_template_prebuilt_path, target_name=mac_target_name, recursive=False)

        # add libraries for targets
        ios_lib_group = pbx_proj.get_or_create_group("ios-libs")
        mac_lib_group = pbx_proj.get_or_create_group("mac-libs")
        for lib in link_libs:
            ios_lib_name = "%s iOS.a" % lib
            mac_lib_name = "%s Mac.a" % lib
            ios_lib_path = "%s/%s" % (ios_template_prebuilt_path, ios_lib_name)
            pbx_proj.add_file_if_doesnt_exist(ios_lib_path, ios_lib_group, tree="<group>", target=ios_target_name)

            mac_lib_path = "%s/%s" % (mac_template_prebuilt_path, mac_lib_name)
            pbx_proj.add_file_if_doesnt_exist(mac_lib_path, mac_lib_group, tree="<group>", target=mac_target_name)

        # add studio resources to the xcode project of cpp template
        if language == "cpp":
            pbx_proj.remove_file_by_path("CloseNormal.png")
            pbx_proj.remove_file_by_path("CloseSelected.png")
            pbx_proj.remove_file_by_path("HelloWorld.png")
            pbx_proj.remove_file_by_path("Marker Felt.ttf")
            pbx_proj.remove_file_by_path("fonts")
            pbx_proj.remove_file_by_path("res")

            res_group = pbx_proj.get_or_create_group("Resources")
            pbx_proj.add_file_if_doesnt_exist("../Resources/res", res_group, tree="<group>")

        if pbx_proj.modified:
            Logging.info(MultiLanguage.get_string('GEN_TEMP_SAVE_XCODE_PROJ_FMT', proj_file_path))
            pbx_proj.save()

        # modify the engine path
        f = open(proj_file_path)
        file_content = f.read()
        f.close()

        install_path = "/Applications/Cocos/frameworks/%s" % self.version
        for old_engine_path in replace_engine_strs:
            file_content = file_content.replace(old_engine_path, install_path)

        f = open(proj_file_path, "w")
        f.write(file_content)
        f.close()
    def modify_vs_proj(self, proj_file_path):
        if proj_file_path.find('cpp-template') >= 0:
            language = 'cpp'
        elif proj_file_path.find('lua-template') >= 0:
            language = 'lua'
        elif proj_file_path.find('js-template') >= 0:
            language = 'js'
        else:
            Logging.warning(MultiLanguage.get_string('GEN_TEMP_UNKNOWN_LANGUAGE_FMT', proj_file_path))
            return

        import modify_vcxproj
        vcx_proj = modify_vcxproj.VCXProject(proj_file_path)

        # remove the project references
        vcx_proj.remove_proj_reference()

        install_path = "$(COCOS_FRAMEWORKS)\\%s\\" % self.version

        copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \
                        "xcopy /Y /Q \"$(EngineRoot)\\prebuilt\\win32\\*.*\" \"$(OutDir)\"\n"
        vcx_proj.set_event_command('PreLinkEvent', copy_libs_cmd, 'debug')
        vcx_proj.set_event_command('PreLinkEvent', copy_libs_cmd, 'release')

        if language == "js":
            custom_step_event = vcx_proj.get_event_command('CustomBuildStep')
            custom_step_event.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script",
                                      "$(ProjectDir)..\\..\\..\\script")
            vcx_proj.set_event_command("CustomBuildStep", custom_step_event, create_new=False)

        vcx_proj.remove_predefine_macro("_DEBUG", 'debug')

        Logging.info(MultiLanguage.get_string('GEN_TEMP_SAVE_VS_PROJ_FMT', proj_file_path))
        vcx_proj.save()

        replace_strs = []
        replace_strs.append("$(EngineRoot)")
        if language == "cpp":
            # link_libs = WIN32_LINK_CPP_LIBS
            replace_strs.append("$(ProjectDir)..\\cocos2d")
            replace_strs.append("..\\cocos2d")
        elif language == "lua":
            # link_libs = WIN32_LINK_CPP_LIBS + WIN32_LINK_LUA_LIBS
            replace_strs.append("$(ProjectDir)..\\..\\cocos2d-x")
            replace_strs.append("..\\..\\cocos2d-x")
        else:
            # link_libs = WIN32_LINK_CPP_LIBS + WIN32_LINK_JS_LIBS
            replace_strs.append("$(ProjectDir)..\\..\\cocos2d-x")
            replace_strs.append("..\\..\\cocos2d-x")

        # modify the Runtime.cpp
        vcx_proj_path = os.path.dirname(proj_file_path)
        cpp_path = os.path.join(vcx_proj_path, os.path.pardir, "Classes/runtime/Runtime.cpp")
        if os.path.exists(cpp_path):
            f = open(cpp_path)
            file_content = f.read()
            f.close()

            file_content = file_content.replace("#ifndef _DEBUG", "#ifndef COCOS2D_DEBUG")
            f = open(cpp_path, "w")
            f.write(file_content)
            f.close()

        f = open(proj_file_path)
        file_content = f.read()
        f.close()

        if language == "lua":
            # replace the "lua\lua;" to "lua\luajit;"
            file_content = file_content.replace("lua\\lua;", "lua\\luajit\\include;")

        file_content = file_content.replace("MultiThreadedDebugDLL", "MultiThreadedDLL")
        for str in replace_strs:
            file_content = file_content.replace(str, install_path)
        file_content = file_content.replace('%s\\' % install_path, install_path)

        f = open(proj_file_path, "w")
        f.write(file_content)
        f.close()