Files
kunlun/build/buildcfg.gni

122 lines
3.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"
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")
if (target_name != current_dir_name) {
cmd = "if grep -q '^\s*\(module_group\|group\)\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
has_current_dir_group =
exec_script("//build/python_scripts/run_shell_cmd.py", [ cmd ], "value")
if (!has_current_dir_group && defined(auto_config)) {
module_name = target_name
group(current_dir_name) {
public_deps = [ ":$module_name" ]
}
}
}
if (defined(invoker.module_switch) && !invoker.module_switch) {
group(target_name) {
not_needed(invoker, "*")
}
} else {
source_set(target_name) {
public_configs = []
forward_variables_from(invoker, "*", [ "configs" ])
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)
sources+=source_list
inc=exec_script("//build/python_scripts/read_files.py",[rebase_path("."),"src_files.txt","inc"],"string")
inc_list=string_split(inc)
include_dirs+=inc_list
}
}
not_needed([ "auto_config" ])
}
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) {
deps = []
foreach(m, invoker.modules) {
deps += [ m ]
}
if (defined(invoker.deps)) {
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 = [
# 把这个目录的配置设置为公共配置
"//ap:public"
]
}