build.gn 去除模板中未用到的配置
This commit is contained in:
@@ -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"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user