From 7a47d6f36e4d03602842d8ce9b3086b026dbee96 Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Tue, 25 Feb 2025 19:41:14 +0800 Subject: [PATCH] =?UTF-8?q?build.gn=20=E5=8E=BB=E9=99=A4=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=E6=9C=AA=E7=94=A8=E5=88=B0=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/buildcfg.gni | 60 +++++++--------------------------------------- 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/build/buildcfg.gni b/build/buildcfg.gni index dc00a78..0d65989 100644 --- a/build/buildcfg.gni +++ b/build/buildcfg.gni @@ -6,22 +6,12 @@ import("//build/config.gni") template("kernel_module") { build_gn = rebase_path("BUILD.gn") # 如果只存在一个kernel_module,则auto_config=true - cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn" + cmd = "grep -c '^\s*\(kernel_module\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn" modules_count = exec_script("//build/python_scripts/run_shell_cmd.py", [ cmd ], "value") if (modules_count == 1) { auto_config = true } - # 如果不存在config("public")或者module_group,则创建config("public") - cmd = "if grep -q '^\s*\(config\s*(\s*\"public\"\s*)\|module_group\s*(\s*\"\S*\"\s*)\)\s*{\s*\$' $build_gn; then echo true; else echo false; fi" - has_public_config = - exec_script("//build/python_scripts/run_shell_cmd.py", [ cmd ], "value") - if (!has_public_config && defined(auto_config)) { - config("public") { - configs = [] - } - } - # 如果不存在module_group或group,则建立group # 如果用其他名称创建module,则自动生成一个以目录名称命名的module current_dir_name = get_path_info(rebase_path("."), "file") @@ -46,20 +36,9 @@ template("kernel_module") { public_configs = [] # 把invoker中的变量复制到当前,除了 configs forward_variables_from(invoker, "*", [ "configs" ]) + # 公共配置也可以在这里添加,以这种方式添加的配置不会被覆盖 这里不能定义configs变量是因为在其他地方通过set_default已经定义了 + # configs+=["//ap:public"] configs += invoker.configs - if (has_public_config) { - included_public_config = false - foreach(cfg, public_configs) { - what = "label_no_toolchain" - if (get_label_info(cfg, what) == get_label_info(":public", what)) { - included_public_config = true - } else { - } - } - if (!included_public_config) { - public_configs += [ ":public" ] - } - } # 自动把src_files.txt 中的文件添加进来 src=exec_script("//build/python_scripts/read_files.py",[rebase_path("."),"src_files.txt","src"],"string") source_list=string_split(src) @@ -76,7 +55,8 @@ template("source_module"){ source_set(target_name){ # 自动把src_files.txt 中的文件添加进来 forward_variables_from(invoker, "*", [ "configs" ]) - # 单独赋值configs是因为这个变量有默认值 + # 公共配置也可以在这里添加,以这种方式添加的配置不会被覆盖 这里不能定义configs变量是因为在其他地方通过set_default已经定义了 + # configs+=["//ap:public"] configs += invoker.configs src=exec_script("//build/python_scripts/read_files.py",[rebase_path("."),"src_files.txt","src"],"string") source_list=string_split(src) @@ -88,21 +68,6 @@ template("source_module"){ } -template("config") { - config(target_name) { - # 如果定义了module_switch 并且 module_switch为false 并且 配置名称为 "public" - if (defined(invoker.module_switch) && !invoker.module_switch && - target_name == "public") { - # 忽略调用者的所有变量,定义任意变量不会导致错误 - not_needed(invoker, "*") - # 将调用者的 configs 变量复制到当前 - forward_variables_from(invoker, [ "configs" ]) - } else { - forward_variables_from(invoker, "*") - } - } -} - template("module_group") { assert(defined(invoker.modules), "modules are must") group(target_name) { @@ -114,28 +79,21 @@ template("module_group") { deps += invoker.deps } } - config("public") { - configs = [] - foreach(m, invoker.modules) { - configs += [ "$m:public" ] - } - if (defined(invoker.configs)) { - configs += invoker.configs - } - } } # 使用这个模板时的默认配置 set_defaults("kernel_module"){ configs = [ - # 把这个目录的配置设置为公共配置 + # 把这个目录的配置设置为公共配置,如果定义 kernel_module 模块时没有指定configs变量,则这个变量默认填充为这里定义的值 + # 如果指定了configs,则以模块指定的为准 "//ap:public" ] } set_defaults("source_module"){ configs = [ - # 把这个目录的配置设置为公共配置 + # 把这个目录的配置设置为公共配置,如果定义 source_module 模块时没有指定configs变量,则这个变量默认填充为这里定义的值 + # 如果指定了configs,则以模块指定的为准 "//ap:public" ] }