Files
kunlun/build/buildcfg.gni

101 lines
3.6 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\)\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
}
# 如果不存在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 = []
# 把invoker中的变量复制到当前除了 configs
forward_variables_from(invoker, "*", [ "configs" ])
# 公共配置也可以在这里添加,以这种方式添加的配置不会被覆盖 这里不能定义configs变量是因为在其他地方通过set_default已经定义了
# configs+=["//ap:public"]
configs += invoker.configs
# 自动把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("source_module"){
source_set(target_name){
# 自动把src_files.txt 中的文件添加进来
forward_variables_from(invoker, "*", [ "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)
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
}
}
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
}
}
}
# 使用这个模板时的默认配置
set_defaults("kernel_module"){
configs = [
# 把这个目录的配置设置为公共配置,如果定义 kernel_module 模块时没有指定configs变量则这个变量默认填充为这里定义的值
# 如果指定了configs则以模块指定的为准
"//ap:public"
]
}
set_defaults("source_module"){
configs = [
# 把这个目录的配置设置为公共配置,如果定义 source_module 模块时没有指定configs变量则这个变量默认填充为这里定义的值
# 如果指定了configs则以模块指定的为准
"//ap:public"
]
}