From 4e6ad3055bdf44a1e1b458ecf11212cef9faf783 Mon Sep 17 00:00:00 2001 From: liangxinyan Date: Sat, 30 Aug 2025 10:44:42 +0800 Subject: [PATCH 1/6] IssueNo: https://gitee.com/openharmony/build/issues/ICVJBU Signed-off-by: liangxinyan --- scripts/compile_app.py | 53 ++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index de3bcd7805..f11f971859 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"[{hash_value}] [0/0] 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"[{hash_value}] [0/0] 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"[{hash_value}] [1/1] Hvigor info: {line}") for line in stderr.splitlines(): - print(f"[2/2] Hvigor warning: {line}") + print(f"[{hash_value}] [2/2] 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"[{hash_value}] [0/0] Hvigor build end") -def build_hvigor_cmd(cwd: str, model_version: str, options): +def build_hvigor_cmd(cwd: str, model_version: str, options, hash_value: str): cmd = ['bash'] - hvigor_version = get_hvigor_version(cwd) + hvigor_version = get_hvigor_version(cwd, hash_value) 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"[{hash_value}] [0/0] hvigor cmd: " + ' '.join(cmd)) return cmd @@ -306,7 +307,7 @@ 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 @@ -314,11 +315,11 @@ def hvigor_build(cwd: str, options): :return: None ''' model_version = get_integrated_project_config(cwd) - print(f"[0/0] model_version: {model_version}") + print(f"[{hash_value}] [0/0] model_version: {model_version}") cmd = build_hvigor_cmd(cwd, model_version, options) - print("[0/0] Hvigor clean start") + print(f"[{hash_value}] [0/0] 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") + print(f"[{hash_value}] [0/0] Hvigor build start") hvigor_write_log(cmd, cwd, env) def main(args): options = parse_args(args) cwd = os.path.abspath(options.cwd) + hash_result = uuid.uuid4() + hash_value = str(hash_result).replace("-", "") # 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:])) -- Gitee From b2f3db1cb206ac7659a8be438b85c0cb9e8b45b8 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Sat, 30 Aug 2025 03:23:38 +0000 Subject: [PATCH 2/6] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index f11f971859..e9c8aa5931 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -314,7 +314,7 @@ def hvigor_build(cwd: str, options, hash_value: str): :param options: command line parameters :return: None ''' - model_version = get_integrated_project_config(cwd) + model_version = get_integrated_project_config(cwd, hash_value) print(f"[{hash_value}] [0/0] model_version: {model_version}") cmd = build_hvigor_cmd(cwd, model_version, options) -- Gitee From ee4c1165e7bf73bfa8f45e50e07685fb2d4b18d1 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Sat, 30 Aug 2025 06:12:01 +0000 Subject: [PATCH 3/6] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index e9c8aa5931..8b6ab52597 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -331,7 +331,7 @@ def hvigor_build(cwd: str, options, hash_value: str): hvigor_sync(cwd, model_version, env) print(f"[{hash_value}] [0/0] Hvigor build start") - hvigor_write_log(cmd, cwd, env) + hvigor_write_log(cmd, cwd, env, hash_value) def main(args): -- Gitee From e5bd990cfde86120bc9132c1e326edaec7587be1 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Sat, 30 Aug 2025 06:50:57 +0000 Subject: [PATCH 4/6] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index 8b6ab52597..f8c29479ba 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -317,7 +317,7 @@ def hvigor_build(cwd: str, options, hash_value: str): model_version = get_integrated_project_config(cwd, hash_value) print(f"[{hash_value}] [0/0] model_version: {model_version}") - cmd = build_hvigor_cmd(cwd, model_version, options) + cmd = build_hvigor_cmd(cwd, model_version, options, hash_value) print(f"[{hash_value}] [0/0] Hvigor clean start") env = os.environ.copy() -- Gitee From 322e1e56589045b641df10a5db440e050e93fe72 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Mon, 1 Sep 2025 00:57:14 +0000 Subject: [PATCH 5/6] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index f8c29479ba..2361f74eb0 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -220,9 +220,9 @@ def hvigor_write_log(cmd, cwd, env, hash_value): print(f"[{hash_value}] [0/0] Hvigor build end") -def build_hvigor_cmd(cwd: str, model_version: str, options, hash_value: str): +def build_hvigor_cmd(cwd: str, model_version: str, options, hash_val: str): cmd = ['bash'] - hvigor_version = get_hvigor_version(cwd, hash_value) + 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: @@ -272,7 +272,7 @@ def build_hvigor_cmd(cwd: str, model_version: str, options, hash_value: str): cmd.extend(['--no-daemon']) - print(f"[{hash_value}] [0/0] hvigor cmd: " + ' '.join(cmd)) + print(f"[{hash_val}] [0/0] hvigor cmd: " + ' '.join(cmd)) return cmd -- Gitee From 1dd2e6f8535d31dad5364fae3077b866f43d13f3 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Fri, 12 Sep 2025 08:57:22 +0000 Subject: [PATCH 6/6] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index 2361f74eb0..e5c1ce7a98 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -116,7 +116,7 @@ def make_env(build_profile: str, cwd: str, ohpm_registry: str, options, hash_val def get_integrated_project_config(cwd: str, hash_value: str): - print(f"[{hash_value}] [0/0] project dir: {cwd}") + 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') @@ -124,7 +124,7 @@ def get_integrated_project_config(cwd: str, hash_value: str): def get_hvigor_version(cwd: str, hash_value: str): - print(f"[{hash_value}] [0/0] project dir: {cwd}") + 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') @@ -208,16 +208,16 @@ def hvigor_write_log(cmd, cwd, env, hash_value): encoding='utf-8') stdout, stderr = proc.communicate() for line in stdout.splitlines(): - print(f"[{hash_value}] [1/1] Hvigor info: {line}") + print(f"[1/1] [{hash_value}] Hvigor info: {line}") for line in stderr.splitlines(): - print(f"[{hash_value}] [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(f"[{hash_value}] [0/0] Hvigor build end") + print(f"[0/0] [{hash_value}] Hvigor build end") def build_hvigor_cmd(cwd: str, model_version: str, options, hash_val: str): @@ -272,7 +272,7 @@ def build_hvigor_cmd(cwd: str, model_version: str, options, hash_val: str): cmd.extend(['--no-daemon']) - print(f"[{hash_val}] [0/0] hvigor cmd: " + ' '.join(cmd)) + print(f"[0/0] [{hash_val}] hvigor cmd: " + ' '.join(cmd)) return cmd @@ -315,11 +315,11 @@ def hvigor_build(cwd: str, options, hash_value: str): :return: None ''' model_version = get_integrated_project_config(cwd, hash_value) - print(f"[{hash_value}] [0/0] model_version: {model_version}") + print(f"[0/0] [{hash_value}] model_version: {model_version}") cmd = build_hvigor_cmd(cwd, model_version, options, hash_value) - print(f"[{hash_value}] [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')}" @@ -330,7 +330,7 @@ def hvigor_build(cwd: str, options, hash_value: str): hvigor_sync(cwd, model_version, env) - print(f"[{hash_value}] [0/0] Hvigor build start") + print(f"[0/0] [{hash_value}] Hvigor build start") hvigor_write_log(cmd, cwd, env, hash_value) @@ -338,7 +338,7 @@ def main(args): options = parse_args(args) cwd = os.path.abspath(options.cwd) hash_result = uuid.uuid4() - hash_value = str(hash_result).replace("-", "") + hash_value = str(hash_result).split("-")[0] # copy system lib deps to app libs dir if options.system_lib_module_info_list: -- Gitee