From a660d365d08107d6fc293710c92d851d63dd01fa Mon Sep 17 00:00:00 2001 From: liangxinyan Date: Sat, 16 Aug 2025 08:40:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?IssueNo:=20[=E6=96=B0=E9=9C=80=E6=B1=82]:?= =?UTF-8?q?=20https://gitee.com/openharmony/build/issues/ICT907=20Signed-o?= =?UTF-8?q?ff-by:=20liangxinyan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ohos/app/app.gni | 10 --------- ohos/app/app_internal.gni | 10 +-------- scripts/compile_app.py | 47 ++++++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/ohos/app/app.gni b/ohos/app/app.gni index c567bd7c17..3918090b50 100644 --- a/ohos/app/app.gni +++ b/ohos/app/app.gni @@ -464,16 +464,6 @@ template("ohos_app") { product = invoker.product } - module_target = "default" - if (defined(invoker.module_target)) { - module_target = invoker.module_target - } - - modules_filter = false - if (defined(invoker.modules_filter) && invoker.modules_filter) { - module_filter = true - } - ohos_test_coverage = false if (defined(invoker.ohos_test_coverage) && invoker.ohos_test_coverage) { ohos_test_coverage = invoker.ohos_test_coverage diff --git a/ohos/app/app_internal.gni b/ohos/app/app_internal.gni index da730138f9..8cb6530787 100644 --- a/ohos/app/app_internal.gni +++ b/ohos/app/app_internal.gni @@ -610,10 +610,8 @@ template("compile_app") { "sdk_type_name", "build_modules", "hvigor_home", - "product", - "module_target", - "modules_filter", "ohos_test_coverage", + "product", ]) script = "//build/scripts/compile_app.py" outputs = [ unsigned_hap_path_list ] @@ -633,14 +631,8 @@ template("compile_app") { ohpm_registry, "--product", product, - "--module-target", - module_target, ] - if (defined(modules_filter) && modules_filter) { - args += [ "--modules-filter" ] - } - if (defined(ohos_test_coverage) && ohos_test_coverage) { args += [ "--ohos-test-coverage" ] } diff --git a/scripts/compile_app.py b/scripts/compile_app.py index 3d906f9edf..5b55906ffe 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -55,8 +55,6 @@ def parse_args(args): parser.add_argument('--target-out-dir', help='base output dir') parser.add_argument('--target-app-dir', help='target output dir') parser.add_argument('--product', help='set product value of hvigor cmd, default or others') - parser.add_argument('--module-target', help='set module target of unsigned hap path') - parser.add_argument('--modules-filter', help='if enable filter unsigned hap or hsp packages', action='store_true') parser.add_argument('--ohos-test-coverage', help='enable test coverage when compile hap', action='store_true') options = parser.parse_args(args) @@ -102,6 +100,8 @@ def make_env(build_profile: str, cwd: str, ohpm_registry: str, options): 'NODE_HOME': os.path.dirname(os.path.abspath(options.nodejs)), } os.chdir(cwd) + if os.path.exists(os.path.join(cwd, 'oh_modules')): + shutil.rmtree(os.path.join(cwd, 'oh_modules'), ignore_errors=True) if os.path.exists(os.path.join(cwd, 'hvigorw')): subprocess.run(['chmod', '+x', 'hvigorw']) if os.path.exists(os.path.join(cwd, '.arkui-x/android/gradlew')): @@ -134,10 +134,12 @@ def get_hvigor_version(cwd: str): return hvigor_version -def get_unsigned_hap_path(project_name: str, src_path: str, cwd: str, options): +def get_unsigned_hap_path(module: str, src_path: str, cwd: str, options): hvigor_version = get_hvigor_version(cwd) + product_name = options.build_profile.replace("/build-profile.json5", "").split("/")[-1] model_version = get_integrated_project_config(cwd) - product_value = options.product + product_value = options.product if options.product else 'default' + module_target = get_target_by_module(module, options) if product_value is None: product_value = 'default' if options.test_hap: @@ -160,6 +162,29 @@ def get_unsigned_hap_path(project_name: str, src_path: str, cwd: str, options): return unsigned_hap_path +def split_build_modules(build_modules: list): + new_build_modules = [] + if not build_modules: + return new_build_modules + for item in build_modules: + target = "default" + module = item + if "@" in item: + split_item = item.split("@") + module = split_item[0] + target = split_item[1] + new_build_modules.append({"module": module, "target": target}) + return new_build_modules + + +def get_target_by_module(module, options): + new_build_modules = split_build_modules(options.build_modules) + for item in new_build_modules: + if item["module"] == module: + return item["target"] + return "default" + + def gen_unsigned_hap_path_json(build_profile: str, cwd: str, options): ''' Generate unsigned_hap_path_list @@ -173,17 +198,17 @@ def gen_unsigned_hap_path_json(build_profile: str, cwd: str, options): build_info = json5.load(input_f) modules_list = build_info.get('modules') for module in modules_list: - if options.modules_filter and module.get('name') not in options.build_modules: - continue 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) + module_name = module.get("name") + unsigned_hap_path = get_unsigned_hap_path(module_name, src_path, cwd, options) hap_file = build_utils.find_in_directory( unsigned_hap_path, '*-unsigned.hap') + if hap_file: + unsigned_hap_path_list.extend(hap_file) hsp_file = build_utils.find_in_directory( unsigned_hap_path, '*-unsigned.hsp') - unsigned_hap_path_list.extend(hap_file) - unsigned_hap_path_list.extend(hsp_file) + if hsp_file: + unsigned_hap_path_list.extend(hsp_file) unsigned_hap_path_json['unsigned_hap_path_list'] = unsigned_hap_path_list file_utils.write_json_file(options.output_file, unsigned_hap_path_json) @@ -253,7 +278,7 @@ def build_hvigor_cmd(cwd: str, model_version: str, options): cmd.extend(['--mode', 'module', '-p', f'module={options.test_module}@ohosTest', 'assembleHap']) elif options.build_modules: - cmd.extend(['assembleHap', '--mode', + cmd.extend([options.assemble_type, '--mode', 'module', '-p', f'product={product_value}', '-p', 'module=' + ','.join(options.build_modules)]) else: cmd.extend(['--mode', -- Gitee From 1534fad2337eeb136a77527f246eab25b1922214 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Sat, 16 Aug 2025 01:14:42 +0000 Subject: [PATCH 2/3] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index 5b55906ffe..3a66a46088 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -54,8 +54,8 @@ def parse_args(args): parser.add_argument('--ohos-app-enable-ubsan', help='hvigor enable ubsan', action='store_true') parser.add_argument('--target-out-dir', help='base output dir') parser.add_argument('--target-app-dir', help='target output dir') - parser.add_argument('--product', help='set product value of hvigor cmd, default or others') parser.add_argument('--ohos-test-coverage', help='enable test coverage when compile hap', action='store_true') + parser.add_argument('--product', help='set product value of hvigor cmd, default or others') options = parser.parse_args(args) return options @@ -177,7 +177,7 @@ def split_build_modules(build_modules: list): return new_build_modules -def get_target_by_module(module, options): +def get_target_by_module(module: str, options): new_build_modules = split_build_modules(options.build_modules) for item in new_build_modules: if item["module"] == module: -- Gitee From 70119a25064880039f451cc8da001a7957256621 Mon Sep 17 00:00:00 2001 From: liangxinyan123 Date: Sat, 16 Aug 2025 03:20:17 +0000 Subject: [PATCH 3/3] update scripts/compile_app.py. Signed-off-by: liangxinyan123 --- scripts/compile_app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/compile_app.py b/scripts/compile_app.py index 3a66a46088..87bf0dfb0c 100755 --- a/scripts/compile_app.py +++ b/scripts/compile_app.py @@ -139,7 +139,6 @@ def get_unsigned_hap_path(module: str, src_path: str, cwd: str, options): product_name = options.build_profile.replace("/build-profile.json5", "").split("/")[-1] model_version = get_integrated_project_config(cwd) product_value = options.product if options.product else 'default' - module_target = get_target_by_module(module, options) if product_value is None: product_value = 'default' if options.test_hap: @@ -151,7 +150,7 @@ def get_unsigned_hap_path(module: str, src_path: str, cwd: str, options): unsigned_hap_path = os.path.join( cwd, src_path, 'build/default/outputs/ohosTest') else: - module_target = options.module_target + module_target = get_target_by_module(module, options) 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) unsigned_hap_path = os.path.join( -- Gitee