mirror of https://github.com/axmolengine/axmol.git
Replace tab with spaces.
This commit is contained in:
parent
f6af1713dd
commit
088cc76b9f
|
@ -9,208 +9,208 @@ from argparse import ArgumentParser
|
|||
|
||||
class CocosBinTemplateGenerator(object):
|
||||
|
||||
def __init__(self, args):
|
||||
print "Generate cocos binary template"
|
||||
def __init__(self, args):
|
||||
print "Generate cocos binary template"
|
||||
|
||||
self.cur_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
self.repo_x = os.path.realpath(args.repo_x)
|
||||
self.template_dir = os.path.realpath(os.path.join(self.cur_dir, os.path.pardir, "templates"))
|
||||
self.lib_dir = os.path.realpath(os.path.join(self.cur_dir, os.path.pardir, "libs"))
|
||||
self.version = self.get_version_from_source()
|
||||
self.is_for_package = False
|
||||
try:
|
||||
self.is_for_package = args.is_for_package
|
||||
except Exception, e:
|
||||
print "[Warn] %s" % e
|
||||
self.cur_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
self.repo_x = os.path.realpath(args.repo_x)
|
||||
self.template_dir = os.path.realpath(os.path.join(self.cur_dir, os.path.pardir, "templates"))
|
||||
self.lib_dir = os.path.realpath(os.path.join(self.cur_dir, os.path.pardir, "libs"))
|
||||
self.version = self.get_version_from_source()
|
||||
self.is_for_package = False
|
||||
try:
|
||||
self.is_for_package = args.is_for_package
|
||||
except Exception, e:
|
||||
print "[Warn] %s" % e
|
||||
|
||||
def generate(self):
|
||||
self.clean_template()
|
||||
self.config_json = self.getConfigJson()
|
||||
self.copy_template()
|
||||
self.modify_binary_mk()
|
||||
self.gen_templates()
|
||||
def generate(self):
|
||||
self.clean_template()
|
||||
self.config_json = self.getConfigJson()
|
||||
self.copy_template()
|
||||
self.modify_binary_mk()
|
||||
self.gen_templates()
|
||||
|
||||
excopy.copy_files_in_dir(self.template_dir, os.path.join(self.repo_x, "templates"))
|
||||
excopy.copy_files_in_dir(self.template_dir, os.path.join(self.repo_x, "templates"))
|
||||
|
||||
def clean_template(self):
|
||||
import shutil
|
||||
rmdir(self.template_dir)
|
||||
rmdir(os.path.join(self.repo_x, "templates", "cpp-template-binary"))
|
||||
rmdir(os.path.join(self.repo_x, "templates", "lua-template-binary"))
|
||||
rmdir(os.path.join(self.repo_x, "templates", "js-template-binary"))
|
||||
def clean_template(self):
|
||||
import shutil
|
||||
rmdir(self.template_dir)
|
||||
rmdir(os.path.join(self.repo_x, "templates", "cpp-template-binary"))
|
||||
rmdir(os.path.join(self.repo_x, "templates", "lua-template-binary"))
|
||||
rmdir(os.path.join(self.repo_x, "templates", "js-template-binary"))
|
||||
|
||||
def copy_template(self):
|
||||
for item in self.config_json["template_copy_config"]:
|
||||
excopy.copy_files_with_config(item, self.repo_x, self.template_dir)
|
||||
templates_dir = os.path.join(self.cur_dir, os.path.pardir, "bin-templates")
|
||||
excopy.copy_files_in_dir(os.path.join(templates_dir, "cpp-template-default"),
|
||||
os.path.join(self.template_dir, "cpp-template-binary"))
|
||||
excopy.copy_files_in_dir(os.path.join(templates_dir, "lua-template-runtime"),
|
||||
os.path.join(self.template_dir, "lua-template-binary"))
|
||||
excopy.copy_files_in_dir(os.path.join(templates_dir, "js-template-runtime"),
|
||||
os.path.join(self.template_dir, "js-template-binary"))
|
||||
def copy_template(self):
|
||||
for item in self.config_json["template_copy_config"]:
|
||||
excopy.copy_files_with_config(item, self.repo_x, self.template_dir)
|
||||
templates_dir = os.path.join(self.cur_dir, os.path.pardir, "bin-templates")
|
||||
excopy.copy_files_in_dir(os.path.join(templates_dir, "cpp-template-default"),
|
||||
os.path.join(self.template_dir, "cpp-template-binary"))
|
||||
excopy.copy_files_in_dir(os.path.join(templates_dir, "lua-template-runtime"),
|
||||
os.path.join(self.template_dir, "lua-template-binary"))
|
||||
excopy.copy_files_in_dir(os.path.join(templates_dir, "js-template-runtime"),
|
||||
os.path.join(self.template_dir, "js-template-binary"))
|
||||
|
||||
def modify_binary_mk(self):
|
||||
android_libs = os.path.join(self.lib_dir, "android")
|
||||
android_mks = self.config_json["android_mks"]
|
||||
import gen_prebuilt_mk
|
||||
for mk_file in android_mks:
|
||||
mk_file_path = os.path.join(self.repo_x, mk_file)
|
||||
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()
|
||||
def modify_binary_mk(self):
|
||||
android_libs = os.path.join(self.lib_dir, "android")
|
||||
android_mks = self.config_json["android_mks"]
|
||||
import gen_prebuilt_mk
|
||||
for mk_file in android_mks:
|
||||
mk_file_path = os.path.join(self.repo_x, mk_file)
|
||||
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()
|
||||
|
||||
def process_file(sour, dest):
|
||||
f = open(sour)
|
||||
file_content = f.read()
|
||||
f.close()
|
||||
def process_file(sour, dest):
|
||||
f = open(sour)
|
||||
file_content = f.read()
|
||||
f.close()
|
||||
|
||||
file_content = file_content.replace("__LIBS_DIR__", self.lib_dir)
|
||||
file_content = file_content.replace("__LIBS_DIR__", self.lib_dir)
|
||||
|
||||
f = open(os.path.join(dest, os.path.basename(sour)), "w")
|
||||
f.write(file_content)
|
||||
f.close()
|
||||
f = open(os.path.join(dest, os.path.basename(sour)), "w")
|
||||
f.write(file_content)
|
||||
f.close()
|
||||
|
||||
from utils_cocos import copy_files_with_cb
|
||||
copy_files_with_cb(os.path.join(self.cur_dir, os.path.pardir, "x-modified"), self.repo_x, process_file)
|
||||
from utils_cocos import copy_files_with_cb
|
||||
copy_files_with_cb(os.path.join(self.cur_dir, os.path.pardir, "x-modified"), self.repo_x, process_file)
|
||||
|
||||
def getConfigJson(self):
|
||||
cfg_json_path = os.path.join(self.cur_dir, "template_binary_config.json")
|
||||
f = open(cfg_json_path)
|
||||
config_json = json.load(f)
|
||||
f.close()
|
||||
def getConfigJson(self):
|
||||
cfg_json_path = os.path.join(self.cur_dir, "template_binary_config.json")
|
||||
f = open(cfg_json_path)
|
||||
config_json = json.load(f)
|
||||
f.close()
|
||||
|
||||
return config_json
|
||||
return config_json
|
||||
|
||||
def gen_templates(self):
|
||||
dst_dir = self.template_dir
|
||||
x_path = self.repo_x
|
||||
lib_dir = self.lib_dir
|
||||
import modify_template
|
||||
# modify the VS project file of templates
|
||||
if self.is_for_package:
|
||||
version = self.version.replace(" ", "-")
|
||||
modifier = modify_template.TemplateModifier(x_path, lib_dir, version, self.is_for_package)
|
||||
else:
|
||||
modifier = modify_template.TemplateModifier(x_path, lib_dir, "no_use", self.is_for_package)
|
||||
cpp_proj_path = os.path.join(dst_dir, "cpp-template-binary/proj.win32/HelloCpp.vcxproj")
|
||||
lua_proj_path = os.path.join(dst_dir, "lua-template-binary/frameworks/runtime-src/proj.win32/HelloLua.vcxproj")
|
||||
js_proj_path = os.path.join(dst_dir, "js-template-binary/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj")
|
||||
modifier.modify_vs_proj(cpp_proj_path, "cpp")
|
||||
modifier.modify_vs_proj(lua_proj_path, "lua")
|
||||
modifier.modify_vs_proj(js_proj_path, "js")
|
||||
def gen_templates(self):
|
||||
dst_dir = self.template_dir
|
||||
x_path = self.repo_x
|
||||
lib_dir = self.lib_dir
|
||||
import modify_template
|
||||
# modify the VS project file of templates
|
||||
if self.is_for_package:
|
||||
version = self.version.replace(" ", "-")
|
||||
modifier = modify_template.TemplateModifier(x_path, lib_dir, version, self.is_for_package)
|
||||
else:
|
||||
modifier = modify_template.TemplateModifier(x_path, lib_dir, "no_use", self.is_for_package)
|
||||
cpp_proj_path = os.path.join(dst_dir, "cpp-template-binary/proj.win32/HelloCpp.vcxproj")
|
||||
lua_proj_path = os.path.join(dst_dir, "lua-template-binary/frameworks/runtime-src/proj.win32/HelloLua.vcxproj")
|
||||
js_proj_path = os.path.join(dst_dir, "js-template-binary/frameworks/runtime-src/proj.win32/HelloJavascript.vcxproj")
|
||||
modifier.modify_vs_proj(cpp_proj_path, "cpp")
|
||||
modifier.modify_vs_proj(lua_proj_path, "lua")
|
||||
modifier.modify_vs_proj(js_proj_path, "js")
|
||||
|
||||
# modify the xcode project file of templates
|
||||
cpp_proj_path = os.path.join(dst_dir, "cpp-template-binary/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj")
|
||||
lua_proj_path = os.path.join(dst_dir, "lua-template-binary/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj")
|
||||
js_proj_path = os.path.join(dst_dir, "js-template-binary/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj")
|
||||
modifier.modify_xcode_proj(cpp_proj_path, "cpp")
|
||||
modifier.modify_xcode_proj(lua_proj_path, "lua")
|
||||
modifier.modify_xcode_proj(js_proj_path, "js")
|
||||
# modify the xcode project file of templates
|
||||
cpp_proj_path = os.path.join(dst_dir, "cpp-template-binary/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj")
|
||||
lua_proj_path = os.path.join(dst_dir, "lua-template-binary/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj")
|
||||
js_proj_path = os.path.join(dst_dir, "js-template-binary/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj")
|
||||
modifier.modify_xcode_proj(cpp_proj_path, "cpp")
|
||||
modifier.modify_xcode_proj(lua_proj_path, "lua")
|
||||
modifier.modify_xcode_proj(js_proj_path, "js")
|
||||
|
||||
# modify the build-cfg.json for templates
|
||||
cpp_build_cfg = os.path.join(dst_dir, "cpp-template-binary/proj.android/build-cfg.json")
|
||||
lua_build_cfg = os.path.join(dst_dir, "lua-template-binary/frameworks/runtime-src/proj.android/build-cfg.json")
|
||||
js_build_cfg = os.path.join(dst_dir, "js-template-binary/frameworks/runtime-src/proj.android/build-cfg.json")
|
||||
self.modify_android_build_cfg(cpp_build_cfg, "cpp")
|
||||
self.modify_android_build_cfg(lua_build_cfg, "lua")
|
||||
self.modify_android_build_cfg(js_build_cfg, "js")
|
||||
# modify the build-cfg.json for templates
|
||||
cpp_build_cfg = os.path.join(dst_dir, "cpp-template-binary/proj.android/build-cfg.json")
|
||||
lua_build_cfg = os.path.join(dst_dir, "lua-template-binary/frameworks/runtime-src/proj.android/build-cfg.json")
|
||||
js_build_cfg = os.path.join(dst_dir, "js-template-binary/frameworks/runtime-src/proj.android/build-cfg.json")
|
||||
self.modify_android_build_cfg(cpp_build_cfg, "cpp")
|
||||
self.modify_android_build_cfg(lua_build_cfg, "lua")
|
||||
self.modify_android_build_cfg(js_build_cfg, "js")
|
||||
|
||||
self.modify_version_json(os.path.join(dst_dir, "lua-template-binary/.settings/version.json"))
|
||||
self.modify_version_json(os.path.join(dst_dir, "js-template-binary/.settings/version.json"))
|
||||
self.modify_version_json(os.path.join(dst_dir, "lua-template-binary/.settings/version.json"))
|
||||
self.modify_version_json(os.path.join(dst_dir, "js-template-binary/.settings/version.json"))
|
||||
|
||||
self.gen_template_config(dst_dir, self.version)
|
||||
self.gen_template_config(dst_dir, self.version)
|
||||
|
||||
def modify_version_json(self, file_path):
|
||||
f = open(file_path)
|
||||
version_info = json.load(f)
|
||||
f.close()
|
||||
def modify_version_json(self, file_path):
|
||||
f = open(file_path)
|
||||
version_info = json.load(f)
|
||||
f.close()
|
||||
|
||||
version_info["engineVersion"] = self.version
|
||||
version_info["engineVersion"] = self.version
|
||||
|
||||
f = open(file_path, "w")
|
||||
json.dump(version_info, f, sort_keys=True, indent=4)
|
||||
f.close()
|
||||
f = open(file_path, "w")
|
||||
json.dump(version_info, f, sort_keys=True, indent=4)
|
||||
f.close()
|
||||
|
||||
def get_version_from_source(self):
|
||||
src_engine_path = self.repo_x
|
||||
version_file_path = os.path.join(src_engine_path, "cocos/cocos2d.cpp")
|
||||
pattern = r".*return[ \t]+\"(.*)\";"
|
||||
def get_version_from_source(self):
|
||||
src_engine_path = self.repo_x
|
||||
version_file_path = os.path.join(src_engine_path, "cocos/cocos2d.cpp")
|
||||
pattern = r".*return[ \t]+\"(.*)\";"
|
||||
|
||||
|
||||
# restore the version of engine
|
||||
ver = ""
|
||||
f = open(version_file_path)
|
||||
import re
|
||||
for line in f.readlines():
|
||||
match = re.match(pattern, line)
|
||||
if match:
|
||||
ver = match.group(1)
|
||||
break
|
||||
f.close()
|
||||
# restore the version of engine
|
||||
ver = ""
|
||||
f = open(version_file_path)
|
||||
import re
|
||||
for line in f.readlines():
|
||||
match = re.match(pattern, line)
|
||||
if match:
|
||||
ver = match.group(1)
|
||||
break
|
||||
f.close()
|
||||
|
||||
if len(ver) <= 0:
|
||||
raise Exception("Can't find version in %s" % version_file_path)
|
||||
if len(ver) <= 0:
|
||||
raise Exception("Can't find version in %s" % version_file_path)
|
||||
|
||||
return ver
|
||||
return ver
|
||||
|
||||
def gen_template_config(self, template_path, engine_ver):
|
||||
import re
|
||||
for name in os.listdir(template_path):
|
||||
fullPath = os.path.join(template_path, name)
|
||||
if not os.path.isdir(fullPath):
|
||||
continue
|
||||
def gen_template_config(self, template_path, engine_ver):
|
||||
import re
|
||||
for name in os.listdir(template_path):
|
||||
fullPath = os.path.join(template_path, name)
|
||||
if not os.path.isdir(fullPath):
|
||||
continue
|
||||
|
||||
if not re.match(".*-template-.*", name):
|
||||
continue
|
||||
if not re.match(".*-template-.*", name):
|
||||
continue
|
||||
|
||||
cfg_path = os.path.join(fullPath, ".cocos-project.json")
|
||||
cfg_info = {}
|
||||
if os.path.exists(cfg_path):
|
||||
f = open(cfg_path)
|
||||
cfg_info = json.load(f)
|
||||
f.close()
|
||||
cfg_path = os.path.join(fullPath, ".cocos-project.json")
|
||||
cfg_info = {}
|
||||
if os.path.exists(cfg_path):
|
||||
f = open(cfg_path)
|
||||
cfg_info = json.load(f)
|
||||
f.close()
|
||||
|
||||
cfg_info["engine_version"] = engine_ver
|
||||
cfg_info["engine_type"] = "prebuilt"
|
||||
cfg_info["engine_version"] = engine_ver
|
||||
cfg_info["engine_type"] = "prebuilt"
|
||||
|
||||
f = open(cfg_path, "w")
|
||||
json.dump(cfg_info, f, sort_keys=True, indent=4)
|
||||
f.close()
|
||||
f = open(cfg_path, "w")
|
||||
json.dump(cfg_info, f, sort_keys=True, indent=4)
|
||||
f.close()
|
||||
|
||||
def modify_android_build_cfg(self, cfg_path, language):
|
||||
f = open(cfg_path)
|
||||
content = f.read()
|
||||
f.close()
|
||||
def modify_android_build_cfg(self, cfg_path, language):
|
||||
f = open(cfg_path)
|
||||
content = f.read()
|
||||
f.close()
|
||||
|
||||
if language == "cpp":
|
||||
replace_str = "../cocos2d"
|
||||
elif language == "lua":
|
||||
replace_str = "../../cocos2d-x"
|
||||
else:
|
||||
replace_str = "../../cocos2d-x"
|
||||
if language == "cpp":
|
||||
replace_str = "../cocos2d"
|
||||
elif language == "lua":
|
||||
replace_str = "../../cocos2d-x"
|
||||
else:
|
||||
replace_str = "../../cocos2d-x"
|
||||
|
||||
if replace_str is not None:
|
||||
content = content.replace(replace_str, self.repo_x)
|
||||
if replace_str is not None:
|
||||
content = content.replace(replace_str, self.repo_x)
|
||||
|
||||
f = open(cfg_path, "w")
|
||||
f.write(content)
|
||||
f.close()
|
||||
f = open(cfg_path, "w")
|
||||
f.write(content)
|
||||
f.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = ArgumentParser(description="Generate binary template.")
|
||||
parser.add_argument('--repo-x', dest='repo_x', help='Set the repo path of cocos2d-x.')
|
||||
parser = ArgumentParser(description="Generate binary template.")
|
||||
parser.add_argument('--repo-x', dest='repo_x', help='Set the repo path of cocos2d-x.')
|
||||
|
||||
(args, unknown) = parser.parse_known_args()
|
||||
(args, unknown) = parser.parse_known_args()
|
||||
|
||||
if len(unknown) > 0:
|
||||
print("unknown arguments: %s" % unknown)
|
||||
if len(unknown) > 0:
|
||||
print("unknown arguments: %s" % unknown)
|
||||
|
||||
if args.repo_x is None:
|
||||
print("ERROR! must set repo of cocos2d-x")
|
||||
exit(1)
|
||||
if args.repo_x is None:
|
||||
print("ERROR! must set repo of cocos2d-x")
|
||||
exit(1)
|
||||
|
||||
templateGenerator = CocosBinTemplateGenerator(args)
|
||||
templateGenerator.generate()
|
||||
templateGenerator = CocosBinTemplateGenerator(args)
|
||||
templateGenerator.generate()
|
||||
|
||||
|
|
|
@ -10,456 +10,456 @@ from utils_cocos import rmdir
|
|||
from argparse import ArgumentParser
|
||||
|
||||
def os_is_win32():
|
||||
return sys.platform == 'win32'
|
||||
return sys.platform == 'win32'
|
||||
|
||||
def is_32bit_windows():
|
||||
arch = os.environ['PROCESSOR_ARCHITECTURE'].lower()
|
||||
archw = os.environ.has_key("PROCESSOR_ARCHITEW6432")
|
||||
return (arch == "x86" and not archw)
|
||||
arch = os.environ['PROCESSOR_ARCHITECTURE'].lower()
|
||||
archw = os.environ.has_key("PROCESSOR_ARCHITEW6432")
|
||||
return (arch == "x86" and not archw)
|
||||
|
||||
def os_is_mac():
|
||||
return sys.platform == 'darwin'
|
||||
return sys.platform == 'darwin'
|
||||
|
||||
def convert_to_python_path(path):
|
||||
return path.replace("\\","/")
|
||||
return path.replace("\\","/")
|
||||
|
||||
def execute_command(cmdstring, cwd=None, timeout=None, shell=True):
|
||||
""" 执行一个SHELL命令
|
||||
封装了subprocess的Popen方法, 支持超时判断,支持读取stdout和stderr
|
||||
参数:
|
||||
cwd: 运行命令时更改路径,如果被设定,子进程会直接先更改当前路径到cwd
|
||||
timeout: 超时时间,秒,支持小数,精度0.1秒
|
||||
shell: 是否通过shell运行
|
||||
Returns: return_code
|
||||
Raises: Exception: 执行超时
|
||||
"""
|
||||
""" 执行一个SHELL命令
|
||||
封装了subprocess的Popen方法, 支持超时判断,支持读取stdout和stderr
|
||||
参数:
|
||||
cwd: 运行命令时更改路径,如果被设定,子进程会直接先更改当前路径到cwd
|
||||
timeout: 超时时间,秒,支持小数,精度0.1秒
|
||||
shell: 是否通过shell运行
|
||||
Returns: return_code
|
||||
Raises: Exception: 执行超时
|
||||
"""
|
||||
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import time
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
if os_is_win32():
|
||||
cmdstring = convert_to_python_path(cmdstring)
|
||||
if os_is_win32():
|
||||
cmdstring = convert_to_python_path(cmdstring)
|
||||
|
||||
print("")
|
||||
print("Execute command:")
|
||||
print(cmdstring)
|
||||
print("")
|
||||
print("")
|
||||
print("Execute command:")
|
||||
print(cmdstring)
|
||||
print("")
|
||||
|
||||
if shell:
|
||||
cmdstring_list = cmdstring
|
||||
else:
|
||||
cmdstring_list = shlex.split(cmdstring)
|
||||
if timeout:
|
||||
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
|
||||
if shell:
|
||||
cmdstring_list = cmdstring
|
||||
else:
|
||||
cmdstring_list = shlex.split(cmdstring)
|
||||
if timeout:
|
||||
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
|
||||
|
||||
# 没有指定标准输出和错误输出的管道,因此会打印到屏幕上
|
||||
sub = None
|
||||
try:
|
||||
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE, shell=shell, bufsize=4096)
|
||||
except Exception, e:
|
||||
print "execute command fail:%s" % cmdstring
|
||||
raise e
|
||||
# 没有指定标准输出和错误输出的管道,因此会打印到屏幕上
|
||||
sub = None
|
||||
try:
|
||||
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE, shell=shell, bufsize=4096)
|
||||
except Exception, e:
|
||||
print "execute command fail:%s" % cmdstring
|
||||
raise e
|
||||
|
||||
# subprocess.poll()方法:检查子进程是否结束了,如果结束了,设定并返回码,放在subprocess.returncode变量中
|
||||
while sub.poll() is None:
|
||||
time.sleep(0.1)
|
||||
if timeout:
|
||||
if end_time <= datetime.datetime.now():
|
||||
raise Exception("Timeout:%s"%cmdstring)
|
||||
# subprocess.poll()方法:检查子进程是否结束了,如果结束了,设定并返回码,放在subprocess.returncode变量中
|
||||
while sub.poll() is None:
|
||||
time.sleep(0.1)
|
||||
if timeout:
|
||||
if end_time <= datetime.datetime.now():
|
||||
raise Exception("Timeout:%s"%cmdstring)
|
||||
|
||||
if 0 != sub.returncode :
|
||||
errStr = "[ERROR] execute command fail:%s" % cmdstring
|
||||
print errStr
|
||||
raise Exception(errStr)
|
||||
if 0 != sub.returncode :
|
||||
errStr = "[ERROR] execute command fail:%s" % cmdstring
|
||||
print errStr
|
||||
raise Exception(errStr)
|
||||
|
||||
return sub.returncode
|
||||
return sub.returncode
|
||||
|
||||
|
||||
class CocosLibsCompiler(object):
|
||||
|
||||
def __init__(self, args):
|
||||
print "Compiler init function"
|
||||
def __init__(self, args):
|
||||
print "Compiler init function"
|
||||
|
||||
# argsments check and set
|
||||
self.clean = args.clean
|
||||
self.build_win = args.win
|
||||
self.build_mac = args.mac
|
||||
self.build_android = args.android
|
||||
self.disable_strip = args.disable_strip
|
||||
self.repo_x = args.repo_x
|
||||
self.vs_version = args.vs_version
|
||||
self.use_incredibuild = False
|
||||
if args.all:
|
||||
self.build_win = True
|
||||
self.build_mac = True
|
||||
self.build_android = True
|
||||
# argsments check and set
|
||||
self.clean = args.clean
|
||||
self.build_win = args.win
|
||||
self.build_mac = args.mac
|
||||
self.build_android = args.android
|
||||
self.disable_strip = args.disable_strip
|
||||
self.repo_x = args.repo_x
|
||||
self.vs_version = args.vs_version
|
||||
self.use_incredibuild = False
|
||||
if args.all:
|
||||
self.build_win = True
|
||||
self.build_mac = True
|
||||
self.build_android = True
|
||||
|
||||
self.cur_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
self.repo_x = os.path.realpath(self.repo_x)
|
||||
self.lib_dir = os.path.realpath(os.path.join(self.cur_dir, os.path.pardir, "libs"))
|
||||
self.cur_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
self.repo_x = os.path.realpath(self.repo_x)
|
||||
self.lib_dir = os.path.realpath(os.path.join(self.cur_dir, os.path.pardir, "libs"))
|
||||
|
||||
def compile(self):
|
||||
print "compile function"
|
||||
if self.clean:
|
||||
self.clean_libs()
|
||||
if self.build_win:
|
||||
self.compile_win()
|
||||
if self.build_mac:
|
||||
self.compile_mac_ios()
|
||||
if self.build_android:
|
||||
self.compile_android("lua")
|
||||
self.compile_android("js")
|
||||
def compile(self):
|
||||
print "compile function"
|
||||
if self.clean:
|
||||
self.clean_libs()
|
||||
if self.build_win:
|
||||
self.compile_win()
|
||||
if self.build_mac:
|
||||
self.compile_mac_ios()
|
||||
if self.build_android:
|
||||
self.compile_android("lua")
|
||||
self.compile_android("js")
|
||||
|
||||
|
||||
def build_win32_proj(self, cmd_path, sln_path, proj_name, mode):
|
||||
build_cmd = " ".join([
|
||||
"\"%s\"" % cmd_path,
|
||||
"\"%s\"" % sln_path,
|
||||
"/%s \"Release|Win32\"" % mode,
|
||||
"/Project \"%s\"" % proj_name
|
||||
])
|
||||
execute_command(build_cmd)
|
||||
def build_win32_proj(self, cmd_path, sln_path, proj_name, mode):
|
||||
build_cmd = " ".join([
|
||||
"\"%s\"" % cmd_path,
|
||||
"\"%s\"" % sln_path,
|
||||
"/%s \"Release|Win32\"" % mode,
|
||||
"/Project \"%s\"" % proj_name
|
||||
])
|
||||
execute_command(build_cmd)
|
||||
|
||||
def compile_win(self):
|
||||
if not os_is_win32():
|
||||
print "this is not win platform, needn't compile"
|
||||
return
|
||||
def compile_win(self):
|
||||
if not os_is_win32():
|
||||
print "this is not win platform, needn't compile"
|
||||
return
|
||||
|
||||
win32_proj_info = {
|
||||
"build/cocos2d-win32.sln" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"build_targets" : [
|
||||
"libluacocos2d"
|
||||
],
|
||||
"rename_targets" : [
|
||||
# "libcocos2d", "libluacocos2d", "libSpine", "libbox2d"
|
||||
]
|
||||
},
|
||||
"build/cocos2d-js-win32.sln" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"build_targets" : [
|
||||
"libjscocos2d"
|
||||
],
|
||||
"rename_targets" : [
|
||||
# "libjscocos2d"
|
||||
]
|
||||
},
|
||||
"tools/simulator/frameworks/runtime-src/proj.win32/simulator.sln" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"build_targets" : [
|
||||
"libsimulator"
|
||||
],
|
||||
"rename_targets" : [
|
||||
# "libsimulator"
|
||||
]
|
||||
}
|
||||
}
|
||||
win32_proj_info = {
|
||||
"build/cocos2d-win32.sln" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"build_targets" : [
|
||||
"libluacocos2d"
|
||||
],
|
||||
"rename_targets" : [
|
||||
# "libcocos2d", "libluacocos2d", "libSpine", "libbox2d"
|
||||
]
|
||||
},
|
||||
"build/cocos2d-js-win32.sln" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"build_targets" : [
|
||||
"libjscocos2d"
|
||||
],
|
||||
"rename_targets" : [
|
||||
# "libjscocos2d"
|
||||
]
|
||||
},
|
||||
"tools/simulator/frameworks/runtime-src/proj.win32/simulator.sln" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"build_targets" : [
|
||||
"libsimulator"
|
||||
],
|
||||
"rename_targets" : [
|
||||
# "libsimulator"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
import _winreg
|
||||
from utils_cocos import get_vs_cmd_path
|
||||
# find the VS in register
|
||||
try:
|
||||
if is_32bit_windows():
|
||||
reg_flag = _winreg.KEY_WOW64_32KEY
|
||||
else:
|
||||
# reg_flag = _winreg.KEY_WOW64_64KEY
|
||||
reg_flag = _winreg.KEY_WOW64_32KEY # _winreg.KEY_WOW64_64KEY
|
||||
import _winreg
|
||||
from utils_cocos import get_vs_cmd_path
|
||||
# find the VS in register
|
||||
try:
|
||||
if is_32bit_windows():
|
||||
reg_flag = _winreg.KEY_WOW64_32KEY
|
||||
else:
|
||||
# reg_flag = _winreg.KEY_WOW64_64KEY
|
||||
reg_flag = _winreg.KEY_WOW64_32KEY # _winreg.KEY_WOW64_64KEY
|
||||
|
||||
vs_reg = _winreg.OpenKey(
|
||||
_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"SOFTWARE\Microsoft\VisualStudio",
|
||||
0,
|
||||
_winreg.KEY_READ | reg_flag
|
||||
)
|
||||
vs_reg = _winreg.OpenKey(
|
||||
_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"SOFTWARE\Microsoft\VisualStudio",
|
||||
0,
|
||||
_winreg.KEY_READ | reg_flag
|
||||
)
|
||||
|
||||
except WindowsError:
|
||||
message = "Visual Studio wasn't installed"
|
||||
raise Exception(message)
|
||||
except WindowsError:
|
||||
message = "Visual Studio wasn't installed"
|
||||
raise Exception(message)
|
||||
|
||||
for key in win32_proj_info.keys():
|
||||
output_dir = os.path.join(win32_proj_info[key]["outputdir"], "windows")
|
||||
for key in win32_proj_info.keys():
|
||||
output_dir = os.path.join(win32_proj_info[key]["outputdir"], "windows")
|
||||
|
||||
proj_path = os.path.join(self.repo_x, key)
|
||||
proj_path = os.path.join(self.repo_x, key)
|
||||
|
||||
vs_command, needUpgrade = get_vs_cmd_path(vs_reg, proj_path, self.vs_version)
|
||||
vs_command, needUpgrade = get_vs_cmd_path(vs_reg, proj_path, self.vs_version)
|
||||
|
||||
# get the build folder & win32 output folder
|
||||
build_folder_path = os.path.join(os.path.dirname(proj_path), "Release.win32")
|
||||
# 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)
|
||||
win32_output_dir = os.path.join(self.repo_x, output_dir)
|
||||
if not os.path.exists(win32_output_dir):
|
||||
os.makedirs(win32_output_dir)
|
||||
|
||||
# clean solution
|
||||
clean_cmd = " ".join([
|
||||
"\"%s\"" % vs_command,
|
||||
"\"%s\"" % proj_path,
|
||||
"/clean \"Release|Win32\""
|
||||
])
|
||||
execute_command(clean_cmd)
|
||||
# clean solution
|
||||
clean_cmd = " ".join([
|
||||
"\"%s\"" % vs_command,
|
||||
"\"%s\"" % proj_path,
|
||||
"/clean \"Release|Win32\""
|
||||
])
|
||||
execute_command(clean_cmd)
|
||||
|
||||
if self.use_incredibuild:
|
||||
# use incredibuild, build whole sln
|
||||
build_cmd = " ".join([
|
||||
"BuildConsole",
|
||||
"%s" % proj_path,
|
||||
"/build",
|
||||
"/cfg=\"Release|Win32\""
|
||||
])
|
||||
execute_command(build_cmd)
|
||||
else:
|
||||
for proj_name in win32_proj_info[key]["build_targets"]:
|
||||
# build the projects
|
||||
self.build_win32_proj(vs_command, proj_path, proj_name, "build")
|
||||
if self.use_incredibuild:
|
||||
# use incredibuild, build whole sln
|
||||
build_cmd = " ".join([
|
||||
"BuildConsole",
|
||||
"%s" % proj_path,
|
||||
"/build",
|
||||
"/cfg=\"Release|Win32\""
|
||||
])
|
||||
execute_command(build_cmd)
|
||||
else:
|
||||
for proj_name in win32_proj_info[key]["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)
|
||||
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")
|
||||
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)
|
||||
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
|
||||
# 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)
|
||||
file_path = os.path.join(build_folder_path, file_name)
|
||||
shutil.copy(file_path, win32_output_dir)
|
||||
|
||||
suffix = ""
|
||||
for proj_name in win32_proj_info[key]["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)
|
||||
suffix = ""
|
||||
for proj_name in win32_proj_info[key]["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.")
|
||||
|
||||
def compile_mac_ios(self):
|
||||
if not os_is_mac():
|
||||
print "this is not mac platform, needn't compile"
|
||||
return
|
||||
print "to compile mac"
|
||||
def compile_mac_ios(self):
|
||||
if not os_is_mac():
|
||||
print "this is not mac platform, needn't compile"
|
||||
return
|
||||
print "to compile mac"
|
||||
|
||||
xcode_proj_info = {
|
||||
"build/cocos2d_libs.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libcocos2d",
|
||||
},
|
||||
"cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libluacocos2d",
|
||||
},
|
||||
"cocos/scripting/js-bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libjscocos2d",
|
||||
},
|
||||
"tools/simulator/libsimulator/proj.ios_mac/libsimulator.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libsimulator",
|
||||
}
|
||||
}
|
||||
xcode_proj_info = {
|
||||
"build/cocos2d_libs.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libcocos2d",
|
||||
},
|
||||
"cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libluacocos2d",
|
||||
},
|
||||
"cocos/scripting/js-bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libjscocos2d",
|
||||
},
|
||||
"tools/simulator/libsimulator/proj.ios_mac/libsimulator.xcodeproj" : {
|
||||
"outputdir" : self.lib_dir,
|
||||
"targets" : "libsimulator",
|
||||
}
|
||||
}
|
||||
|
||||
XCODE_CMD_FMT = "xcodebuild -project \"%s\" -configuration Release -target \"%s\" %s CONFIGURATION_BUILD_DIR=%s"
|
||||
for key in xcode_proj_info.keys():
|
||||
output_dir = xcode_proj_info[key]["outputdir"]
|
||||
proj_path = os.path.join(self.repo_x, key)
|
||||
ios_out_dir = os.path.join(output_dir, "ios")
|
||||
mac_out_dir = os.path.join(output_dir, "mac")
|
||||
ios_sim_libs_dir = os.path.join(ios_out_dir, "simulator")
|
||||
ios_dev_libs_dir = os.path.join(ios_out_dir, "device")
|
||||
XCODE_CMD_FMT = "xcodebuild -project \"%s\" -configuration Release -target \"%s\" %s CONFIGURATION_BUILD_DIR=%s"
|
||||
for key in xcode_proj_info.keys():
|
||||
output_dir = xcode_proj_info[key]["outputdir"]
|
||||
proj_path = os.path.join(self.repo_x, key)
|
||||
ios_out_dir = os.path.join(output_dir, "ios")
|
||||
mac_out_dir = os.path.join(output_dir, "mac")
|
||||
ios_sim_libs_dir = os.path.join(ios_out_dir, "simulator")
|
||||
ios_dev_libs_dir = os.path.join(ios_out_dir, "device")
|
||||
|
||||
target = xcode_proj_info[key]["targets"]
|
||||
target = xcode_proj_info[key]["targets"]
|
||||
|
||||
# compile ios simulator
|
||||
build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphonesimulator ARCHS=\"i386 x86_64\" VALID_ARCHS=\"i386 x86_64\"", ios_sim_libs_dir)
|
||||
retVal = execute_command(build_cmd)
|
||||
if 0 != retVal:
|
||||
print "[ERROR] compile ios simulator fail"
|
||||
return retVal
|
||||
# compile ios simulator
|
||||
build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphonesimulator ARCHS=\"i386 x86_64\" VALID_ARCHS=\"i386 x86_64\"", ios_sim_libs_dir)
|
||||
retVal = execute_command(build_cmd)
|
||||
if 0 != retVal:
|
||||
print "[ERROR] compile ios simulator fail"
|
||||
return retVal
|
||||
|
||||
# compile ios device
|
||||
build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphoneos", ios_dev_libs_dir)
|
||||
retVal = execute_command(build_cmd)
|
||||
if 0 != retVal:
|
||||
print "[ERROR] compile ios device fail"
|
||||
return retVal
|
||||
# compile ios device
|
||||
build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphoneos", ios_dev_libs_dir)
|
||||
retVal = execute_command(build_cmd)
|
||||
if 0 != retVal:
|
||||
print "[ERROR] compile ios device fail"
|
||||
return retVal
|
||||
|
||||
# compile mac
|
||||
build_cmd = XCODE_CMD_FMT % (proj_path, "%s Mac" % target, "", mac_out_dir)
|
||||
retVal = execute_command(build_cmd)
|
||||
if 0 != retVal:
|
||||
print "[ERROR] compile mac fail"
|
||||
return retVal
|
||||
# compile mac
|
||||
build_cmd = XCODE_CMD_FMT % (proj_path, "%s Mac" % target, "", mac_out_dir)
|
||||
retVal = execute_command(build_cmd)
|
||||
if 0 != retVal:
|
||||
print "[ERROR] compile mac fail"
|
||||
return retVal
|
||||
|
||||
# generate fat libs for iOS
|
||||
for lib in os.listdir(ios_sim_libs_dir):
|
||||
sim_lib = os.path.join(ios_sim_libs_dir, lib)
|
||||
dev_lib = os.path.join(ios_dev_libs_dir, lib)
|
||||
output_lib = os.path.join(ios_out_dir, lib)
|
||||
lipo_cmd = "lipo -create -output \"%s\" \"%s\" \"%s\"" % (output_lib, sim_lib, dev_lib)
|
||||
# generate fat libs for iOS
|
||||
for lib in os.listdir(ios_sim_libs_dir):
|
||||
sim_lib = os.path.join(ios_sim_libs_dir, lib)
|
||||
dev_lib = os.path.join(ios_dev_libs_dir, lib)
|
||||
output_lib = os.path.join(ios_out_dir, lib)
|
||||
lipo_cmd = "lipo -create -output \"%s\" \"%s\" \"%s\"" % (output_lib, sim_lib, dev_lib)
|
||||
|
||||
execute_command(lipo_cmd)
|
||||
execute_command(lipo_cmd)
|
||||
|
||||
# remove the simulator & device libs in iOS
|
||||
rmdir(ios_sim_libs_dir)
|
||||
rmdir(ios_dev_libs_dir)
|
||||
# remove the simulator & device libs in iOS
|
||||
rmdir(ios_sim_libs_dir)
|
||||
rmdir(ios_dev_libs_dir)
|
||||
|
||||
if not self.disable_strip:
|
||||
# strip the libs
|
||||
ios_strip_cmd = "xcrun -sdk iphoneos strip -S %s/*.a" % ios_out_dir
|
||||
execute_command(ios_strip_cmd)
|
||||
mac_strip_cmd = "xcrun strip -S %s/*.a" % mac_out_dir
|
||||
execute_command(mac_strip_cmd)
|
||||
if not self.disable_strip:
|
||||
# strip the libs
|
||||
ios_strip_cmd = "xcrun -sdk iphoneos strip -S %s/*.a" % ios_out_dir
|
||||
execute_command(ios_strip_cmd)
|
||||
mac_strip_cmd = "xcrun strip -S %s/*.a" % mac_out_dir
|
||||
execute_command(mac_strip_cmd)
|
||||
|
||||
def compile_android(self, language):
|
||||
print "compile android"
|
||||
# build .so for android
|
||||
CONSOLE_PATH = "tools/cocos2d-console/bin"
|
||||
SCRIPT_MK_PATH = "frameworks/runtime-src/proj.android/jni/Application.mk"
|
||||
ANDROID_A_PATH = "frameworks/runtime-src/proj.android/obj/local"
|
||||
def compile_android(self, language):
|
||||
print "compile android"
|
||||
# build .so for android
|
||||
CONSOLE_PATH = "tools/cocos2d-console/bin"
|
||||
SCRIPT_MK_PATH = "frameworks/runtime-src/proj.android/jni/Application.mk"
|
||||
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 os_is_win32():
|
||||
cmd_path = os.path.join(console_dir, "cocos.bat")
|
||||
else:
|
||||
cmd_path = os.path.join(console_dir, "cocos")
|
||||
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 os_is_win32():
|
||||
cmd_path = os.path.join(console_dir, "cocos.bat")
|
||||
else:
|
||||
cmd_path = os.path.join(console_dir, "cocos")
|
||||
|
||||
proj_name = "My%sGame" % language
|
||||
proj_dir = os.path.join(self.cur_dir, "temp")
|
||||
proj_path = os.path.join(proj_dir, proj_name)
|
||||
rmdir(proj_path)
|
||||
proj_name = "My%sGame" % language
|
||||
proj_dir = os.path.join(self.cur_dir, "temp")
|
||||
proj_path = os.path.join(proj_dir, proj_name)
|
||||
rmdir(proj_path)
|
||||
|
||||
# create a runtime project
|
||||
create_cmd = "%s new -l %s -t runtime -d %s %s" % (cmd_path, language, proj_dir, proj_name)
|
||||
execute_command(create_cmd)
|
||||
# create a runtime project
|
||||
create_cmd = "%s new -l %s -t runtime -d %s %s" % (cmd_path, language, proj_dir, proj_name)
|
||||
execute_command(create_cmd)
|
||||
|
||||
# Add multi ABI in Application.mk
|
||||
mk_file = os.path.join(proj_path, SCRIPT_MK_PATH)
|
||||
self.modify_mk(mk_file)
|
||||
# Add multi ABI in Application.mk
|
||||
mk_file = os.path.join(proj_path, SCRIPT_MK_PATH)
|
||||
self.modify_mk(mk_file)
|
||||
|
||||
# build it
|
||||
build_cmd = "%s compile -s %s -p android --ndk-mode release -j 4" % (cmd_path, proj_path)
|
||||
execute_command(build_cmd)
|
||||
# build it
|
||||
build_cmd = "%s compile -s %s -p android --ndk-mode release -j 4" % (cmd_path, proj_path)
|
||||
execute_command(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$"
|
||||
]
|
||||
}
|
||||
excopy.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)
|
||||
# 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$"
|
||||
]
|
||||
}
|
||||
excopy.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 os_is_win32():
|
||||
if is_32bit_windows():
|
||||
bit_str = ""
|
||||
else:
|
||||
bit_str = "-x86_64"
|
||||
sys_folder_name = "windows%s" % bit_str
|
||||
elif os_is_mac():
|
||||
sys_folder_name = "darwin-x86_64"
|
||||
if not self.disable_strip:
|
||||
# strip the android libs
|
||||
ndk_root = os.environ["NDK_ROOT"]
|
||||
if os_is_win32():
|
||||
if is_32bit_windows():
|
||||
bit_str = ""
|
||||
else:
|
||||
bit_str = "-x86_64"
|
||||
sys_folder_name = "windows%s" % bit_str
|
||||
elif os_is_mac():
|
||||
sys_folder_name = "darwin-x86_64"
|
||||
|
||||
# set strip execute file name
|
||||
if os_is_win32():
|
||||
strip_execute_name = "strip.exe"
|
||||
else:
|
||||
strip_execute_name = "strip"
|
||||
# set strip execute file name
|
||||
if 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 not os.path.exists(strip_cmd_path):
|
||||
strip_cmd_path = os.path.join(ndk_root, "toolchains/arm-linux-androideabi-4.8/prebuilt/%s/arm-linux-androideabi/bin/%s"
|
||||
% (sys_folder_name.replace(bit_str, ""), strip_execute_name))
|
||||
if os.path.exists(strip_cmd_path):
|
||||
armlibs = ["armeabi", "armeabi-v7a"]
|
||||
for fold in armlibs:
|
||||
self.trip_libs(strip_cmd_path, "%s/%s" % (android_out_dir, fold))
|
||||
# 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 not os.path.exists(strip_cmd_path):
|
||||
strip_cmd_path = os.path.join(ndk_root, "toolchains/arm-linux-androideabi-4.8/prebuilt/%s/arm-linux-androideabi/bin/%s"
|
||||
% (sys_folder_name.replace(bit_str, ""), strip_execute_name))
|
||||
if os.path.exists(strip_cmd_path):
|
||||
armlibs = ["armeabi", "armeabi-v7a"]
|
||||
for fold in armlibs:
|
||||
self.trip_libs(strip_cmd_path, "%s/%s" % (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, "%s/x86" % android_out_dir)
|
||||
# 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, "%s/x86" % android_out_dir)
|
||||
|
||||
# remove the project
|
||||
rmdir(proj_path)
|
||||
# remove the project
|
||||
rmdir(proj_path)
|
||||
|
||||
def trip_libs(self, strip_cmd, folder):
|
||||
if os_is_win32():
|
||||
for name in os.listdir(folder):
|
||||
if name[-2:] != ".a":
|
||||
pass
|
||||
full_name = os.path.join(folder, name)
|
||||
command = "%s -S %s" % (strip_cmd, full_name)
|
||||
execute_command(command)
|
||||
else:
|
||||
strip_cmd = "%s -S %s/*.a" % (strip_cmd, folder)
|
||||
execute_command(strip_cmd)
|
||||
def trip_libs(self, strip_cmd, folder):
|
||||
if os_is_win32():
|
||||
for name in os.listdir(folder):
|
||||
if name[-2:] != ".a":
|
||||
pass
|
||||
full_name = os.path.join(folder, name)
|
||||
command = "%s -S %s" % (strip_cmd, full_name)
|
||||
execute_command(command)
|
||||
else:
|
||||
strip_cmd = "%s -S %s/*.a" % (strip_cmd, folder)
|
||||
execute_command(strip_cmd)
|
||||
|
||||
|
||||
def modify_mk(self, mk_file):
|
||||
if os.path.isfile(mk_file):
|
||||
file_obj = open(mk_file, "a")
|
||||
file_obj.write("\nAPP_ABI :=armeabi armeabi-v7a x86\n")
|
||||
file_obj.close()
|
||||
def modify_mk(self, mk_file):
|
||||
if os.path.isfile(mk_file):
|
||||
file_obj = open(mk_file, "a")
|
||||
file_obj.write("\nAPP_ABI :=armeabi armeabi-v7a x86\n")
|
||||
file_obj.close()
|
||||
|
||||
def clean_libs(self):
|
||||
print "to clean libs"
|
||||
rmdir(self.lib_dir)
|
||||
def clean_libs(self):
|
||||
print "to clean libs"
|
||||
rmdir(self.lib_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = ArgumentParser(description="Generate prebuilt engine for Cocos Engine.")
|
||||
parser.add_argument('-c', dest='clean', action="store_true", help='clean libs folder')
|
||||
parser.add_argument('-all', dest='all', action="store_true", help='compile all platform')
|
||||
parser.add_argument('--win', dest='win', action="store_true", help='compile windows platform')
|
||||
parser.add_argument('--mac', dest='mac', action="store_true", help='compile mac platform')
|
||||
parser.add_argument('--android', dest='android', action="store_true",help='complile android platform')
|
||||
parser.add_argument('--dis-strip', "--disable-strip", dest='disable_strip', action="store_true", help='Disable the strip of the generated libs.')
|
||||
parser.add_argument('--repo-x', dest='repo_x', help='Set the repo path of cocos2d-x.')
|
||||
parser.add_argument('--vs', dest='vs_version', help='visual studio version, such as 2013.', default=2013)
|
||||
parser = ArgumentParser(description="Generate prebuilt engine for Cocos Engine.")
|
||||
parser.add_argument('-c', dest='clean', action="store_true", help='clean libs folder')
|
||||
parser.add_argument('-all', dest='all', action="store_true", help='compile all platform')
|
||||
parser.add_argument('--win', dest='win', action="store_true", help='compile windows platform')
|
||||
parser.add_argument('--mac', dest='mac', action="store_true", help='compile mac platform')
|
||||
parser.add_argument('--android', dest='android', action="store_true",help='complile android platform')
|
||||
parser.add_argument('--dis-strip', "--disable-strip", dest='disable_strip', action="store_true", help='Disable the strip of the generated libs.')
|
||||
parser.add_argument('--repo-x', dest='repo_x', help='Set the repo path of cocos2d-x.')
|
||||
parser.add_argument('--vs', dest='vs_version', help='visual studio version, such as 2013.', default=2013)
|
||||
|
||||
(args, unknown) = parser.parse_known_args()
|
||||
(args, unknown) = parser.parse_known_args()
|
||||
|
||||
if len(unknown) > 0:
|
||||
print("unknown arguments: %s" % unknown)
|
||||
if len(unknown) > 0:
|
||||
print("unknown arguments: %s" % unknown)
|
||||
|
||||
if args.repo_x is None:
|
||||
print("ERROR! must set repo of cocos2d-x")
|
||||
exit(1)
|
||||
if not args.win and not args.mac and not args.android:
|
||||
args.all = True
|
||||
if args.repo_x is None:
|
||||
print("ERROR! must set repo of cocos2d-x")
|
||||
exit(1)
|
||||
if not args.win and not args.mac and not args.android:
|
||||
args.all = True
|
||||
|
||||
beginSecond = time.time()
|
||||
print ">>> Bgein Compile at %s" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(beginSecond))
|
||||
beginSecond = time.time()
|
||||
print ">>> Bgein Compile at %s" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(beginSecond))
|
||||
|
||||
compiler = CocosLibsCompiler(args)
|
||||
compiler.compile()
|
||||
compiler = CocosLibsCompiler(args)
|
||||
compiler.compile()
|
||||
|
||||
endSecond = time.time()
|
||||
print ">>> Bgein Compile at %s" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(beginSecond))
|
||||
print ">>> End Compile at %s" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(endSecond))
|
||||
interSecond = endSecond - beginSecond
|
||||
interSecond = int(interSecond)
|
||||
print ">>> Use Second %d" % interSecond
|
||||
houre = interSecond/(60*60)
|
||||
interSecond = interSecond%(60*60)
|
||||
minute = interSecond/60
|
||||
second = interSecond%60
|
||||
print ">>> Use Time %d:%d:%d" % (houre, minute, second)
|
||||
endSecond = time.time()
|
||||
print ">>> Bgein Compile at %s" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(beginSecond))
|
||||
print ">>> End Compile at %s" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(endSecond))
|
||||
interSecond = endSecond - beginSecond
|
||||
interSecond = int(interSecond)
|
||||
print ">>> Use Second %d" % interSecond
|
||||
houre = interSecond/(60*60)
|
||||
interSecond = interSecond%(60*60)
|
||||
minute = interSecond/60
|
||||
second = interSecond%60
|
||||
print ">>> Use Time %d:%d:%d" % (houre, minute, second)
|
||||
|
||||
|
|
|
@ -410,13 +410,13 @@ class PBXTargetDependency(PBXType):
|
|||
|
||||
|
||||
class PBXAggregateTarget(PBXType):
|
||||
pass
|
||||
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class PBXHeadersBuildPhase(PBXType):
|
||||
pass
|
||||
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class PBXBuildPhase(PBXType):
|
||||
def add_build_file(self, bf):
|
||||
if bf.get('isa') != 'PBXBuildFile':
|
||||
|
@ -1956,7 +1956,7 @@ class XcodeProject(PBXDict):
|
|||
|
||||
@classmethod
|
||||
def LoadFromXML(cls, path):
|
||||
tree = plistlib.readPlist(path)
|
||||
tree = plistlib.readPlist(path)
|
||||
return XcodeProject(tree, path)
|
||||
|
||||
|
||||
|
|
|
@ -4,219 +4,219 @@ import sys
|
|||
from xml.dom import minidom
|
||||
|
||||
def os_is_win32():
|
||||
return sys.platform == 'win32'
|
||||
return sys.platform == 'win32'
|
||||
|
||||
def os_is_mac():
|
||||
return sys.platform == 'darwin'
|
||||
return sys.platform == 'darwin'
|
||||
|
||||
class VCXProject(object):
|
||||
def __init__(self, proj_file_path):
|
||||
self.xmldoc = minidom.parse(proj_file_path)
|
||||
self.root_node = self.xmldoc.documentElement
|
||||
if os.path.isabs(proj_file_path):
|
||||
self.file_path = proj_file_path
|
||||
else:
|
||||
self.file_path = os.path.abspath(proj_file_path)
|
||||
def __init__(self, proj_file_path):
|
||||
self.xmldoc = minidom.parse(proj_file_path)
|
||||
self.root_node = self.xmldoc.documentElement
|
||||
if os.path.isabs(proj_file_path):
|
||||
self.file_path = proj_file_path
|
||||
else:
|
||||
self.file_path = os.path.abspath(proj_file_path)
|
||||
|
||||
def get_or_create_node(self, parent, node_name):
|
||||
children = parent.getElementsByTagName(node_name)
|
||||
if len(children) > 0:
|
||||
return children[0]
|
||||
else:
|
||||
child = parent.createElement(node_name)
|
||||
return child
|
||||
def get_or_create_node(self, parent, node_name):
|
||||
children = parent.getElementsByTagName(node_name)
|
||||
if len(children) > 0:
|
||||
return children[0]
|
||||
else:
|
||||
child = parent.createElement(node_name)
|
||||
return child
|
||||
|
||||
def save(self, new_path=None):
|
||||
if new_path is None:
|
||||
savePath = self.file_path
|
||||
else:
|
||||
if os.path.isabs(new_path):
|
||||
savePath = new_path
|
||||
else:
|
||||
savePath = os.path.abspath(new_path)
|
||||
def save(self, new_path=None):
|
||||
if new_path is None:
|
||||
savePath = self.file_path
|
||||
else:
|
||||
if os.path.isabs(new_path):
|
||||
savePath = new_path
|
||||
else:
|
||||
savePath = os.path.abspath(new_path)
|
||||
|
||||
print("Saving the vcxproj to %s" % savePath)
|
||||
print("Saving the vcxproj to %s" % savePath)
|
||||
|
||||
if not os.path.isabs(savePath):
|
||||
savePath = os.path.abspath(savePath)
|
||||
if not os.path.isabs(savePath):
|
||||
savePath = os.path.abspath(savePath)
|
||||
|
||||
file_obj = open(savePath, "w")
|
||||
self.xmldoc.writexml(file_obj, encoding="utf-8")
|
||||
file_obj.close()
|
||||
file_obj = open(savePath, "w")
|
||||
self.xmldoc.writexml(file_obj, encoding="utf-8")
|
||||
file_obj.close()
|
||||
|
||||
file_obj = open(savePath, "r")
|
||||
file_content = file_obj.read()
|
||||
file_obj.close()
|
||||
file_obj = open(savePath, "r")
|
||||
file_content = file_obj.read()
|
||||
file_obj.close()
|
||||
|
||||
file_content = file_content.replace(""", "\"")
|
||||
file_content = file_content.replace("/>", " />")
|
||||
file_content = file_content.replace(""", "\"")
|
||||
file_content = file_content.replace("/>", " />")
|
||||
|
||||
if os_is_mac():
|
||||
file_content = file_content.replace("\n", "\r\n")
|
||||
if os_is_mac():
|
||||
file_content = file_content.replace("\n", "\r\n")
|
||||
|
||||
file_content = file_content.replace("?><", "?>\r\n<")
|
||||
file_content = file_content.replace("?><", "?>\r\n<")
|
||||
|
||||
file_obj = open(savePath, "w")
|
||||
file_obj.write(file_content)
|
||||
file_obj.close()
|
||||
file_obj = open(savePath, "w")
|
||||
file_obj.write(file_content)
|
||||
file_obj.close()
|
||||
|
||||
print("Saving Finished")
|
||||
print("Saving Finished")
|
||||
|
||||
def remove_lib(self, lib_name):
|
||||
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"
|
||||
def remove_lib(self, lib_name):
|
||||
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"
|
||||
|
||||
# remove the linked lib config
|
||||
link_node = self.get_or_create_node(cfg_node, "Link")
|
||||
depends_node = self.get_or_create_node(link_node, "AdditionalDependencies")
|
||||
link_info = depends_node.firstChild.nodeValue
|
||||
cur_libs = link_info.split(";")
|
||||
link_modified = False
|
||||
# remove the linked lib config
|
||||
link_node = self.get_or_create_node(cfg_node, "Link")
|
||||
depends_node = self.get_or_create_node(link_node, "AdditionalDependencies")
|
||||
link_info = depends_node.firstChild.nodeValue
|
||||
cur_libs = link_info.split(";")
|
||||
link_modified = False
|
||||
|
||||
if lib_name in cur_libs:
|
||||
print("Remove linked library %s from \"%s\" configuration" % (lib_name, cur_mode))
|
||||
cur_libs.remove(lib_name)
|
||||
link_modified = True
|
||||
if lib_name in cur_libs:
|
||||
print("Remove linked library %s from \"%s\" configuration" % (lib_name, cur_mode))
|
||||
cur_libs.remove(lib_name)
|
||||
link_modified = True
|
||||
|
||||
if link_modified:
|
||||
link_info = ";".join(cur_libs)
|
||||
depends_node.firstChild.nodeValue = link_info
|
||||
if link_modified:
|
||||
link_info = ";".join(cur_libs)
|
||||
depends_node.firstChild.nodeValue = link_info
|
||||
|
||||
def add_lib(self, lib_name):
|
||||
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"
|
||||
def add_lib(self, lib_name):
|
||||
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"
|
||||
|
||||
# add the linked lib config
|
||||
link_node = self.get_or_create_node(cfg_node, "Link")
|
||||
depends_node = self.get_or_create_node(link_node, "AdditionalDependencies")
|
||||
link_info = depends_node.firstChild.nodeValue
|
||||
cur_libs = link_info.split(";")
|
||||
link_modified = False
|
||||
if lib_name not in cur_libs:
|
||||
print("Add linked library %s for \"%s\" configuration" % (lib_name, cur_mode))
|
||||
cur_libs.insert(0, lib_name)
|
||||
link_modified = True
|
||||
# add the linked lib config
|
||||
link_node = self.get_or_create_node(cfg_node, "Link")
|
||||
depends_node = self.get_or_create_node(link_node, "AdditionalDependencies")
|
||||
link_info = depends_node.firstChild.nodeValue
|
||||
cur_libs = link_info.split(";")
|
||||
link_modified = False
|
||||
if lib_name not in cur_libs:
|
||||
print("Add linked library %s for \"%s\" configuration" % (lib_name, cur_mode))
|
||||
cur_libs.insert(0, lib_name)
|
||||
link_modified = True
|
||||
|
||||
if link_modified:
|
||||
link_info = ";".join(cur_libs)
|
||||
depends_node.firstChild.nodeValue = link_info
|
||||
if link_modified:
|
||||
link_info = ";".join(cur_libs)
|
||||
depends_node.firstChild.nodeValue = link_info
|
||||
|
||||
def get_event_command(self, event, config):
|
||||
cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup")
|
||||
ret = ""
|
||||
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"
|
||||
def get_event_command(self, event, config):
|
||||
cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup")
|
||||
ret = ""
|
||||
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 cur_mode.lower() != config.lower():
|
||||
continue
|
||||
if cur_mode.lower() != config.lower():
|
||||
continue
|
||||
|
||||
event_nodes = cfg_node.getElementsByTagName(event)
|
||||
if len(event_nodes) <= 0:
|
||||
continue
|
||||
event_nodes = cfg_node.getElementsByTagName(event)
|
||||
if len(event_nodes) <= 0:
|
||||
continue
|
||||
|
||||
event_node = event_nodes[0]
|
||||
cmd_nodes = event_node.getElementsByTagName("Command")
|
||||
if len(cmd_nodes) <= 0:
|
||||
continue
|
||||
event_node = event_nodes[0]
|
||||
cmd_nodes = event_node.getElementsByTagName("Command")
|
||||
if len(cmd_nodes) <= 0:
|
||||
continue
|
||||
|
||||
cmd_node = cmd_nodes[0]
|
||||
ret = cmd_node.firstChild.nodeValue
|
||||
break
|
||||
cmd_node = cmd_nodes[0]
|
||||
ret = cmd_node.firstChild.nodeValue
|
||||
break
|
||||
|
||||
return ret
|
||||
return ret
|
||||
|
||||
def set_event_command(self, event, command, 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"
|
||||
def set_event_command(self, event, command, 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) and (cur_mode.lower() != config.lower()):
|
||||
continue
|
||||
if (config is not None) and (cur_mode.lower() != config.lower()):
|
||||
continue
|
||||
|
||||
event_node = self.get_or_create_node(cfg_node, event)
|
||||
cmd_node = self.get_or_create_node(event_node, "Command")
|
||||
cmd_node.firstChild.nodeValue = command
|
||||
event_node = self.get_or_create_node(cfg_node, event)
|
||||
cmd_node = self.get_or_create_node(event_node, "Command")
|
||||
cmd_node.firstChild.nodeValue = command
|
||||
|
||||
def get_node_if(self, parent, name):
|
||||
children = parent.getElementsByTagName(name)
|
||||
child = None
|
||||
if len(children) > 0:
|
||||
child = children[0]
|
||||
else:
|
||||
child = self.xmldoc.createElement(name)
|
||||
parent.appendChild(child)
|
||||
return child
|
||||
def get_node_if(self, parent, name):
|
||||
children = parent.getElementsByTagName(name)
|
||||
child = None
|
||||
if len(children) > 0:
|
||||
child = children[0]
|
||||
else:
|
||||
child = self.xmldoc.createElement(name)
|
||||
parent.appendChild(child)
|
||||
return child
|
||||
|
||||
def set_item(self, event, eventItem, command):
|
||||
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"
|
||||
def set_item(self, event, eventItem, command):
|
||||
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"
|
||||
|
||||
print "event: %s" % event
|
||||
event_node = self.get_node_if(cfg_node, event)
|
||||
cmd_node = self.get_node_if(event_node, eventItem)
|
||||
text_node = self.xmldoc.createTextNode(command)
|
||||
cmd_node.appendChild(text_node)
|
||||
print "event: %s" % event
|
||||
event_node = self.get_node_if(cfg_node, event)
|
||||
cmd_node = self.get_node_if(event_node, eventItem)
|
||||
text_node = self.xmldoc.createTextNode(command)
|
||||
cmd_node.appendChild(text_node)
|
||||
|
||||
def set_include_dirs(self, paths):
|
||||
if "%(AdditionalIncludeDirectories)" not in paths:
|
||||
paths.append("%(AdditionalIncludeDirectories)")
|
||||
def set_include_dirs(self, paths):
|
||||
if "%(AdditionalIncludeDirectories)" not in paths:
|
||||
paths.append("%(AdditionalIncludeDirectories)")
|
||||
|
||||
include_value = ";".join(paths)
|
||||
include_value = include_value.replace("/", "\\")
|
||||
cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup")
|
||||
for cfg_node in cfg_nodes:
|
||||
compile_node = self.get_or_create_node(cfg_node, "ClCompile")
|
||||
include_node = self.get_or_create_node(compile_node, "AdditionalIncludeDirectories")
|
||||
include_node.firstChild.nodeValue = include_value
|
||||
include_value = ";".join(paths)
|
||||
include_value = include_value.replace("/", "\\")
|
||||
cfg_nodes = self.root_node.getElementsByTagName("ItemDefinitionGroup")
|
||||
for cfg_node in cfg_nodes:
|
||||
compile_node = self.get_or_create_node(cfg_node, "ClCompile")
|
||||
include_node = self.get_or_create_node(compile_node, "AdditionalIncludeDirectories")
|
||||
include_node.firstChild.nodeValue = include_value
|
||||
|
||||
def remove_proj_reference(self):
|
||||
itemgroups = self.root_node.getElementsByTagName("ItemGroup")
|
||||
for item in itemgroups:
|
||||
proj_refers = item.getElementsByTagName("ProjectReference")
|
||||
if len(proj_refers) > 0:
|
||||
self.root_node.removeChild(item)
|
||||
def remove_proj_reference(self):
|
||||
itemgroups = self.root_node.getElementsByTagName("ItemGroup")
|
||||
for item in itemgroups:
|
||||
proj_refers = item.getElementsByTagName("ProjectReference")
|
||||
if len(proj_refers) > 0:
|
||||
self.root_node.removeChild(item)
|
||||
|
||||
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"
|
||||
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) and (cur_mode.lower() != config.lower()):
|
||||
continue
|
||||
if (config is not None) and (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")
|
||||
defined_values = predefine_node.firstChild.nodeValue
|
||||
compile_node = self.get_or_create_node(cfg_node, "ClCompile")
|
||||
predefine_node = self.get_or_create_node(compile_node, "PreprocessorDefinitions")
|
||||
defined_values = predefine_node.firstChild.nodeValue
|
||||
|
||||
defined_list = defined_values.split(";")
|
||||
if macro in defined_list:
|
||||
defined_list.remove(macro)
|
||||
new_value = ";".join(defined_list)
|
||||
predefine_node.firstChild.nodeValue = new_value
|
||||
defined_list = defined_values.split(";")
|
||||
if macro in defined_list:
|
||||
defined_list.remove(macro)
|
||||
new_value = ";".join(defined_list)
|
||||
predefine_node.firstChild.nodeValue = new_value
|
||||
|
|
|
@ -6,181 +6,181 @@ import sys
|
|||
import shutil
|
||||
|
||||
if sys.platform == 'win32':
|
||||
import _winreg
|
||||
import _winreg
|
||||
|
||||
def execute_command(cmdstring, cwd=None, timeout=None, shell=True):
|
||||
""" 执行一个SHELL命令
|
||||
封装了subprocess的Popen方法, 支持超时判断,支持读取stdout和stderr
|
||||
参数:
|
||||
cwd: 运行命令时更改路径,如果被设定,子进程会直接先更改当前路径到cwd
|
||||
timeout: 超时时间,秒,支持小数,精度0.1秒
|
||||
shell: 是否通过shell运行
|
||||
Returns: return_code
|
||||
Raises: Exception: 执行超时
|
||||
"""
|
||||
""" 执行一个SHELL命令
|
||||
封装了subprocess的Popen方法, 支持超时判断,支持读取stdout和stderr
|
||||
参数:
|
||||
cwd: 运行命令时更改路径,如果被设定,子进程会直接先更改当前路径到cwd
|
||||
timeout: 超时时间,秒,支持小数,精度0.1秒
|
||||
shell: 是否通过shell运行
|
||||
Returns: return_code
|
||||
Raises: Exception: 执行超时
|
||||
"""
|
||||
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import time
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
#if os_is_win32():
|
||||
# cmdstring = convert_to_python_path(cmdstring)
|
||||
#if os_is_win32():
|
||||
# cmdstring = convert_to_python_path(cmdstring)
|
||||
|
||||
print("")
|
||||
print("Execute command:")
|
||||
print(cmdstring)
|
||||
print("")
|
||||
print("")
|
||||
print("Execute command:")
|
||||
print(cmdstring)
|
||||
print("")
|
||||
|
||||
if shell:
|
||||
cmdstring_list = cmdstring
|
||||
else:
|
||||
cmdstring_list = shlex.split(cmdstring)
|
||||
if timeout:
|
||||
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
|
||||
if shell:
|
||||
cmdstring_list = cmdstring
|
||||
else:
|
||||
cmdstring_list = shlex.split(cmdstring)
|
||||
if timeout:
|
||||
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
|
||||
|
||||
# 没有指定标准输出和错误输出的管道,因此会打印到屏幕上
|
||||
sub = None
|
||||
try:
|
||||
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE, shell=shell, bufsize=4096)
|
||||
except Exception, e:
|
||||
print "execute command fail:%s" % cmdstring
|
||||
raise e
|
||||
# 没有指定标准输出和错误输出的管道,因此会打印到屏幕上
|
||||
sub = None
|
||||
try:
|
||||
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE, shell=shell, bufsize=4096)
|
||||
except Exception, e:
|
||||
print "execute command fail:%s" % cmdstring
|
||||
raise e
|
||||
|
||||
# subprocess.poll()方法:检查子进程是否结束了,如果结束了,设定并返回码,放在subprocess.returncode变量中
|
||||
while sub.poll() is None:
|
||||
time.sleep(0.1)
|
||||
if timeout:
|
||||
if end_time <= datetime.datetime.now():
|
||||
raise Exception("Timeout:%s"%cmdstring)
|
||||
# subprocess.poll()方法:检查子进程是否结束了,如果结束了,设定并返回码,放在subprocess.returncode变量中
|
||||
while sub.poll() is None:
|
||||
time.sleep(0.1)
|
||||
if timeout:
|
||||
if end_time <= datetime.datetime.now():
|
||||
raise Exception("Timeout:%s"%cmdstring)
|
||||
|
||||
if 0 != sub.returncode :
|
||||
errStr = "[ERROR] execute command fail:%s" % cmdstring
|
||||
print errStr
|
||||
raise Exception(errStr)
|
||||
if 0 != sub.returncode :
|
||||
errStr = "[ERROR] execute command fail:%s" % cmdstring
|
||||
print errStr
|
||||
raise Exception(errStr)
|
||||
|
||||
return sub.returncode
|
||||
return sub.returncode
|
||||
|
||||
def get_required_vs_version(proj_file):
|
||||
# Now VS2012 is the mini version required
|
||||
return "11.0"
|
||||
# Now VS2012 is the mini version required
|
||||
return "11.0"
|
||||
|
||||
def get_vs_cmd_path(vs_reg, proj_path, vs_version):
|
||||
# get required vs version
|
||||
required_vs_version = get_required_vs_version(proj_path)
|
||||
if required_vs_version is None:
|
||||
raise Exception("Can't parse the sln file to find required VS version")
|
||||
# get required vs version
|
||||
required_vs_version = get_required_vs_version(proj_path)
|
||||
if required_vs_version is None:
|
||||
raise Exception("Can't parse the sln file to find required VS version")
|
||||
|
||||
# get the correct available VS path
|
||||
needUpgrade = False
|
||||
vsPath = None
|
||||
# get the correct available VS path
|
||||
needUpgrade = False
|
||||
vsPath = None
|
||||
|
||||
if vs_version is None:
|
||||
i = 0
|
||||
try:
|
||||
while True:
|
||||
version = _winreg.EnumKey(vs_reg, i)
|
||||
try:
|
||||
if float(version) >= float(required_vs_version):
|
||||
key = _winreg.OpenKey(vs_reg, r"SxS\VS7")
|
||||
vsPath, type = _winreg.QueryValueEx(key, version)
|
||||
if vs_version is None:
|
||||
i = 0
|
||||
try:
|
||||
while True:
|
||||
version = _winreg.EnumKey(vs_reg, i)
|
||||
try:
|
||||
if float(version) >= float(required_vs_version):
|
||||
key = _winreg.OpenKey(vs_reg, r"SxS\VS7")
|
||||
vsPath, type = _winreg.QueryValueEx(key, version)
|
||||
|
||||
if float(version) > float(required_vs_version):
|
||||
needUpgrade = True
|
||||
if float(version) > float(required_vs_version):
|
||||
needUpgrade = True
|
||||
|
||||
key.close()
|
||||
break
|
||||
except:
|
||||
pass
|
||||
i += 1
|
||||
except WindowsError:
|
||||
pass
|
||||
else:
|
||||
if vs_version == 2012:
|
||||
vs_ver = "11.0"
|
||||
needUpgrade = False
|
||||
else:
|
||||
vs_ver = "12.0"
|
||||
needUpgrade = True
|
||||
key.close()
|
||||
break
|
||||
except:
|
||||
pass
|
||||
i += 1
|
||||
except WindowsError:
|
||||
pass
|
||||
else:
|
||||
if vs_version == 2012:
|
||||
vs_ver = "11.0"
|
||||
needUpgrade = False
|
||||
else:
|
||||
vs_ver = "12.0"
|
||||
needUpgrade = True
|
||||
|
||||
try:
|
||||
key = _winreg.OpenKey(vs_reg, r"SxS\VS7")
|
||||
vsPath, type = _winreg.QueryValueEx(key, vs_ver)
|
||||
except:
|
||||
raise Exception("Can't find VS%d" % vs_version)
|
||||
try:
|
||||
key = _winreg.OpenKey(vs_reg, r"SxS\VS7")
|
||||
vsPath, type = _winreg.QueryValueEx(key, vs_ver)
|
||||
except:
|
||||
raise Exception("Can't find VS%d" % vs_version)
|
||||
|
||||
if vsPath is None:
|
||||
message = "Can't find correct Visual Studio's path in the regedit"
|
||||
raise Exception(message)
|
||||
if vsPath is None:
|
||||
message = "Can't find correct Visual Studio's path in the regedit"
|
||||
raise Exception(message)
|
||||
|
||||
commandPath = os.path.join(vsPath, "Common7", "IDE", "devenv")
|
||||
return (commandPath, needUpgrade)
|
||||
commandPath = os.path.join(vsPath, "Common7", "IDE", "devenv")
|
||||
return (commandPath, needUpgrade)
|
||||
|
||||
def rmdir(folder):
|
||||
if os.path.exists(folder):
|
||||
if sys.platform == 'win32':
|
||||
execute_command("rd /s/q %s" % folder)
|
||||
else:
|
||||
shutil.rmtree(folder)
|
||||
if os.path.exists(folder):
|
||||
if sys.platform == 'win32':
|
||||
execute_command("rd /s/q %s" % folder)
|
||||
else:
|
||||
shutil.rmtree(folder)
|
||||
|
||||
def mkdir(folder):
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
def cpdir(source, dest):
|
||||
source_dir = source
|
||||
dest_dir = dest
|
||||
source_dir = source
|
||||
dest_dir = dest
|
||||
|
||||
if not os.path.exists(source_dir):
|
||||
raise Exception("cpdir source_dir (%s) not exists" % source_dir)
|
||||
if not os.path.exists(source_dir):
|
||||
raise Exception("cpdir source_dir (%s) not exists" % source_dir)
|
||||
|
||||
mkdir(dest_dir)
|
||||
mkdir(dest_dir)
|
||||
|
||||
for f in os.listdir(source_dir):
|
||||
path = os.path.join(source_dir, f)
|
||||
if os.path.isfile(path):
|
||||
shutil.copy(path, dest_dir)
|
||||
elif os.path.isdir(path):
|
||||
new_dest = os.path.join(dest_dir, f)
|
||||
cpdir(path, new_dest)
|
||||
for f in os.listdir(source_dir):
|
||||
path = os.path.join(source_dir, f)
|
||||
if os.path.isfile(path):
|
||||
shutil.copy(path, dest_dir)
|
||||
elif os.path.isdir(path):
|
||||
new_dest = os.path.join(dest_dir, f)
|
||||
cpdir(path, new_dest)
|
||||
|
||||
def win2unix(filePath):
|
||||
try:
|
||||
oldfile = open(filePath, "rb+")
|
||||
path, name = os.path.split(filePath)
|
||||
newfile = open(path + '$' + name, "wb+")
|
||||
try:
|
||||
oldfile = open(filePath, "rb+")
|
||||
path, name = os.path.split(filePath)
|
||||
newfile = open(path + '$' + name, "wb+")
|
||||
|
||||
old = b'\r'
|
||||
new = b''
|
||||
old = b'\r'
|
||||
new = b''
|
||||
|
||||
data = b''
|
||||
while (True):
|
||||
data = oldfile.read(200)
|
||||
newData = data.replace(old, new)
|
||||
newfile.write(newData)
|
||||
if len(data) < 200:
|
||||
break
|
||||
newfile.close()
|
||||
oldfile.close()
|
||||
data = b''
|
||||
while (True):
|
||||
data = oldfile.read(200)
|
||||
newData = data.replace(old, new)
|
||||
newfile.write(newData)
|
||||
if len(data) < 200:
|
||||
break
|
||||
newfile.close()
|
||||
oldfile.close()
|
||||
|
||||
os.remove(filePath)
|
||||
os.rename(path + '$' + name, filePath)
|
||||
except IOError as e:
|
||||
print(e)
|
||||
os.remove(filePath)
|
||||
os.rename(path + '$' + name, filePath)
|
||||
except IOError as e:
|
||||
print(e)
|
||||
|
||||
def copy_files_with_cb(src, dst, cb):
|
||||
for item in os.listdir(src):
|
||||
path = os.path.join(src, item)
|
||||
if os.path.isfile(path):
|
||||
if cb is None:
|
||||
shutil.copy(path, dst)
|
||||
else:
|
||||
cb(path, dst)
|
||||
if os.path.isdir(path):
|
||||
new_dst = os.path.join(dst, item)
|
||||
if not os.path.isdir(new_dst):
|
||||
os.makedirs(new_dst)
|
||||
copy_files_with_cb(path, new_dst, cb)
|
||||
for item in os.listdir(src):
|
||||
path = os.path.join(src, item)
|
||||
if os.path.isfile(path):
|
||||
if cb is None:
|
||||
shutil.copy(path, dst)
|
||||
else:
|
||||
cb(path, dst)
|
||||
if os.path.isdir(path):
|
||||
new_dst = os.path.join(dst, item)
|
||||
if not os.path.isdir(new_dst):
|
||||
os.makedirs(new_dst)
|
||||
copy_files_with_cb(path, new_dst, cb)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue