From f5142aaba1ac7f688241470ebc2aa9720f236fc0 Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Mon, 20 Jan 2025 11:33:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9BBUILD.gn?= =?UTF-8?q?=E6=96=87=E4=BB=B6,=20=E6=B7=BB=E5=8A=A0=20source=5Fmodule?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/buildcfg.gni | 21 +++++++++++++++++++++ common/BUILD.gn | 11 +++++++++-- common/io_lib/BUILD.gn | 8 ++++++++ common/pkt/BUILD.gn | 8 ++++++++ common/utils/BUILD.gn | 8 ++++++++ find_func_def.py | 28 ++++++++++++++-------------- startup/BUILD.gn | 11 +++++++++-- startup/riscv3/BUILD.gn | 8 ++++++++ 8 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 common/io_lib/BUILD.gn create mode 100644 common/pkt/BUILD.gn create mode 100644 common/utils/BUILD.gn create mode 100644 startup/riscv3/BUILD.gn diff --git a/build/buildcfg.gni b/build/buildcfg.gni index 782602a..dc00a78 100644 --- a/build/buildcfg.gni +++ b/build/buildcfg.gni @@ -44,6 +44,7 @@ template("kernel_module") { } else { source_set(target_name) { public_configs = [] + # 把invoker中的变量复制到当前,除了 configs forward_variables_from(invoker, "*", [ "configs" ]) configs += invoker.configs if (has_public_config) { @@ -71,6 +72,20 @@ template("kernel_module") { not_needed([ "auto_config" ]) } +template("source_module"){ + source_set(target_name){ + # 自动把src_files.txt 中的文件添加进来 + forward_variables_from(invoker, "*", [ "configs" ]) + # 单独赋值configs是因为这个变量有默认值 + 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("config") { @@ -118,4 +133,10 @@ set_defaults("kernel_module"){ ] } +set_defaults("source_module"){ + configs = [ + # 把这个目录的配置设置为公共配置 + "//ap:public" + ] +} diff --git a/common/BUILD.gn b/common/BUILD.gn index fca4687..dd35934 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -11,9 +11,16 @@ import("//build/buildcfg.gni") -module_name = "kl_sdk" +module_name = get_path_info(rebase_path("."), "name") -kernel_module(module_name) { +module_group(module_name) { + modules = ["pkt","io_lib","utils",":kl_sdk"] +} + +module_name1 = "kl_sdk" + +source_module(module_name1) { sources = [] include_dirs = [] } + diff --git a/common/io_lib/BUILD.gn b/common/io_lib/BUILD.gn new file mode 100644 index 0000000..0e3edc6 --- /dev/null +++ b/common/io_lib/BUILD.gn @@ -0,0 +1,8 @@ +import("//build/buildcfg.gni") + +module_name = "kl_sdk" + +kernel_module(module_name) { + sources=[] + include_dirs=[] +} \ No newline at end of file diff --git a/common/pkt/BUILD.gn b/common/pkt/BUILD.gn new file mode 100644 index 0000000..0e3edc6 --- /dev/null +++ b/common/pkt/BUILD.gn @@ -0,0 +1,8 @@ +import("//build/buildcfg.gni") + +module_name = "kl_sdk" + +kernel_module(module_name) { + sources=[] + include_dirs=[] +} \ No newline at end of file diff --git a/common/utils/BUILD.gn b/common/utils/BUILD.gn new file mode 100644 index 0000000..0e3edc6 --- /dev/null +++ b/common/utils/BUILD.gn @@ -0,0 +1,8 @@ +import("//build/buildcfg.gni") + +module_name = "kl_sdk" + +kernel_module(module_name) { + sources=[] + include_dirs=[] +} \ No newline at end of file diff --git a/find_func_def.py b/find_func_def.py index deb93a3..58f7f1d 100644 --- a/find_func_def.py +++ b/find_func_def.py @@ -368,18 +368,18 @@ def lex(text:bytes,file_name:str=""): else: buff.append(c_old&0xff) c_old=c - if not (lex_obj.deal_macro(buff)): # 处理宏 - is_space=True - while True: - c=lex_obj.get_next_char() - if(is_space and c==TOKEN('#')): - break - if(c==-1): - break - if not isspace(c): - is_space=False - elif(c==TOKEN('\n')): - is_space=True + # if not (lex_obj.deal_macro(buff)): # 处理宏 + # is_space=True + # while True: + # c=lex_obj.get_next_char() + # if(is_space and c==TOKEN('#')): + # break + # if(c==-1): + # break + # if not isspace(c): + # is_space=False + # elif(c==TOKEN('\n')): + # is_space=True elif isinstr(c,"/"): c=lex_obj.get_next_char() if(c==TOKEN("/")): @@ -420,8 +420,8 @@ def lex(text:bytes,file_name:str=""): else: lex_obj.save_one_char_token(TOKEN(".")) else: - raise Exception(f"未知的字符 {bytes([c])}, {lex_obj.file_name}:{lex_obj.line},{lex_obj.pos}") - # c=lex_obj.get_next_char() + # raise Exception(f"未知的字符 {bytes([c])}, {lex_obj.file_name}:{lex_obj.line},{lex_obj.pos}") + c=lex_obj.get_next_char() # if(line_old==lex_obj.line and pos_old==lex_obj.pos): # print(f"pointer not move.") # print(line_old,pos_old) diff --git a/startup/BUILD.gn b/startup/BUILD.gn index fca4687..2932cbe 100644 --- a/startup/BUILD.gn +++ b/startup/BUILD.gn @@ -11,9 +11,16 @@ import("//build/buildcfg.gni") -module_name = "kl_sdk" +module_name = get_path_info(rebase_path("."), "name") -kernel_module(module_name) { +module_group(module_name) { + modules = ["riscv3",":kl_sdk"] +} + +module_name1 = "kl_sdk" + +source_module(module_name1) { sources = [] include_dirs = [] } + diff --git a/startup/riscv3/BUILD.gn b/startup/riscv3/BUILD.gn new file mode 100644 index 0000000..96f6015 --- /dev/null +++ b/startup/riscv3/BUILD.gn @@ -0,0 +1,8 @@ +import("//build/buildcfg.gni") + +module_name = "kl_sdk" + +kernel_module(module_name) { + sources = [] + include_dirs = [] +}