def __generate_module_script_tasks(self, module): """ 生成cmake的脚本回调 """ cmake_text = "" for (cond, task) in module.tasks.items(): fake_target = module.name + "_" + cond # 这里执行task的时候会多拼接上一遍,不过没影响,因为执行的task一般不进行build操作。 arguments_info = core.data.arguments.clone(["task", module.name, cond, "-a", self.arch]) arguments_str = "" for index, value in enumerate(arguments_info.argv): if index > 1: arguments_str += " " + value command = "python {} {} {}".format( arguments_info.argv[0], arguments_info.argv[1], arguments_str) core.i(command) if cond == SCRIPT_PRE_BUILD: cmake_text += CMAKE_MODULE_PRE_BUILD_TEMPLATE.format(fake_target, command, module.name) else: cmake_text += CMAKE_MODULE_PRE_LINK_OR_POST_BUILD_TEMPLATE.format(module.name, str.upper(cond), command) return cmake_text
def _check_ndk_path(self, environ_key, sub_path): if environ_key in os.environ: ndk_path = os.path.join(str(os.environ[environ_key]), sub_path) core.i("check key:{} value:{}".format(environ_key, ndk_path)) if os.path.isdir(ndk_path): return ndk_path return ""
def __generate_header(self): """ create CmakeLists.txt's header :return: info """ # 设置ccache缓存相关内容 cache_path = "" use_cache = not core.data.arguments.has_opt("--no_cache") and not PlatformInfo.is_windows_system() if use_cache: cache_result = process_utils.execute_with_msg("which ccache") if cache_result: cache_list = cache_result.split("\n") if os.path.exists(cache_list[0]): cache_path = cache_list[0] else: use_cache = False else: use_cache = False if not use_cache: core.i("enable ccache, but ccache not install!!!") tmake_path = core.data.arguments.tmake_path() self.cmake_text += CMAKE_HEADER_TEMPLATE.format( self.info.project_name, self.info.mini_version, core.BUILD_OUTPUT_NAME, # bin core.BUILD_INSTALL_PREFIX, # export self.info.build_target.upper(), self.info.build_config.upper(), CMAKE_CACHE_TEMPLATE.format(cache_path, tmake_path, tmake_path) if use_cache else "" )
def copy_bin_to_export(src_dir, dst_dir): if NO_CHANGE_CMAKELISTS: return src_dir = src_dir.replace("\\", "/") dst_dir = dst_dir.replace("\\", "/") if not os.path.exists(src_dir): core.i("copy_bin_to_export error directory: {}".format(src_dir)) return if os.path.exists(dst_dir): shutil.rmtree(dst_dir) shutil.copytree(src_dir, dst_dir)
def get_mp_build_string(self): mp_args = "" if core.data.arguments.has_flag("nmp", "nmp"): return mp_args try: cpu_cnt = int(cpu_count() * 3 / 4) except: cpu_cnt = 0 if cpu_cnt <= 0: cpu_cnt = 1 mp_args = " -- -j {} ".format(cpu_cnt) core.i("mp_args = " + mp_args) return mp_args
def move_header_files(src_dir, dst_dir): if NO_CHANGE_CMAKELISTS: return src_dir = src_dir.replace("\\", "/") dst_dir = dst_dir.replace("\\", "/") if not os.path.exists(src_dir): core.i("move_header_files: no src_dir={}".format(src_dir)) return libname = dst_dir[dst_dir.rfind("/")+1:] bfind = False for f in os.listdir(src_dir): sourceF = os.path.join(src_dir, f) sourceF = sourceF.replace("\\", "/") if os.path.isdir(sourceF): if f == libname: bfind = True src_dir = sourceF break if not bfind: src_dir = os.path.join(src_dir, "include") if not os.path.exists(src_dir): core.i("move_header_files no include directory: {}".format(src_dir)) return target_path = os.path.join(dst_dir, "include") if os.path.exists(target_path): shutil.rmtree(target_path) shutil.copytree(src_dir, target_path) else: if os.path.exists(dst_dir): shutil.rmtree(dst_dir) for f in os.listdir(src_dir): sourceF = os.path.join(src_dir, f) sourceF = sourceF.replace("\\", "/") if os.path.isdir(sourceF): target_path = os.path.join(dst_dir, "include") shutil.copytree(sourceF, target_path) else: target_path = os.path.join(dst_dir, "include") target_file = os.path.join(target_path, f) if os.path.exists(target_file): os.remove(target_file) shutil.copy(sourceF, target_path)
def execute_task(self, task): if core.data.target == core.data.platform.host: core.v('curr run name : %s' % task) args = [] command = string.strip(task.command) cwd = task.work_directory args += task.args core.v('command : {} , cwd : {} , args : {}'.format( command, cwd, args)) if len(command) <= 0: raise core.TmakeException( '[Possible error] tmake_host_tester_task : {} command property configuration error !!!' .format(task)) cmd_check = re.split(' *', command) core.v('pre cmd_check : {}'.format(cmd_check)) cmd_check[0] = os.path.join(self.acg.path.build_symbol_path, cmd_check[0]) if core.data.platform.host == core.PLATFORM_WINDOWS: cmd_check[0] += '.exe' core.v('post cmd_check : {}'.format(cmd_check)) if not os.path.exists(cmd_check[0]): raise core.TmakeException( '%s is not exist %s , please first build !' % (cmd_check[0], self.__common_log_info())) if len(cwd) <= 0: cwd = None elif not os.path.isabs(cwd): cwd = os.path.abspath( os.path.join(self.acg.path.project_folder, cwd)) cmd_check += args core.i('\n----> exec {} ......'.format(cmd_check)) self.env_set() ret, msg = process_utils.execute_prog_with_sysstdout( cmd_check, cwd) if ret == 0: core.s('{} test success!\n'.format(task.name)) else: raise core.TmakeException( '{} test error! {} message : {}\n'.format( task.name, ret, msg)) else: raise core.TmakeException( '%s and %s do not match , please do not add -t parameter' % (core.data.target, core.data.platform.host))
def print_info(self): """trace log""" core.v('---->abs xml path : %s ' % os.path.join(self.__xmlpath)) core.i(">>>>>>>>> the project info:") core.i("name : " + str(self.name)) core.i("link_name : " + str(self.link_name)) core.i("version : " + str(self.version)) core.i("author : " + str(self.author)) core.i("git_url : " + str(self.git_url)) core.i("git_branch : " + str(self.git_branch)) core.i("git_commit : " + str(self.git_commit)) core.i("include_dir : " + str(self.include_dir)) core.i("lib_dir : " + str(self.lib_dir)) core.i("sym_lib_dir : " + str(self.sym_lib_dir)) core.i("package : " + str("{}.zip".format(self.package_name)))
def tmake_logi(msg): """log for i""" core.i(msg)
def __init__(self, message): core.i('skip info: {0}'.format(message)) core.e(' SkipException --> {0}'.format(message))
def run_build(self): """ call cmake build """ target = core.data.target command_text = "" use_nmake = "" if PlatformInfo.is_windows_system(): vs_tools = core.data.environment.get_vs_tool_path(self.arch) if target != core.PLATFORM_ANDROID and target != core.PLATFORM_WINDOWS: raise core.TmakeException('unsupported target : ' + target) command_text += '"' + vs_tools + '" ' command_text += "&&" if core.data.use_cmakelist: command_text += tmake_utils.get_cd_command() + " \"" + self.path.project_folder + "\" && " else: command_text += tmake_utils.get_cd_command() + " \"" + self.path.build_path + "\" && " if not core.data.arguments.has_flag("nmp", "nmp") and target == core.PLATFORM_WINDOWS and not "wince" in self.arch\ and not core.data.use_cmakelist: use_nmake = '-G "NMake Makefiles JOM" ' jom_exe = os.path.join(core.data.arguments.tmake_path(), "tools", "jom.exe") use_nmake += ' -DCMAKE_MAKE_PROGRAM="' + jom_exe + '"' core.i("use_nmake = " + use_nmake) elif target == core.PLATFORM_WINDOWS and "wince" in self.arch: use_nmake = '-G "Visual Studio 9 2008 ' + core.WINCE_CPU_MAP[self.arch] + '"' else: use_nmake = '-G "NMake Makefiles" ' if core.data.use_cmakelist: command_text += '"' + self.cmake_home + '" ../../../../ ' + use_nmake + self.__build_params() else: command_text += '"' + self.cmake_home + '" . ' + use_nmake + self.__build_params() command_text += "&&" command_text += self.__build_target() if target == core.PLATFORM_WINDOWS and "wince" in self.arch: configuration = '' if self.info.build_config == core.CONFIG_DEBUG: configuration = 'Debug' elif self.info.build_config == core.CONFIG_RELWITHDEBINFO: configuration = 'RelWithDebInfo' else: configuration = 'Release' command_text += "&&" command_text += 'msbuild.exe ' + self.info.project_name + ".sln " + '/t:ReBuild ' + '/p:Configuration=' + configuration + ' /p:Platform=' + '"' + \ core.WINCE_CPU_MAP[self.arch] + '"' if core.data.use_cmakelist and target != core.PLATFORM_WINDOWS: if core.data.arguments.tmake_cmd() == "project": path_info = PathInfo(self.arch, core.data.arguments.work_path()) base_path = path_info.project_path else: base_path = core.data.project.get_build_folder(self.arch) export_path = os.path.join(base_path, core.BUILD_INSTALL_PREFIX) exectable_output_path = os.path.join(base_path, core.BUILD_OUTPUT_NAME) library_output_path = os.path.join(base_path, core.BUILD_OUTPUT_NAME) pre_command_text = '"' + self.cmake_home + '" ../../../../ ' + " -DCMAKE_INSTALL_PREFIX={}".format(export_path) + \ " -DEXECUTABLE_OUTPUT_PATH={}".format(exectable_output_path) + \ " -DLIBRARY_OUTPUT_PATH={}".format(library_output_path) + \ use_nmake + self.__build_params() pre_command_text = tmake_utils.get_cd_command() + " \"" + self.path.build_path + "\" && " + pre_command_text ret = subprocess.call(pre_command_text, shell=True) if ret != 0: raise core.TmakeException('Set CMAKE_INSTALL_PREFIX failed! return code is {}'.format(ret)) self.execute_build_command(command_text)