From 8372ec1bfcc084023d1c4d7518c0688d45a3bbf2 Mon Sep 17 00:00:00 2001 From: zhaohang Date: Thu, 17 Apr 2025 13:56:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Egn-flags=E5=8F=82=E6=95=B0;?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8B=AC=E7=AB=8B=E7=BC=96=E8=AF=91=E4=BD=BF?= =?UTF-8?q?=E7=94=A8--skip-download=E6=88=96=E8=80=85--fast-rebuild?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E4=B8=8B=E8=BD=BD=E9=98=B6=E6=AE=B5=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E7=BC=96=E8=AF=91=EF=BC=8C=E6=9C=AA=E8=83=BD=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B0=E6=97=A5=E5=BF=97=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- hb/resolver/indep_build_args_resolver.py | 11 +++++----- hb/resources/args/default/indepbuildargs.json | 22 +++++++++---------- hb/services/indep_build.py | 5 +++++ indep_configs/scripts/gn_ninja_cmd.py | 6 ++--- indep_configs/scripts/utils.py | 20 ++++++++--------- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/hb/resolver/indep_build_args_resolver.py b/hb/resolver/indep_build_args_resolver.py index 39d16385f0..fd55d0d9b2 100644 --- a/hb/resolver/indep_build_args_resolver.py +++ b/hb/resolver/indep_build_args_resolver.py @@ -204,20 +204,19 @@ class IndepBuildArgsResolver(ArgsResolverInterface): @staticmethod def resolve_gn_args(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): indep_build_module.indep_build.regist_flag('gn-args', target_arg.arg_value) + + @staticmethod + def resolve_gn_flags(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): + indep_build_module.indep_build.regist_flag('gn-flags', target_arg.arg_value) @staticmethod def resolve_ninja_args(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): indep_build_module.indep_build.regist_flag('ninja-args', target_arg.arg_value) - @staticmethod - def resolve_export_compile_commands(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): - indep_build_module.indep_build.regist_flag('export-compile-commands', target_arg.arg_value) - if target_arg.arg_value: - LogUtil.hb_info('Perhaps you need to set the parameter --compile-commands-dir={dir of compile_commands.json} in the clangd plugin and restart language server.') - @staticmethod def resolve_skip_download(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): indep_build_module.hpm.regist_flag('skip-download', target_arg.arg_value) + indep_build_module.indep_build.regist_flag('skip-download', target_arg.arg_value) @staticmethod def resolve_build_target(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): diff --git a/hb/resources/args/default/indepbuildargs.json b/hb/resources/args/default/indepbuildargs.json index 38ff5e4c8c..6168ea6bde 100644 --- a/hb/resources/args/default/indepbuildargs.json +++ b/hb/resources/args/default/indepbuildargs.json @@ -102,6 +102,16 @@ "resolve_function": "resolve_gn_args", "testFunction": "" }, + "gn_flags": { + "arg_name": "--gn-flags", + "argDefault": [], + "arg_help": "Default:[]. Help:Specify gn build arguments, you could use this option like this 'hb build --gn-flags \"--export-compile-commands\"", + "arg_phase": "indepCompilation", + "arg_type": "list", + "arg_attribute": {}, + "resolve_function": "resolve_gn_flags", + "testFunction": "" + }, "ninja_args": { "arg_name": "--ninja-args", "argDefault": [], @@ -116,7 +126,7 @@ "arg_name": "--skip-download", "argDefault": false, "arg_help": "Default:false. Help:You can use this option to skip hpm download", - "arg_phase": "hpmDownload", + "arg_phase": ["hpmDownload","indepCompilation"], "arg_type": "bool", "arg_attribute": {}, "resolve_function": "resolve_skip_download", @@ -151,15 +161,5 @@ "arg_attribute": {}, "resolve_function": "resolve_ccache", "testFunction": "" - }, - "export_compile_commands": { - "arg_name": "--export-compile-commands", - "argDefault": false, - "arg_help": "Default:false. Help:Generate compile_commands.json", - "arg_phase": "indepCompilation", - "arg_type": "bool", - "arg_attribute": {}, - "resolve_function": "resolve_export_compile_commands", - "testFunction": "" } } \ No newline at end of file diff --git a/hb/services/indep_build.py b/hb/services/indep_build.py index 4456dcef09..973077cab4 100644 --- a/hb/services/indep_build.py +++ b/hb/services/indep_build.py @@ -33,6 +33,11 @@ class IndepBuild(BuildFileGeneratorInterface): cmd.extend(flags_list) variant = self.flags_dict["variant"] logpath = os.path.join('out', variant, 'build.log') + if self.flags_dict.get("skip-download") or self.flags_dict.get("fast-rebuild"): + if os.path.exists(logpath): + mtime = os.stat(logpath).st_mtime + os.rename(logpath, '{}/build.{}.log'.format(os.path.dirname(logpath), mtime)) + ret_code = SystemUtil.exec_command(cmd, log_path=logpath, pre_msg="run indep build", after_msg="indep build end") if ret_code != 0: diff --git a/indep_configs/scripts/gn_ninja_cmd.py b/indep_configs/scripts/gn_ninja_cmd.py index 595058c34b..85de6ea92b 100644 --- a/indep_configs/scripts/gn_ninja_cmd.py +++ b/indep_configs/scripts/gn_ninja_cmd.py @@ -21,10 +21,10 @@ from utils import ( get_json, get_ninja_args, get_gn_args, + get_gn_flags, is_enable_ccache, print_ccache_stats, clean_ccache_info, - is_export_compile_commands, ) sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -115,8 +115,8 @@ def _gn_cmd(root_path, variants, out_dir, test_filter): "-C", f"out/{variants}/{out_dir}", ] - if is_export_compile_commands(): - _cmd_list.append("--export-compile-commands") + input_gn_flags = get_gn_flags() + _cmd_list.extend(input_gn_flags) print( 'Executing gn command: {} {} --args="{}" {}'.format( diff --git a/indep_configs/scripts/utils.py b/indep_configs/scripts/utils.py index a0e1e18399..f12a4e33b9 100755 --- a/indep_configs/scripts/utils.py +++ b/indep_configs/scripts/utils.py @@ -66,11 +66,6 @@ def get_indep_args(): return None -def is_export_compile_commands(): - data = get_indep_args() - return data["export_compile_commands"]["argDefault"] - - def get_ninja_args(): """ Obtain the parameters for the Ninja build system from the independent build parameters. @@ -80,23 +75,26 @@ def get_ninja_args(): data = get_indep_args() input_ninja_args.extend(data["ninja_args"]["argDefault"]) if data["keep_ninja_going"]["argDefault"]: - input_ninja_args.append("-k10000") + input_ninja_args.append("-k100000") return input_ninja_args def get_gn_args(): - """ - Obtain the parameters for the GN build system from the independent build parameters. - :return: A list of GN parameters - """ input_gn_args = [] data = get_indep_args() if data["gn_args"]["argDefault"]: input_gn_args.extend(data["gn_args"]["argDefault"]) - return input_gn_args +def get_gn_flags(): + input_gn_flags = [] + data = get_indep_args() + if data["gn_flags"]["argDefault"]: + input_gn_flags.extend(data["gn_flags"]["argDefault"]) + return input_gn_flags + + def get_build_target(): """ Obtain the build targets from the independent build parameters. -- Gitee