Esempio n. 1
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()
Esempio n. 2
0
    def modify_vs_proj(self, proj_file_path, language):
        proj_modifier_path = os.path.join(os.path.dirname(__file__),
                                          "proj_modifier")
        sys.path.append(proj_modifier_path)

        import modify_vcxproj
        vcx_proj = modify_vcxproj.VCXProject(proj_file_path)

        # remove the project references
        vcx_proj.remove_proj_reference()

        install_path = self.engine_path
        if self.is_for_package:
            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')

        #
        # copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \
        #                 "xcopy /Y /Q \"$(EngineRoot)tools\\framework-compile\\libs\\windows\\*.*\" \"$(OutDir)\"\n"
        # if self.is_for_package:
        #     copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \
        #                 "xcopy /Y /Q \"%s\\prebuilt\\win32\\*.*\" \"$(OutDir)\"\n" % install_path
        # if language == "cpp":
        #     copy_libs_cmd = copy_libs_cmd + "xcopy \"$(ProjectDir)..\\Resources\" \"$(OutDir)\" /D /E /I /F /Y\n"
        #
        # vcx_proj.set_event_command("PreLinkEvent", copy_libs_cmd)
        #
        # if language == "lua":
        #     link_cmd = "libcmt.lib;%(IgnoreSpecificDefaultLibraries)"
        #     vcx_proj.set_item("Link", "IgnoreSpecificDefaultLibraries", link_cmd)
        #
        # debug_prebuild = vcx_proj.get_event_command("PreBuildEvent", "debug")
        # debug_prebuild = debug_prebuild.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script",
        #                                         "$(ProjectDir)..\\..\\..\\script")
        # vcx_proj.set_event_command("PreBuildEvent", debug_prebuild, "debug")
        #
        # release_prebuild = vcx_proj.get_event_command("PreBuildEvent", "release")
        # release_prebuild = release_prebuild.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script",
        #                                         "$(ProjectDir)..\\..\\..\\script")
        # vcx_proj.set_event_command("PreBuildEvent", release_prebuild, "release")

        vcx_proj.save()

        replace_strs = []
        if self.is_for_package:
            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()