diff --git a/scripts/compile_app.py b/scripts/compile_app.py index de3bcd78051e79dea04ac8e0224645cd5c97a757..e5c1ce7a98e332d0d3be8de7fcc629282da1cc72 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -19,6 +19,7 @@ import sys import subprocess import shutil import json5 +import uuid from util import build_utils from util import file_utils @@ -73,7 +74,7 @@ def get_root_dir(): current_dir = new_dir -def make_env(build_profile: str, cwd: str, ohpm_registry: str, options): +def make_env(build_profile: str, cwd: str, ohpm_registry: str, options, hash_value: str): ''' Set up the application compilation environment and run "ohpm install" :param build_profile: module compilation information file @@ -81,7 +82,7 @@ def make_env(build_profile: str, cwd: str, ohpm_registry: str, options): :param ohpm_registry: ohpm registry :return: None ''' - print(f"build_profile:{build_profile}; cwd:{cwd}") + print(f"[{hash_value}] build_profile:{build_profile}; cwd:{cwd}") cur_dir = os.getcwd() root_dir = get_root_dir() ohpm_path = os.path.join(root_dir, "prebuilts/build-tools/common/oh-command-line-tools/ohpm/bin/ohpm") @@ -114,25 +115,25 @@ def make_env(build_profile: str, cwd: str, ohpm_registry: str, options): os.chdir(cur_dir) -def get_integrated_project_config(cwd: str): - print(f"[0/0] project dir: {cwd}") +def get_integrated_project_config(cwd: str, hash_value: str): + print(f"[0/0] [{hash_value}] project dir: {cwd}") with open(os.path.join(cwd, 'hvigor/hvigor-config.json5'), 'r') as input_f: hvigor_info = json5.load(input_f) model_version = hvigor_info.get('modelVersion') return model_version -def get_hvigor_version(cwd: str): - print(f"[0/0] project dir: {cwd}") +def get_hvigor_version(cwd: str, hash_value: str): + print(f"[0/0] [{hash_value}] project dir: {cwd}") with open(os.path.join(cwd, 'hvigor/hvigor-config.json5'), 'r') as input_f: hvigor_info = json5.load(input_f) hvigor_version = hvigor_info.get('hvigorVersion') return hvigor_version -def get_unsigned_hap_path(project_name: str, src_path: str, cwd: str, options): - hvigor_version = get_hvigor_version(cwd) - model_version = get_integrated_project_config(cwd) +def get_unsigned_hap_path(project_name: str, src_path: str, cwd: str, options, hash_value: str): + hvigor_version = get_hvigor_version(cwd, hash_value) + model_version = get_integrated_project_config(cwd, hash_value) if options.test_hap: if options.target_app_dir and ((hvigor_version and float(hvigor_version[:3]) > 4.1) or model_version): new_src_path = os.path.join(options.target_out_dir, options.target_app_dir, project_name, src_path) @@ -152,7 +153,7 @@ def get_unsigned_hap_path(project_name: str, src_path: str, cwd: str, options): return unsigned_hap_path -def gen_unsigned_hap_path_json(build_profile: str, cwd: str, options): +def gen_unsigned_hap_path_json(build_profile: str, cwd: str, options, hash_value: str): ''' Generate unsigned_hap_path_list :param build_profile: module compilation information file @@ -167,7 +168,7 @@ def gen_unsigned_hap_path_json(build_profile: str, cwd: str, options): for module in modules_list: src_path = module.get('srcPath') project_name = options.build_profile.replace("/build-profile.json5", "").split("/")[-1] - unsigned_hap_path = get_unsigned_hap_path(project_name, src_path, cwd, options) + unsigned_hap_path = get_unsigned_hap_path(project_name, src_path, cwd, options, hash_value) hap_file = build_utils.find_in_directory( unsigned_hap_path, '*-unsigned.hap') hsp_file = build_utils.find_in_directory( @@ -198,7 +199,7 @@ def copy_libs(cwd: str, system_lib_module_info_list: list, ohos_app_abi: str, mo shutil.copyfile(lib_path, dest) -def hvigor_write_log(cmd, cwd, env): +def hvigor_write_log(cmd, cwd, env, hash_value): proc = subprocess.Popen(cmd, cwd=cwd, env=env, @@ -207,21 +208,21 @@ def hvigor_write_log(cmd, cwd, env): encoding='utf-8') stdout, stderr = proc.communicate() for line in stdout.splitlines(): - print(f"[1/1] Hvigor info: {line}") + print(f"[1/1] [{hash_value}] Hvigor info: {line}") for line in stderr.splitlines(): - print(f"[2/2] Hvigor warning: {line}") + print(f"[2/2] [{hash_value}] Hvigor warning: {line}") os.makedirs(os.path.join(cwd, 'build'), exist_ok=True) with open(os.path.join(cwd, 'build', 'build.log'), 'w') as f: f.write(f'{stdout}\n') f.write(f'{stderr}\n') if proc.returncode or "ERROR: BUILD FAILED" in stderr or "ERROR: BUILD FAILED" in stdout: raise Exception('ReturnCode:{}. Hvigor build failed: {}'.format(proc.returncode, stderr)) - print("[0/0] Hvigor build end") + print(f"[0/0] [{hash_value}] Hvigor build end") -def build_hvigor_cmd(cwd: str, model_version: str, options): +def build_hvigor_cmd(cwd: str, model_version: str, options, hash_val: str): cmd = ['bash'] - hvigor_version = get_hvigor_version(cwd) + hvigor_version = get_hvigor_version(cwd, hash_val) if options.hvigor_home: cmd.extend([f'{os.path.abspath(options.hvigor_home)}/bin/hvigorw']) elif model_version: @@ -271,7 +272,7 @@ def build_hvigor_cmd(cwd: str, model_version: str, options): cmd.extend(['--no-daemon']) - print("[0/0] hvigor cmd: " + ' '.join(cmd)) + print(f"[0/0] [{hash_val}] hvigor cmd: " + ' '.join(cmd)) return cmd @@ -306,19 +307,19 @@ def hvigor_sync(cwd: str, model_version: str, env): stderr=subprocess.DEVNULL) -def hvigor_build(cwd: str, options): +def hvigor_build(cwd: str, options, hash_value: str): ''' Run hvigorw to build the app or hap :param cwd: app project directory :param options: command line parameters :return: None ''' - model_version = get_integrated_project_config(cwd) - print(f"[0/0] model_version: {model_version}") + model_version = get_integrated_project_config(cwd, hash_value) + print(f"[0/0] [{hash_value}] model_version: {model_version}") - cmd = build_hvigor_cmd(cwd, model_version, options) + cmd = build_hvigor_cmd(cwd, model_version, options, hash_value) - print("[0/0] Hvigor clean start") + print(f"[0/0] [{hash_value}] Hvigor clean start") env = os.environ.copy() env['CI'] = 'true' env['PATH'] = f"{os.path.dirname(os.path.abspath(options.nodejs))}:{os.environ.get('PATH')}" @@ -329,13 +330,15 @@ def hvigor_build(cwd: str, options): hvigor_sync(cwd, model_version, env) - print("[0/0] Hvigor build start") - hvigor_write_log(cmd, cwd, env) + print(f"[0/0] [{hash_value}] Hvigor build start") + hvigor_write_log(cmd, cwd, env, hash_value) def main(args): options = parse_args(args) cwd = os.path.abspath(options.cwd) + hash_result = uuid.uuid4() + hash_value = str(hash_result).split("-")[0] # copy system lib deps to app libs dir if options.system_lib_module_info_list: @@ -349,14 +352,14 @@ def main(args): os.environ['PATH'] = f'{cwd}/.arkui-x/android:{os.environ.get("PATH")}' # generate unsigned_hap_path_list and run ohpm install - make_env(options.build_profile, cwd, options.ohpm_registry, options) + make_env(options.build_profile, cwd, options.ohpm_registry, options, hash_value) # invoke hvigor to build hap or app - hvigor_build(cwd, options) + hvigor_build(cwd, options, hash_value) # generate a json file to record the path of all unsigned haps, and When signing hap later, # this json file will serve as input to provide path information for each unsigned hap. - gen_unsigned_hap_path_json(options.build_profile, cwd, options) + gen_unsigned_hap_path_json(options.build_profile, cwd, options, hash_value) if __name__ == '__main__': sys.exit(main(sys.argv[1:]))