From f12201b2c7018f7631615297340026f3d78aed28 Mon Sep 17 00:00:00 2001 From: zhangwuf Date: Fri, 26 Apr 2024 16:54:26 +0800 Subject: [PATCH] =?UTF-8?q?libclang.so=E8=B7=AF=E5=BE=84=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=92=8C=E6=96=87=E4=BB=B6=E7=BA=A7=E7=BB=9F=E8=AE=A1=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=9B=BA=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwuf --- build-tools/capi_parser/src/bin/config.py | 10 ++++++ .../capi_parser/src/coreImpl/parser/parser.py | 32 ++++++++++++++++--- .../capi_parser/src/utils/constants.py | 2 +- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/build-tools/capi_parser/src/bin/config.py b/build-tools/capi_parser/src/bin/config.py index e1b0c968d..7a891896a 100644 --- a/build-tools/capi_parser/src/bin/config.py +++ b/build-tools/capi_parser/src/bin/config.py @@ -24,6 +24,7 @@ class ToolNameType(enum.Enum): DIFF = 'diff' CHECK = 'check' COLLECT_H = 'collect_h' + COLLECT_FILE = 'collect_file' tool_name_type_set = [ @@ -53,6 +54,8 @@ def run_tools(options): check.curr_entry(options.parser_path) elif tool_name == ToolNameType['COLLECT_H'].value: parser.parser_direct(options.parser_path) + elif tool_name == ToolNameType['COLLECT_FILE'].value: + parser.parser_file_level(options.output_path) else: print("工具名称错误") @@ -78,6 +81,13 @@ class Config(object): "type": str, "help": "解析路径" }, + { + "name": "--output-path", + "abbr": "-O", + "required": True, + "type": str, + "help": "collect_file工具输出文件路径" + }, { "name": "--diff-path-old", "abbr": "-old", diff --git a/build-tools/capi_parser/src/coreImpl/parser/parser.py b/build-tools/capi_parser/src/coreImpl/parser/parser.py index a1e3930f9..f08f069ea 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parser.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parser.py @@ -332,7 +332,7 @@ def get_dir_file_path(dir_path): for dir_name in dir_names: link_include_path.append(os.path.join(dir_path, dir_name)) for file in filenames: - if file.endswith('.h'): + if 'build-tools' not in dir_path and file.endswith('.h'): file_path_list.append(os.path.join(dir_path, file)) return file_path_list, link_include_path @@ -362,19 +362,21 @@ def get_file_api_json(data_total): if 'name' in one_file_data and 'kit_name' in one_file_data and 'sub_system' in one_file_data: api_message_obj = OneFileApiMessage(one_file_data['name'], one_file_data['kit_name'], one_file_data['sub_system'], file_api_num) + api_message_obj.set_file_path(api_message_obj.get_file_path().replace('\\', '/')) current_file = os.path.dirname(__file__) kit_json_file_path = os.path.abspath(os.path.join(current_file, r"kit_sub_system/c_file_kit_sub_system.json")) complete_kit_or_system(api_message_obj, kit_json_file_path) - api_obj_total_list.append(api_message_obj) api_obj_total_json = json.dumps(api_obj_total_list, default=lambda obj: obj.__dict__, indent=4, ensure_ascii=False) return api_obj_total_json -def generate_file_api_json(json_data): - with open(StringConstant.FILE_LEVEL_API_DATA.value, 'w', encoding='utf-8') as fs: +def generate_file_api_json(json_data, output_path=''): + if not output_path: + output_path = StringConstant.FILE_LEVEL_API_DATA.value + with open(output_path, 'w', encoding='utf-8') as fs: fs.write(json_data) fs.close() @@ -395,7 +397,7 @@ def get_kit_system_data(json_path, relative_path): with open(json_path, 'r', encoding='utf-8') as fs: kit_system_data = json.load(fs) for data in kit_system_data['data']: - if 'filePath' in data and relative_path == data['filePath'].replace('/', '\\'): + if 'filePath' in data and relative_path in data['filePath']: kit_name = data['kitName'] sub_system_name = data['subSystem'] break @@ -421,3 +423,23 @@ def parser_direct(path): # 目录路径 generating_tables.get_api_data(data_total, StringConstant.PARSER_DIRECT_EXCEL_NAME.value) return data_total + + +def parser_file_level(output_path): + current_file = os.path.dirname(__file__) + parser_path = os.path.abspath(os.path.join(current_file, r'../../../../..')) + file_path_list = [] + link_include_path = [] # 装链接头文件路径 + dir_path = '' + if os.path.isdir(parser_path): + file_path_total, link_include_total = get_dir_file_path(parser_path) + file_path_list.extend(file_path_total) + link_include_path.extend(link_include_total) + dir_path = parser_path + else: + print('c_path is incorrect') + data_total = parse_include.get_include_file(file_path_list, link_include_path, dir_path) + file_api_json = get_file_api_json(data_total) + generate_file_api_json(file_api_json, output_path) + + return data_total diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index 4f26ca052..aed1044ee 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -19,7 +19,7 @@ import enum class StringConstant(enum.Enum): - LIB_CLG_PATH = r'home/tools/llvm/lib/libclang.so' # 共享库 + LIB_CLG_PATH = r'/home/tools/llvm/lib/libclang.so' # 共享库 FUNK_NAME = "ohos_ndk_headers" REPLACE_WAREHOUSE = '\\interface_sdk_c\\interface_sdk_c' # 拉到本地仓路径(去掉磁盘) # 拉到本地仓的三方库绝对路径