Solve the error in framework-compile tools.

This commit is contained in:
Bin Zhang 2015-06-27 14:44:10 +08:00
parent 0ac3da1636
commit 652aaf3bcd
3 changed files with 103 additions and 70 deletions

View File

@ -126,74 +126,94 @@ class CocosLibsCompiler(object):
if len(vs_cmd_info) == 0: if len(vs_cmd_info) == 0:
raise CustomError('Not found available VS.', CustomError.ERROR_TOOLS_NOT_FOUND) 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 # get the VS projects info
win32_proj_info = self.cfg_info[CocosLibsCompiler.KEY_VS_PROJS_INFO] win32_proj_info = self.cfg_info[CocosLibsCompiler.KEY_VS_PROJS_INFO]
for vs_version in compile_vs_versions: for vs_version in compile_vs_versions:
if not vs_version in vs_cmd_info.keys(): if not vs_version in vs_cmd_info.keys():
continue continue
vs_command = vs_cmd_info[vs_version] # rename the cocos2d project out dll name
for key in win32_proj_info.keys(): f = open(cocos2d_proj_file, 'r')
# clean solutions old_file_content = f.read()
proj_path = os.path.join(self.repo_x, key) f.close()
clean_cmd = " ".join([
"\"%s\"" % vs_command,
"\"%s\"" % proj_path,
"/clean \"Release|Win32\""
])
utils_cocos.execute_command(clean_cmd)
for key in win32_proj_info.keys(): new_file_content = old_file_content.replace('$(OutDir)$(ProjectName).dll', '$(OutDir)$(ProjectName)_%d.dll' % vs_version)
output_dir = os.path.join(self.lib_dir, "win32") f = open(cocos2d_proj_file, 'w')
proj_path = os.path.join(self.repo_x, key) f.write(new_file_content)
f.close()
# get the build folder & win32 output folder try:
build_folder_path = os.path.join(os.path.dirname(proj_path), "Release.win32") vs_command = vs_cmd_info[vs_version]
win32_output_dir = os.path.join(self.repo_x, output_dir) for key in win32_proj_info.keys():
if not os.path.exists(win32_output_dir): # clean solutions
os.makedirs(win32_output_dir) proj_path = os.path.join(self.repo_x, key)
clean_cmd = " ".join([
# build project "\"%s\"" % vs_command,
if self.use_incredibuild: "\"%s\"" % proj_path,
# use incredibuild, build whole sln "/clean \"Release|Win32\""
build_cmd = " ".join([
"BuildConsole",
"%s" % proj_path,
"/build",
"/cfg=\"Release|Win32\""
]) ])
utils_cocos.execute_command(build_cmd) utils_cocos.execute_command(clean_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")
lib_file_path = os.path.join(build_folder_path, "%s.lib" % proj_name) for key in win32_proj_info.keys():
if not os.path.exists(lib_file_path): output_dir = os.path.join(self.lib_dir, "win32")
# if the lib is not generated, rebuild the project proj_path = os.path.join(self.repo_x, key)
self.build_win32_proj(vs_command, proj_path, proj_name, "rebuild")
if not os.path.exists(lib_file_path): # get the build folder & win32 output folder
raise Exception("Library %s not generated as expected!" % lib_file_path) 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 # build project
for file_name in os.listdir(build_folder_path): if self.use_incredibuild:
name, ext = os.path.splitext(file_name) # use incredibuild, build whole sln
if ext != ".lib" and ext != ".dll": build_cmd = " ".join([
continue "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) lib_file_path = os.path.join(build_folder_path, "%s.lib" % proj_name)
shutil.copy(file_path, win32_output_dir) 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.") print("Win32 build succeeded.")

View File

@ -150,19 +150,20 @@ class TemplateModifier(object):
install_path = self.engine_path install_path = self.engine_path
if self.is_for_package: 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" \ copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \
"xcopy /Y /Q \"$(EngineRoot)\\prebuilt\\win32\\*.*\" \"$(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": 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", custom_step_event.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script",
"$(ProjectDir)..\\..\\..\\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" \ # copy_libs_cmd = "if not exist \"$(OutDir)\" mkdir \"$(OutDir)\"\n" \
@ -179,9 +180,6 @@ class TemplateModifier(object):
# link_cmd = "libcmt.lib;%(IgnoreSpecificDefaultLibraries)" # link_cmd = "libcmt.lib;%(IgnoreSpecificDefaultLibraries)"
# vcx_proj.set_item("Link", "IgnoreSpecificDefaultLibraries", link_cmd) # 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 = vcx_proj.get_event_command("PreBuildEvent", "debug")
# debug_prebuild = debug_prebuild.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script", # debug_prebuild = debug_prebuild.replace("$(ProjectDir)..\\..\\cocos2d-x\\cocos\\scripting\\js-bindings\\script",
# "$(ProjectDir)..\\..\\..\\script") # "$(ProjectDir)..\\..\\..\\script")
@ -234,6 +232,8 @@ class TemplateModifier(object):
file_content = file_content.replace("MultiThreadedDebugDLL", "MultiThreadedDLL") file_content = file_content.replace("MultiThreadedDebugDLL", "MultiThreadedDLL")
for str in replace_strs: for str in replace_strs:
file_content = file_content.replace(str, install_path) 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 = open(proj_file_path, "w")
f.write(file_content) f.write(file_content)
f.close() f.close()

View File

@ -147,6 +147,9 @@ class VCXProject(object):
cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup") cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup")
for cfg_node in cfg_nodes: for cfg_node in cfg_nodes:
if config is not None: if config is not None:
if 'Condition' not in cfg_node.attributes.keys():
continue
cond_attr = cfg_node.attributes["Condition"].value cond_attr = cfg_node.attributes["Condition"].value
if cond_attr.lower().find("debug") >= 0: if cond_attr.lower().find("debug") >= 0:
cur_mode = "Debug" cur_mode = "Debug"
@ -161,7 +164,13 @@ class VCXProject(object):
continue continue
cmd_node = self.get_or_create_node(event_node, "Command") 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): def get_node_if(self, parent, name):
children = parent.getElementsByTagName(name) children = parent.getElementsByTagName(name)
@ -210,14 +219,18 @@ class VCXProject(object):
def remove_predefine_macro(self, macro, config=None): def remove_predefine_macro(self, macro, config=None):
cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup") cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup")
for cfg_node in cfg_nodes: for cfg_node in cfg_nodes:
cond_attr = cfg_node.attributes["Condition"].value if config is not None:
if cond_attr.lower().find("debug") >= 0: if 'Condition' not in cfg_node.attributes.keys():
cur_mode = "Debug" continue
else:
cur_mode = "Release"
if (config is not None) and (cur_mode.lower() != config.lower()): cond_attr = cfg_node.attributes["Condition"].value
continue 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") compile_node = self.get_or_create_node(cfg_node, "ClCompile")
predefine_node = self.get_or_create_node(compile_node, "PreprocessorDefinitions") predefine_node = self.get_or_create_node(compile_node, "PreprocessorDefinitions")