From 652aaf3bcd605b8f72d98b196c1bbd1420277f76 Mon Sep 17 00:00:00 2001 From: Bin Zhang Date: Sat, 27 Jun 2015 14:44:10 +0800 Subject: [PATCH] Solve the error in framework-compile tools. --- tools/framework-compile/bin/gen_cocos_libs.py | 128 ++++++++++-------- .../framework-compile/bin/modify_template.py | 16 +-- .../bin/proj_modifier/modify_vcxproj.py | 29 ++-- 3 files changed, 103 insertions(+), 70 deletions(-) diff --git a/tools/framework-compile/bin/gen_cocos_libs.py b/tools/framework-compile/bin/gen_cocos_libs.py index 73602aa66e..a93c365d99 100755 --- a/tools/framework-compile/bin/gen_cocos_libs.py +++ b/tools/framework-compile/bin/gen_cocos_libs.py @@ -126,74 +126,94 @@ class CocosLibsCompiler(object): if len(vs_cmd_info) == 0: raise CustomError('Not found available VS.', CustomError.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[CocosLibsCompiler.KEY_VS_PROJS_INFO] for vs_version in compile_vs_versions: if not vs_version in vs_cmd_info.keys(): continue - 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, - "/clean \"Release|Win32\"" - ]) - utils_cocos.execute_command(clean_cmd) + # rename the cocos2d project out dll name + f = open(cocos2d_proj_file, 'r') + old_file_content = f.read() + f.close() - 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) + 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() - # get the build folder & win32 output folder - build_folder_path = os.path.join(os.path.dirname(proj_path), "Release.win32") - 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=\"Release|Win32\"" + 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, + "/clean \"Release|Win32\"" ]) - utils_cocos.execute_command(build_cmd) - else: - for proj_name in win32_proj_info[key][CocosLibsCompiler.KEY_VS_BUILD_TARGETS]: - # build the projects - self.build_win32_proj(vs_command, proj_path, proj_name, "build") + utils_cocos.execute_command(clean_cmd) - lib_file_path = os.path.join(build_folder_path, "%s.lib" % proj_name) - if not os.path.exists(lib_file_path): - # if the lib is not generated, rebuild the project - self.build_win32_proj(vs_command, proj_path, proj_name, "rebuild") + 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) - if not os.path.exists(lib_file_path): - raise Exception("Library %s not generated as expected!" % lib_file_path) + # get the build folder & win32 output folder + build_folder_path = os.path.join(os.path.dirname(proj_path), "Release.win32") + win32_output_dir = os.path.join(self.repo_x, output_dir) + if not os.path.exists(win32_output_dir): + os.makedirs(win32_output_dir) - # 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 + # build project + if self.use_incredibuild: + # use incredibuild, build whole sln + build_cmd = " ".join([ + "BuildConsole", + "%s" % proj_path, + "/build", + "/cfg=\"Release|Win32\"" + ]) + utils_cocos.execute_command(build_cmd) + else: + for proj_name in win32_proj_info[key][CocosLibsCompiler.KEY_VS_BUILD_TARGETS]: + # build the projects + self.build_win32_proj(vs_command, proj_path, proj_name, "build") - file_path = os.path.join(build_folder_path, file_name) - shutil.copy(file_path, win32_output_dir) + lib_file_path = os.path.join(build_folder_path, "%s.lib" % proj_name) + if not os.path.exists(lib_file_path): + # if the lib is not generated, rebuild the project + self.build_win32_proj(vs_command, proj_path, proj_name, "rebuild") + + if not os.path.exists(lib_file_path): + raise Exception("Library %s not generated as expected!" % lib_file_path) + + # 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][CocosLibsCompiler.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 os.path.exists(src_name): + 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() - # rename the specified libs - suffix = "_%d" % vs_version - for proj_name in win32_proj_info[key][CocosLibsCompiler.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 os.path.exists(src_name): - if os.path.exists(dst_name): - os.remove(dst_name) - os.rename(src_name, dst_name) print("Win32 build succeeded.") diff --git a/tools/framework-compile/bin/modify_template.py b/tools/framework-compile/bin/modify_template.py index 1fb601adcb..0f02223f1e 100755 --- a/tools/framework-compile/bin/modify_template.py +++ b/tools/framework-compile/bin/modify_template.py @@ -150,19 +150,20 @@ class TemplateModifier(object): install_path = self.engine_path if self.is_for_package: - install_path = "$(COCOS_FRAMEWORKS)\\%s" % self.version + install_path = "$(COCOS_FRAMEWORKS)\\%s\\" % self.version - custom_step_event = vcx_proj.get_event_command('CustomBuildStep') copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \ "xcopy /Y /Q \"$(EngineRoot)\\prebuilt\\win32\\*.*\" \"$(OutDir)\"\n" - custom_step_event = copy_libs_cmd + custom_step_event + vcx_proj.set_event_command('PreLinkEvent', copy_libs_cmd, 'debug') + vcx_proj.set_event_command('PreLinkEvent', copy_libs_cmd, 'release') if language == "js": - vcx_proj.set_event_command('PreLinkEvent', '', create_new=False) + 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.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" \ @@ -179,9 +180,6 @@ class TemplateModifier(object): # link_cmd = "libcmt.lib;%(IgnoreSpecificDefaultLibraries)" # vcx_proj.set_item("Link", "IgnoreSpecificDefaultLibraries", link_cmd) # - # vcx_proj.remove_predefine_macro("_DEBUG") - # - # # debug_prebuild = vcx_proj.get_event_command("PreBuildEvent", "debug") # debug_prebuild = debug_prebuild.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script", # "$(ProjectDir)..\\..\\..\\script") @@ -234,6 +232,8 @@ class TemplateModifier(object): 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() diff --git a/tools/framework-compile/bin/proj_modifier/modify_vcxproj.py b/tools/framework-compile/bin/proj_modifier/modify_vcxproj.py index e3940460f4..57173848bf 100755 --- a/tools/framework-compile/bin/proj_modifier/modify_vcxproj.py +++ b/tools/framework-compile/bin/proj_modifier/modify_vcxproj.py @@ -147,6 +147,9 @@ class VCXProject(object): cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup") for cfg_node in cfg_nodes: if config is not None: + if 'Condition' not in cfg_node.attributes.keys(): + continue + cond_attr = cfg_node.attributes["Condition"].value if cond_attr.lower().find("debug") >= 0: cur_mode = "Debug" @@ -161,7 +164,13 @@ class VCXProject(object): continue cmd_node = self.get_or_create_node(event_node, "Command") - cmd_node.firstChild.nodeValue = command + if cmd_node.firstChild is None: + impl = minidom.getDOMImplementation() + dom = impl.createDocument(None, 'catalog', None) + nodeValue = dom.createTextNode(command) + cmd_node.appendChild(nodeValue) + else: + cmd_node.firstChild.nodeValue = command def get_node_if(self, parent, name): children = parent.getElementsByTagName(name) @@ -210,14 +219,18 @@ class VCXProject(object): def remove_predefine_macro(self, macro, config=None): cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup") for cfg_node in cfg_nodes: - cond_attr = cfg_node.attributes["Condition"].value - if cond_attr.lower().find("debug") >= 0: - cur_mode = "Debug" - else: - cur_mode = "Release" + if config is not None: + if 'Condition' not in cfg_node.attributes.keys(): + continue - if (config is not None) and (cur_mode.lower() != config.lower()): - continue + cond_attr = cfg_node.attributes["Condition"].value + if cond_attr.lower().find("debug") >= 0: + cur_mode = "Debug" + else: + cur_mode = "Release" + + if (cur_mode.lower() != config.lower()): + continue compile_node = self.get_or_create_node(cfg_node, "ClCompile") predefine_node = self.get_or_create_node(compile_node, "PreprocessorDefinitions")