diff --git a/hb/services/loader.py b/hb/services/loader.py index b0ae32eb443f5d1050f4a48b5d88d41e2df52f7e..aa7b93f29a7a87029758efc376b109b7a6e660b3 100644 --- a/hb/services/loader.py +++ b/hb/services/loader.py @@ -52,7 +52,6 @@ class OHOSLoader(LoadInterface): self.build_xts = "" self.ignore_api_check = "" self.load_test_config = "" - self.subsystem_configs = "" self._subsystem_info = "" def __post_init__(self): @@ -87,9 +86,6 @@ class OHOSLoader(LoadInterface): self.build_xts = self.args_dict.get('build_xts') self.ignore_api_check = self.args_dict.get('ignore_api_check') self.load_test_config = self.args_dict.get('load_test_config') - self.subsystem_configs = subsystem_scan.scan(self.subsystem_config_file, - self.example_subsystem_file, - self.source_root_dir) self._subsystem_info = subsystem_info.get_subsystem_info( self.subsystem_config_file, @@ -132,14 +128,14 @@ class OHOSLoader(LoadInterface): # check method - '''Description: Check the parameters passed in config. If the parameters are not - specified or the file content pointed to by the parameters does not - exist, an exception will be thrown directly. - @parameter:none - @return :none - ''' @throw_exception def _check_args(self): + '''Description: Check the parameters passed in config. If the parameters are not + specified or the file content pointed to by the parameters does not + exist, an exception will be thrown directly. + @parameter:none + @return :none + ''' LogUtil.hb_info("Checking all build args...") # check subsystem_config_file if not read_json_file(self.subsystem_config_file): @@ -204,124 +200,87 @@ class OHOSLoader(LoadInterface): # generate method - '''Description: Generate SystemCapability.json & syscap.json & syscap.para, dir:[ + @throw_exception + def _generate_syscap_files(self): + '''Description: Generate SystemCapability.json & syscap.json & syscap.para, dir:[ (//out/preloader/${product_name}/system/etc/SystemCapability.json), (//out/preloader/${product_name}/system/etc/syscap.json), (//out/preloader/${product_name}/system/etc/param/syscap.para)] - @parameter:none - @return :none - ''' - @throw_exception - def _generate_syscap_files(self): + @parameter:none + @return :none + ''' + def valid_syscap(syscap): + return 'syscap' in syscap and syscap['syscap'] is not None and len(syscap['syscap']) > 0 and syscap['syscap'] != [""] + + def update_syscap_init_list(syscap_string, syscap_name, all_syscap_product, target_syscap_init_list): + target_syscap_init_str = "const." + if syscap_name in all_syscap_product: + if all_syscap_product[syscap_name]: + target_syscap_init_str += syscap_name + '=true\n' + else: + return syscap_string + else: + if syscap_string.endswith('true'): + target_syscap_init_str += syscap_name + '=true\n' + elif syscap_string.endswith('false'): + return syscap_string + else: + target_syscap_init_str += syscap_string + "=true\n" + + if target_syscap_init_str not in target_syscap_init_list: + target_syscap_init_list.append(target_syscap_init_str) + return None + pre_syscap_info_path = os.path.dirname(self.platforms_config_file) - system_path = os.path.join(self.source_root_dir, os.path.join( - os.path.dirname(self.platforms_config_file), "system/")) - syscap_product_dict = read_json_file( - os.path.join(pre_syscap_info_path, "syscap.json")) + system_path = os.path.join(self.source_root_dir, pre_syscap_info_path, "system/") + syscap_product_dict = read_json_file(os.path.join(pre_syscap_info_path, "syscap.json")) syscap_info_list = self.parts_config_info.get('syscap_info') + + all_syscap_set = {syscap_string.split('=')[0].strip() for syscap in syscap_info_list + if syscap['component'] in self.required_parts_targets_list and valid_syscap(syscap) + for syscap_string in syscap['syscap']} + + for key, value in syscap_product_dict['part_to_syscap'].items(): + for syscap in value: + if syscap not in all_syscap_set: + raise OHOSException("In config.json of part [{}],the syscap[{}] is incorrect, \ + please check the syscap name".format(key, syscap), "2008") + target_syscap_with_part_name_list = [] target_syscap_list = [] target_syscap_for_init_list = [] - all_syscap_list = [] + for syscap in syscap_info_list: - if syscap['component'] not in self.required_parts_targets_list: + if syscap['component'] not in self.required_parts_targets_list or not valid_syscap(syscap): continue - if 'syscap' not in syscap or syscap['syscap'] is None \ - or len(syscap['syscap']) == 0 or syscap['syscap'] == [""]: - continue - for syscap_string in syscap['syscap']: - all_syscap_list.append(syscap_string.split('=')[0].strip()) - for key, value in syscap_product_dict['part_to_syscap'].items(): - for syscap in value: - if syscap not in all_syscap_list: - raise OHOSException( - "In config.json of part [{}],the syscap[{}] is incorrect, \ - please check the syscap name".format(key, syscap), "2008") - - for syscap in syscap_info_list: remove_list = [] - if syscap['component'] not in self.required_parts_targets_list: - continue - if 'syscap' not in syscap or syscap['syscap'] is None \ - or len(syscap['syscap']) == 0 or syscap['syscap'] == [""]: - continue + all_syscap_product = syscap_product_dict['syscap'] + for syscap_string in syscap['syscap']: - if syscap_string.startswith("SystemCapability.") is True: - target_syscap_init_str = "const." - syscap_name = syscap_string.split('=')[0].strip() - all_syscap_product = syscap_product_dict['syscap'] - if syscap_name in all_syscap_product and not all_syscap_product[syscap_name]: - remove_list.append(syscap_string) - continue - elif syscap_name in all_syscap_product and all_syscap_product[syscap_name]: - target_syscap_init_str += syscap_name + '=true\n' - else: - if syscap_string.endswith('true'): - target_syscap_init_str += syscap_name + '=true\n' - elif syscap_string.endswith('false'): - remove_list.append(syscap_string) - continue - else: - target_syscap_init_str += syscap_string + "=true\n" - if target_syscap_init_str not in target_syscap_for_init_list: - target_syscap_for_init_list.append( - target_syscap_init_str) - else: + if not syscap_string.startswith("SystemCapability."): raise OHOSException("""In bundle.json of part [{}], The syscap string [{}] is incorrect, need start with \"SystemCapability.\"""".format(syscap['component'], syscap_string), "2009") - for remove_str in remove_list: - syscap['syscap'].remove(remove_str) - for i in range(len(syscap['syscap'])): - if syscap['syscap'][i].endswith('true') or syscap['syscap'][i].endswith('false'): - syscap['syscap'][i] = syscap['syscap'][i].split('=')[ - 0].strip() + syscap_name = syscap_string.split('=')[0].strip() + remove_item = update_syscap_init_list(syscap_string, syscap_name, all_syscap_product, target_syscap_for_init_list) + if remove_item: + remove_list.append(remove_item) + + syscap['syscap'] = [syscap['syscap'][i].split('=')[0].strip() for i in range(len(syscap['syscap'])) + if syscap['syscap'][i].endswith('true') or syscap['syscap'][i].endswith('false')] syscap['syscap'].sort() target_syscap_with_part_name_list.append(syscap) target_syscap_list.extend(syscap['syscap']) - # Generate SystemCapability.json & syscap.json & syscap.para - target_syscap_list.sort() - syscap_info_dict = read_json_file(os.path.join( - pre_syscap_info_path, "SystemCapability.json")) - syscap_info_dict.update({'syscap': {'os': target_syscap_list}}) - system_etc_path = os.path.join(system_path, "etc/") - if not os.path.exists(system_path): - os.mkdir(system_path) - if not os.path.exists(system_etc_path): - os.mkdir(system_etc_path) - syscap_info_json = os.path.join( - system_etc_path, "SystemCapability.json") - write_json_file(syscap_info_json, syscap_info_dict) - LogUtil.hb_info( - "generate syscap info file to '{}'".format(syscap_info_json)) - target_syscap_with_part_name_list.sort( - key=lambda syscap: syscap['component']) - syscap_info_with_part_name_file = os.path.join( - system_etc_path, "syscap.json") - write_json_file(syscap_info_with_part_name_file, { - 'components': target_syscap_with_part_name_list}) - LogUtil.hb_info("generate syscap info with part name list to '{}'".format( - syscap_info_with_part_name_file)) - if not os.path.exists(os.path.join(system_etc_path, "param/")): - os.mkdir(os.path.join(system_etc_path, "param/")) - target_syscap_for_init_file = os.path.join( - system_etc_path, "param/syscap.para") - file = open(target_syscap_for_init_file, "w") - file.writelines(target_syscap_for_init_list) - file.close() - LogUtil.hb_info("generate target syscap for init list to '{}'".format( - target_syscap_for_init_file)) - - '''Description: output infos for testfwk into a json file. \ - (/out/${product_name}/build_configs/infos_for_testfwk.json) - @parameter:none - @return :none - ''' def _generate_infos_for_testfwk(self): + '''Description: output infos for testfwk into a json file. \ + (/out/${product_name}/build_configs/infos_for_testfwk.json) + @parameter:none + @return :none + ''' infos_for_testfwk_file = os.path.join(self.config_output_dir, "infos_for_testfwk.json") parts_info = self.parts_config_info.get('parts_info') @@ -338,13 +297,13 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generate infos for testfwk to '{}'".format( infos_for_testfwk_file)) - '''Description: output all target platform parts into a json file \ - (/out/${product_name}/build_configs/target_platforms_parts.json) - @parameter:none - @return :none - ''' def _generate_target_platform_parts(self): + '''Description: output all target platform parts into a json file \ + (/out/${product_name}/build_configs/target_platforms_parts.json) + @parameter:none + @return :none + ''' target_platform_parts_file = os.path.join(self.config_output_dir, "target_platforms_parts.json") write_json_file(target_platform_parts_file, @@ -353,13 +312,13 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generate target platform parts to '{}'".format( target_platform_parts_file)) - '''Description: Generate parts differences in different platforms, using phone as base. \ - (/out/${product_name}/build_configs/parts_different_info.json) - @parameter: none - @return :none - ''' def _generate_part_different_info(self): + '''Description: Generate parts differences in different platforms, using phone as base. \ + (/out/${product_name}/build_configs/parts_different_info.json) + @parameter: none + @return :none + ''' parts_different_info = self._get_parts_by_platform() parts_different_info_file = os.path.join(self.config_output_dir, "parts_different_info.json") @@ -369,13 +328,13 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generate part different info to '{}'".format( parts_different_info_file)) - '''Description: output platforms list into a gni file. \ - (/out/${product_name}/build_configs/platforms_list.gni) - @parameter: none - @return: none - ''' def _generate_platforms_list(self): + '''Description: output platforms list into a gni file. \ + (/out/${product_name}/build_configs/platforms_list.gni) + @parameter: none + @return: none + ''' platforms_list_gni_file = os.path.join(self.config_output_dir, "platforms_list.gni") _platforms = set(self.build_platforms) @@ -388,13 +347,13 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generate platforms list to '{}'".format( platforms_list_gni_file)) - '''Description: output auto install part into a json file. \ - (/out/${product_name}/build_configs/auto_install_parts.json) - @parameter: none - @return: none - ''' def _generate_auto_install_part(self): + '''Description: output auto install part into a json file. \ + (/out/${product_name}/build_configs/auto_install_parts.json) + @parameter: none + @return: none + ''' parts_path_info = self.parts_config_info.get("parts_path_info") auto_install_part_list = [] for part, path in parts_path_info.items(): @@ -407,13 +366,13 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generate auto install part to '{}'".format( auto_install_list_file)) - '''Description: output src flag into a json file. \ - (/out/${product_name}/build_configs/parts_src_flag.json) - @parameter: none - @return :none - ''' def _generate_src_flag(self): + '''Description: output src flag into a json file. \ + (/out/${product_name}/build_configs/parts_src_flag.json) + @parameter: none + @return :none + ''' parts_src_flag_file = os.path.join(self.config_output_dir, "parts_src_flag.json") write_json_file(parts_src_flag_file, @@ -422,13 +381,13 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info( "generated parts src flag to '{}/subsystem_info/parts_src_flag.json'".format(self.config_output_dir)) - '''Description: output build target list into a json file.\ - (/out/${product_name}/build_configs/required_parts_targets_list.json) - @parameter: none - @return :none - ''' def _generate_required_parts_targets_list(self): + '''Description: output build target list into a json file.\ + (/out/${product_name}/build_configs/required_parts_targets_list.json) + @parameter: none + @return :none + ''' build_targets_list_file = os.path.join(self.config_output_dir, "required_parts_targets_list.json") write_json_file(build_targets_list_file, @@ -436,26 +395,26 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generate build targets list file to '{}'".format( build_targets_list_file)) - '''Description: output build target info into a json file. \ - (/out/${product_name}/build_configs/required_parts_targets.json) - @parameter: none - @return: none - ''' def _generate_required_parts_targets(self): + '''Description: output build target info into a json file. \ + (/out/${product_name}/build_configs/required_parts_targets.json) + @parameter: none + @return: none + ''' build_targets_info_file = os.path.join(self.config_output_dir, "required_parts_targets.json") write_json_file(build_targets_info_file, self.required_parts_targets) LogUtil.hb_info("generate required parts targets to '{}'".format( build_targets_info_file)) - '''Description: output platforms part by src into a json file. \ - (/out/${product_name}/build_configs/platforms_parts_by_src.json) - @parameter: none - @return :none - ''' def _generate_platforms_part_by_src(self): + '''Description: output platforms part by src into a json file. \ + (/out/${product_name}/build_configs/platforms_parts_by_src.json) + @parameter: none + @return :none + ''' platforms_parts_by_src = self._get_platforms_parts() platforms_parts_by_src_file = os.path.join(self.source_root_dir, self.config_output_relpath, @@ -466,50 +425,50 @@ class OHOSLoader(LoadInterface): LogUtil.hb_info("generated platforms parts by src to '{}'".format( platforms_parts_by_src_file)) - '''Description: output system configs info into 4 files:[ + + def _generate_target_gn(self): + '''Description: output system configs info into 4 files:[ (/out/${product_name}/build_configs/subsystem_info/parts_list.gni), (/out/${product_name}/build_configs/subsystem_info/inner_kits_list.gni), (/out/${product_name}/build_configs/subsystem_info/system_kits_list.gni), (/out/${product_name}/build_configs/subsystem_info/parts_test_list.gni), (/out/${product_name}/build_configs/subsystem_info/BUILD.gn)] - @parameter: none - @return :none - ''' - - def _generate_target_gn(self): + @parameter: none + @return :none + ''' generate_targets_gn.gen_targets_gn(self.required_parts_targets, self.config_output_dir) - '''Description: output phony targets build file. \ - (/out/${product_name}/build_configs/phony_target/BUILD.gn) - @parameter: none - @return :none - ''' def _generate_phony_targets_build_file(self): + '''Description: output phony targets build file. \ + (/out/${product_name}/build_configs/phony_target/BUILD.gn) + @parameter: none + @return :none + ''' generate_targets_gn.gen_phony_targets(self.required_phony_targets, self.config_output_dir) - '''Description: output system configs info into 2 files:[ - (/out/${product_name}/build_configs/subsystem_info/${platform}-stub/BUILG.gn), - (/out/${product_name}/build_configs/subsystem_info/${platform}-stub/zframework_stub_exists.gni)] - @parameter: none - @return :none - ''' def _generate_stub_targets(self): + '''Description: output system configs info into 2 files:[ + (/out/${product_name}/build_configs/subsystem_info/${platform}-stub/BUILG.gn), + (/out/${product_name}/build_configs/subsystem_info/${platform}-stub/zframework_stub_exists.gni)] + @parameter: none + @return :none + ''' generate_targets_gn.gen_stub_targets( self.parts_config_info.get('parts_kits_info'), self.target_platform_stubs, self.config_output_dir) - '''Description: output system capabilities into a json file. \ - (/out/${product_name}/build_configs/${platform}_system_capabilities.json) - @parameter: none - @return :none - ''' def _generate_system_capabilities(self): + '''Description: output system capabilities into a json file. \ + (/out/${product_name}/build_configs/${platform}_system_capabilities.json) + @parameter: none + @return :none + ''' for platform in self.build_platforms: platform_parts = self.target_platform_parts.get(platform) platform_capabilities = [] @@ -532,15 +491,15 @@ class OHOSLoader(LoadInterface): "generated system capabilities to '{}/{}_system_capabilities.json'".format( self.config_output_dir, platform)) - '''Description: output system configs info into three json files:[ + + def _generate_subsystem_configs(self): + '''Description: output system configs info into three json files:[ (/out/${product_name}/build_configs/subsystem_info/subsystem_build_config.json), (/out/${product_name}/build_configs/subsystem_info/src_subsystem_info.json), (/out/${product_name}/build_configs/subsystem_info/no_src_subsystem_info.json)] - @parameter: none - @return :none - ''' - - def _generate_subsystem_configs(self): + @parameter: none + @return :none + ''' # The function has been implemented in module util/loader/subsystem_info.py LogUtil.hb_info( @@ -769,25 +728,11 @@ class OHOSLoader(LoadInterface): def _execute_loader_args_display(self): LogUtil.hb_info('Loading configuration file...') - args = [] - args.append('platforms_config_file="{}"'.format( - self.platforms_config_file)) - args.append('subsystem_config_file="{}"'.format( - self.subsystem_config_file)) - args.append('example_subsystem_file="{}"'.format( - self.example_subsystem_file)) - args.append('exclusion_modules_config_file="{}"'.format( - self.exclusion_modules_config_file)) - args.append('source_root_dir="{}"'.format(self.source_root_dir)) - args.append('gn_root_out_dir="{}"'.format(self.gn_root_out_dir)) - args.append('build_platform_name={}'.format(self.build_platform_name)) - args.append('build_xts={}'.format(self.build_xts)) - args.append('load_test_config={}'.format(self.load_test_config)) - args.append('target_os={}'.format(self.target_os)) - args.append('target_cpu={}'.format(self.target_cpu)) - args.append('os_level={}'.format(self.os_level)) - args.append('ignore_api_check={}'.format(self.ignore_api_check)) - args.append('scalable_build={}'.format(self.scalable_build)) + fields = ['platforms_config_file', 'subsystem_config_file', 'example_subsystem_file', + 'exclusion_modules_config_file', 'source_root_dir', 'gn_root_out_dir', + 'build_platform_name', 'build_xts', 'load_test_config', 'target_os', + 'target_cpu', 'os_level', 'ignore_api_check', 'scalable_build'] + args = [f'{field}="{getattr(self, field)}"' for field in fields] LogUtil.write_log(self.config.log_path, 'loader args:{}'.format(args), 'info') diff --git a/hb/services/preloader.py b/hb/services/preloader.py index 1d79e7e8325b062c1d6693258a2bd6771ce3981b..e00dd98d97f98583094eebf61b6eb185185b32f7 100644 --- a/hb/services/preloader.py +++ b/hb/services/preloader.py @@ -54,12 +54,11 @@ class OHOSPreloader(PreloadInterface): # generate method - '''Description: generate platforms build info to "out/preloader/{product_name}/platforms.build" - @parameter:none - @return :none - ''' - def _generate_platforms_build(self): + '''Description: generate platforms build info to "out/preloader/{product_name}/platforms.build" + @parameter:none + @return :none + ''' config = { 'target_os': self._target_os, "target_cpu": self._target_cpu, @@ -72,12 +71,12 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated platforms build info to {}/platforms.build'.format(self._dirs.preloader_output_dir)) - '''Description: generate build gnargs prop info to "out/preloader/{product_name}/build_gnargs.prop" - @parameter:none - @return :none - ''' def _generate_build_gnargs_prop(self): + '''Description: generate build gnargs prop info to "out/preloader/{product_name}/build_gnargs.prop" + @parameter:none + @return :none + ''' all_features = {} for _part_name, vals in self._all_parts.items(): _features = vals.get('features') @@ -101,12 +100,12 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated build gnargs prop info to {}/build_gnargs.prop'.format(self._dirs.preloader_output_dir)) - '''Description: generate features to "out/preloader/{product_name}/features.json" - @parameter:none - @return :none - ''' def _generate_features_json(self): + '''Description: generate features to "out/preloader/{product_name}/features.json" + @parameter:none + @return :none + ''' all_features = {} part_feature_map = {} for _part_name, vals in self._all_parts.items(): @@ -124,12 +123,12 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated features info to {}/features.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate syscap to "out/preloader/product_name/syscap.json" - @parameter:none - @return :none - ''' def _generate_syscap_json(self): + '''Description: generate syscap to "out/preloader/product_name/syscap.json" + @parameter:none + @return :none + ''' all_syscap = {} part_syscap_map = {} for _part_name, vals in self._all_parts.items(): @@ -145,12 +144,12 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated syscap info to {}/syscap.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate exclusion modules info to "out/preloader/product_name/exclusion_modules.json" - @parameter:none - @return :none - ''' def _generate_exclusion_modules_json(self): + '''Description: generate exclusion modules info to "out/preloader/product_name/exclusion_modules.json" + @parameter:none + @return :none + ''' exclusions = {} for _part_name, vals in self._all_parts.items(): _exclusions = vals.get('exclusions') @@ -162,23 +161,23 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated exclusion modules info to {}/exclusion_modules.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate build config info to "out/preloader/product_name/build_config.json" - @parameter:none - @return :none - ''' def _generate_build_config_json(self): + '''Description: generate build config info to "out/preloader/product_name/build_config.json" + @parameter:none + @return :none + ''' IoUtil.dump_json_file( self._outputs.build_config_json, self._build_vars) LogUtil.hb_info( 'generated build config info to {}/build_config.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate build prop info to "out/preloader/product_name/build.prop" - @parameter:none - @return :none - ''' def _generate_build_prop(self): + '''Description: generate build prop info to "out/preloader/product_name/build.prop" + @parameter:none + @return :none + ''' build_vars_list = [] for key, value in self._build_vars.items(): build_vars_list.append('{}={}'.format(key, value)) @@ -188,23 +187,23 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated build prop info to {}/build.prop'.format(self._dirs.preloader_output_dir)) - '''Description: generate parts to "out/preloader/product_name/parts.json" - @parameter:none - @return :none - ''' def _generate_parts_json(self): + '''Description: generate parts to "out/preloader/product_name/parts.json" + @parameter:none + @return :none + ''' parts_info = {"parts": sorted(list(self._all_parts.keys()))} IoUtil.dump_json_file(self._outputs.parts_json, parts_info) LogUtil.hb_info( 'generated product parts info to {}/parts.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate parts config to "out/preloader/product_name/parts_config.json" - @parameter:none - @return :none - ''' def _generate_parts_config_json(self): + '''Description: generate parts config to "out/preloader/product_name/parts_config.json" + @parameter:none + @return :none + ''' parts_config = {} for part in self._all_parts: part = part.replace(":", "_") @@ -216,12 +215,12 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated parts config info to {}/parts_config.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate subsystem config info to "out/preloader/product_name/subsystem_config.json" - @parameter:none - @return :none - ''' def _generate_subsystem_config_json(self): + '''Description: generate subsystem config info to "out/preloader/product_name/subsystem_config.json" + @parameter:none + @return :none + ''' if self._subsystem_info: self._subsystem_info.update( self._product._get_product_specific_subsystem()) @@ -232,12 +231,12 @@ class OHOSPreloader(PreloadInterface): LogUtil.hb_info( 'generated subsystem config info to {}/subsystem_config.json'.format(self._dirs.preloader_output_dir)) - '''Description: generate systemcapability_json to "out/preloader/product_name/systemcapability.json" - @parameter:none - @return :none - ''' def _generate_systemcapability_json(self): + '''Description: generate systemcapability_json to "out/preloader/product_name/systemcapability.json" + @parameter:none + @return :none + ''' IoUtil.dump_json_file( self._outputs.systemcapability_json, self._product._syscap_info) LogUtil.hb_info( diff --git a/rust/rustc_toolchain.gni b/rust/rustc_toolchain.gni index 5a42cb7713226b66b9484d4d7d17c08e2035f19f..539798253a693b176f7c6ea00d919929630d1805 100644 --- a/rust/rustc_toolchain.gni +++ b/rust/rustc_toolchain.gni @@ -48,6 +48,7 @@ if (is_rust_nightly) { rust_path = "${rust_base}/${host_platform_dir}/${rust_version}" rust_bin = "${rust_path}/bin" +sccache = "${rust_bin}/sccache" rustc = "${rust_bin}/rustc" clippy_driver = "${rust_bin}/clippy-driver" diff --git a/toolchain/gcc_toolchain.gni b/toolchain/gcc_toolchain.gni index 21af100a21a97cf66f917a06ad12e1e0fb05b509..e52a65b0bd4166d578fc8b6549afbb0303e60d6f 100755 --- a/toolchain/gcc_toolchain.gni +++ b/toolchain/gcc_toolchain.gni @@ -597,7 +597,7 @@ template("gcc_toolchain") { pool = "//build/toolchain:link_pool($default_toolchain)" - command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --rustc=$rustc --depfile=$depfile --rsp=$rspfile -- --crate-name {{crate_name}} -C prefer-dynamic {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $outfile LDFLAGS RUSTENV {{rustenv}}" + command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --sccache=$sccache --rustc=$rustc --depfile=$depfile --rsp=$rspfile -- --crate-name {{crate_name}} -C prefer-dynamic {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $outfile LDFLAGS RUSTENV {{rustenv}}" description = "RUST staticlib $outfile" rust_sysroot = rust_sysroot_relative_to_out @@ -617,7 +617,7 @@ template("gcc_toolchain") { # Don't add rspfile in rust_rlib tool. pool = "//build/toolchain:link_pool($default_toolchain)" - command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --rustc=$rustc --depfile=$depfile -- --crate-name {{crate_name}} -C prefer-dynamic {{source}} --crate-type {{crate_type}} $cc_command_args {{rustdeps}} {{externs}} --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $outfile LDFLAGS RUSTENV {{rustenv}}" + command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --sccache=$sccache --rustc=$rustc --depfile=$depfile -- --crate-name {{crate_name}} -C prefer-dynamic {{source}} --crate-type {{crate_type}} $cc_command_args {{rustdeps}} {{externs}} --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $outfile LDFLAGS RUSTENV {{rustenv}}" description = "RUST rlib $outfile" rust_sysroot = rust_sysroot_relative_to_out outputs = [ outfile ] @@ -646,7 +646,7 @@ template("gcc_toolchain") { minidebug_switch = " --mini-debug" } - command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} -C prefer-dynamic $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -Clink-arg=-Wl,-soname=\"$cdylibname\" -o $unstripped_outfile LDFLAGS {{ldflags}} RUSTENV {{rustenv}}" + command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --sccache=$sccache --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} -C prefer-dynamic $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -Clink-arg=-Wl,-soname=\"$cdylibname\" -o $unstripped_outfile LDFLAGS {{ldflags}} RUSTENV {{rustenv}}" description = "RUST cdylib $outfile" rust_sysroot = rust_sysroot_relative_to_out @@ -674,7 +674,7 @@ template("gcc_toolchain") { if (full_mini_debug && !is_debug) { minidebug_switch = " --mini-debug" } - command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $unstripped_outfile LDFLAGS RUSTENV {{rustenv}}" + command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --sccache=$sccache --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $unstripped_outfile LDFLAGS RUSTENV {{rustenv}}" description = "RUST bin $outfile" rust_sysroot = rust_sysroot_relative_to_out @@ -703,7 +703,7 @@ template("gcc_toolchain") { if (full_mini_debug && !is_debug) { minidebug_switch = " --mini-debug" } - command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} -C prefer-dynamic $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $unstripped_outfile LDFLAGS {{ldflags}} RUSTENV {{rustenv}}" + command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --sccache=$sccache --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} -C prefer-dynamic $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $unstripped_outfile LDFLAGS {{ldflags}} RUSTENV {{rustenv}}" description = "RUST dylib $outfile" rust_sysroot = rust_sysroot_relative_to_out @@ -733,7 +733,7 @@ template("gcc_toolchain") { if (full_mini_debug && !is_debug) { minidebug_switch = " --mini-debug" } - command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} -C prefer-dynamic $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $unstripped_outfile LDFLAGS {{ldflags}} RUSTENV {{rustenv}}" + command = "$python_path \"$rustc_wrapper\" --clippy-driver=$clippy_driver --sccache=$sccache --rustc=$rustc --depfile=$depfile --rsp=$rspfile --output=$outfile --unstripped-file=$unstripped_outfile --strip=$llvm_strip $minidebug_switch -- --crate-name {{crate_name}} -C prefer-dynamic $strip_switch {{source}} --crate-type {{crate_type}} $cc_command_args --emit=dep-info=$depfile,link -Z dep-info-omit-d-target -Z unstable-options {{rustflags}} -o $unstripped_outfile LDFLAGS {{ldflags}} RUSTENV {{rustenv}}" description = "RUST proc-macro $outfile" rust_sysroot = rust_sysroot_relative_to_out diff --git a/toolchain/rustc_wrapper.py b/toolchain/rustc_wrapper.py index 0aca7682e907dd1060506bd98e03083cb90da67e..1b2eb620973e87eab7d6a3ebdca9fde1b37abdd5 100755 --- a/toolchain/rustc_wrapper.py +++ b/toolchain/rustc_wrapper.py @@ -44,8 +44,10 @@ def exec_formatted_command(args): rustenv = remaining_args[rustenv_index + 1:] rustc_args.extend(["-Clink-arg=%s" % arg for arg in ldflags]) - rustc_args.insert(0, args.rustc) - + rustc_args.insert(0, args.clippy_driver) + os.environ['RUSTC_WRAPPER'] = str(args.sccache) + os.environ['RUSTC'] = str(args.clippy_driver) + print(rustc_args) if args.rsp: flags = os.O_WRONLY modes = stat.S_IWUSR | stat.S_IRUSR @@ -61,10 +63,11 @@ def exec_formatted_command(args): (key, value) = item.split("=", 1) env[key] = value fixed_env_vars.append(key) - - ret = subprocess.run([args.clippy_driver, *rustc_args], env=env, check=False) - if ret.returncode != 0: - sys.exit(ret.returncode) + print(args.clippy_driver) + process = subprocess.Popen([f'{args.sccache}',*rustc_args], env=env) + returncode = process.wait() + if returncode != 0: + sys.exit(returncode) if args.depfile is not None: env_dep_re = re.compile("# env-dep:(.*)=.*") @@ -88,6 +91,9 @@ def main(): parser.add_argument('--clippy-driver', required=True, type=pathlib.Path) + parser.add_argument('--sccache', + required=True, + type=pathlib.Path) parser.add_argument('--rustc', required=True, type=pathlib.Path)