From d91999e46b6b575bb176308540619ec86069c441 Mon Sep 17 00:00:00 2001 From: zhangwuf Date: Mon, 8 Jul 2024 16:27:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9diff=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwuf --- .../src/coreImpl/diff/diff_processor_node.py | 4 +++ .../src/coreImpl/parser/generating_tables.py | 10 ++++++ .../src/coreImpl/parser/parse_include.py | 18 ++++++---- .../capi_parser/src/coreImpl/parser/parser.py | 35 ++++++++++++------- .../capi_parser/src/typedef/diff/diff.py | 4 +-- .../capi_parser/src/utils/constants.py | 12 +++---- 6 files changed, 56 insertions(+), 27 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py b/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py index 19a2893b5f1..dfacb5c9925 100644 --- a/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py +++ b/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py @@ -123,6 +123,10 @@ def process_func_param_location(old_param_list, new_param_list): result_list = [] old_param_str_list = get_param_name_and_type(old_param_list) new_param_str_list = get_param_name_and_type(new_param_list) + old_param_str_content = ' '.join(old_param_str_list) + new_param_str_content = ' '.join(new_param_str_list) + if old_param_str_content == new_param_str_content: + return result_list old_len = len(old_param_list) for i, element in enumerate(old_param_str_list): if element not in new_param_str_list: diff --git a/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py b/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py index 05e59c2c980..cb07bf22cf7 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py +++ b/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py @@ -216,6 +216,16 @@ def get_json_file(generate_json_file, original_json_file): # 获取生成的jso return compare_result_list, head_name, generate_data_only_new, original_data_only # 返回对比数据,和所需表格名 +def get_parser_json_data(generate_json_file_path, parser_data): + generate_json_file_path = r'{}'.format(generate_json_file_path) # 获取要对比的json文件 + head_name = os.path.splitext(generate_json_file_path) # 去掉文件名后缀 + head_name = head_name[0] + '.xlsx' # 加后缀 + compare_result_list = [] + generate_data_only = filter_compare(parser_data) + original_data_only = [] + return compare_result_list, head_name, generate_data_only, original_data_only # 返回对比数据,和所需表格名 + + def get_api_data(parser_data, excel_file_name): generate_json_unique = [] original_json_unique = [] diff --git a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py index 45d6c095250..5401e37f970 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py @@ -96,7 +96,7 @@ def judgment_extern(cursor, data): # 判断是否带有extern def binary_operator(cursor, data): # 二元操作符处理 - data["name"] = "binary_ope_no_spelling" + data["name"] = "" tokens = cursor.get_tokens() spelling_arr = ['<<', '>>', '+', '-', '*', '/'] for token in tokens: @@ -117,7 +117,7 @@ def processing_parm(cursor, data): # 函数参数节点处理 if cursor.spelling: # 函数参数是否带参数名 data["name"] = cursor.spelling else: - data["name"] = "arg_no_spelling" + data["name"] = "" if cursor.type.get_pointee().kind == TypeKind.FUNCTIONPROTO: # 参数为函数指针,获取对应的返回类型 data["func_pointer_result_type"] = cursor.type.get_pointee().get_result().spelling @@ -169,10 +169,10 @@ def processing_type(cursor, data): # 没有类型的节点处理 def processing_name(cursor, data): # 没有名的节点处理 if cursor.kind == CursorKind.PAREN_EXPR: # 括号表达式() data["paren"] = "()" - data["name"] = "paren_expr_no_spelling" + data["name"] = "" elif cursor.kind == CursorKind.UNEXPOSED_EXPR: # 未公开表达式,用于表示未明确定义的表达式 - data["name"] = "unexposed_expr_no_spelling" + data["name"] = "" def processing_char(cursor, data): # 字符节点处理 @@ -357,6 +357,8 @@ def ast_to_dict(cursor, current_file, last_data, gn_path, comment=None, key=0): for child in children: # 剔除多余宏定义和跳过UNEXPOSED_ATTR节点 if (child.location.file is not None) and (not child.kind.is_attribute()) \ + and child.kind.name != CursorKind.MACRO_INSTANTIATION.name \ + and child.kind.name != CursorKind.INCLUSION_DIRECTIVE.name \ and (child.location.file.name == current_file): processing_ast_node(child, current_file, data, name, gn_path) else: @@ -499,7 +501,11 @@ def get_start_comments(include_path): # 获取每个头文件的最开始注释 line_dist = {} global calculation_times with open(include_path, 'r', encoding='utf-8') as f: - last_line = f.readlines()[-1] + file_line_data = f.readlines() + if file_line_data: + last_line = file_line_data[-1] + else: + last_line = -1 f.seek(0) content = '' mark = 0 @@ -520,7 +526,7 @@ def get_start_comments(include_path): # 获取每个头文件的最开始注释 line_number += 1 content += line line = f.readline() - if line == last_line: + if line == last_line and last_line != -1: mark = 0 if 0 == mark: content = '' diff --git a/build-tools/capi_parser/src/coreImpl/parser/parser.py b/build-tools/capi_parser/src/coreImpl/parser/parser.py index f9d897767b9..dca2f920caf 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parser.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parser.py @@ -160,6 +160,13 @@ def get_result_table(json_files, abs_path, link_path, gn_path): # 进行处理 (compare_result_list, head_name, generate_data_only, original_data_only) = generating_tables.get_json_file(parser_json_name, json_files) + elif abs_path: + file_name = os.path.splitext(os.path.split(abs_path[0])[1]) + parser_file_data = parse_include.get_include_file(abs_path, link_path, gn_path) + parser_json_name = change_json_file(parser_file_data, file_name[0]) # 生成json文件 + (compare_result_list, head_name, generate_data_only, + original_data_only) = generating_tables.get_parser_json_data(parser_json_name, parser_file_data) + obj_data = ParserGetResultTable(compare_result_list, head_name, generate_data_only, original_data_only, parser_file_data) @@ -170,7 +177,7 @@ def create_dir(sources_dir, gn_file, function_name, link_include_file): if sources_dir: for item in sources_dir: directory = item - new_dire = os.path.join('sysroot', directory) + new_dire = os.path.join('sysroot_myself', directory) new_dire = os.path.normpath(new_dire) if not os.path.exists(new_dire): os.makedirs(new_dire) @@ -258,11 +265,11 @@ def find_include(link_include_path): def copy_self_include(link_include_path, self_include_file, flag=-1): - for dir_path, _, file_name_list in os.walk(self_include_file): - for file in file_name_list: - if (file.endswith('.h') and ('sysroot' not in dir_path) - and (dir_path not in link_include_path)): - link_include_path.append(dir_path) + for dir_path, dir_name, file_name_list in os.walk(self_include_file): + for element in dir_name: + dir_path_name = os.path.abspath(os.path.join(dir_path, element)) + if 'sysroot_myself' not in dir_path and dir_path_name not in link_include_path: + link_include_path.append(dir_path_name) def delete_typedef_child(child): @@ -278,7 +285,7 @@ def parser(directory_path): # 目录路径 function_name = StringConstant.FUNK_NAME.value # 匹配的函数名 link_include_path = [] # 装链接头文件路径 - copy_std_lib(link_include_path) # ndk头文件移到sysroot中 + copy_std_lib(link_include_path) # 头文件移到sysroot_myself中 find_include(link_include_path) link_include(directory_path, function_name, link_include_path) @@ -288,15 +295,16 @@ def parser(directory_path): # 目录路径 def parser_include_ast(dire_file_path, include_path, flag=-1): # 对于单独的.h解析接口 correct_include_path = [] - - link_include_path = [] + link_include_path = [dire_file_path] + # 针对check if -1 == flag: copy_std_lib(link_include_path, dire_file_path) + link_include(dire_file_path, StringConstant.FUNK_NAME.value, link_include_path) + # 针对diff else: copy_std_lib(link_include_path) find_include(link_include_path) - link_include(dire_file_path, StringConstant.FUNK_NAME.value, link_include_path) - if len(link_include_path) <= 1: + if len(link_include_path) <= 2: copy_self_include(link_include_path, dire_file_path, flag) for item in include_path: split_path = os.path.splitext(item) @@ -318,9 +326,10 @@ def get_dir_file_path(dir_path): link_include_path = [] # 装链接头文件路径 for dir_path, dir_names, filenames in os.walk(dir_path): for dir_name in dir_names: - link_include_path.append(os.path.join(dir_path, dir_name)) + if 'build-tools' not in dir_path and 'sysroot_myself' not in dir_path: + link_include_path.append(os.path.join(dir_path, dir_name)) for file in filenames: - if 'build-tools' not in dir_path and 'sysroot' not in dir_path and file.endswith('.h'): + if 'build-tools' not in dir_path and 'sysroot_myself' 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 diff --git a/build-tools/capi_parser/src/typedef/diff/diff.py b/build-tools/capi_parser/src/typedef/diff/diff.py index cd95d1c5f68..6312b47aee2 100644 --- a/build-tools/capi_parser/src/typedef/diff/diff.py +++ b/build-tools/capi_parser/src/typedef/diff/diff.py @@ -51,14 +51,14 @@ class DiffType(enum.Enum): REDUCE_DOC = 'delete doc' ADD_DOC_TAG = 'add doc tag' REDUCE_DOC_TAG = 'delete doc tag' - FUNCTION_PARAM_POS_CHANGE = 'change param site in function' # 我觉得可以理解为函数参数类型改变 + FUNCTION_PARAM_POS_CHANGE = 'change param site in function' DEFINE_NAME_CHANGE = 'change define name' DEFINE_TEXT_CHANGE = 'change define text' FUNCTION_NAME_CHANGE = 'change function name' FUNCTION_RETURN_CHANGE = 'change function return value' - FUNCTION_PARAM_NAME_CHANGE = 'change param name in function' # 这个我觉得不考虑 + FUNCTION_PARAM_NAME_CHANGE = 'change param name in function' FUNCTION_PARAM_TYPE_CHANGE = 'change param type in function' FUNCTION_PARAM_ADD = 'add param in function' FUNCTION_PARAM_REDUCE = 'delete param in function' diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index 488ca3b3135..9c67d962b86 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -24,12 +24,12 @@ class StringConstant(enum.Enum): REPLACE_WAREHOUSE = '\\interface_sdk_c\\interface_sdk_c' # 拉到本地仓路径(去掉磁盘) # 拉到本地仓的三方库绝对路径 INCLUDE_LIB = r'.\third_party\musl\ndk_musl_include' - STD_INCLUDE = r'.\sysroot\ndk_musl_include_files' - CREATE_LIB_PATH = r'.\sysroot\$ndk_headers_out_dir' - SELF_INCLUDE = r'.\sysroot\self_include_files' - SELF_INCLUDE_OLD = r'.\sysroot\self_include_files_old' - SELF_INCLUDE_NEW = r'.\sysroot\self_include_files_new' - SYSROOT = r'.\sysroot' + STD_INCLUDE = r'.\sysroot_myself\std_include_files' + CREATE_LIB_PATH = r'.\sysroot_myself\$is_headers_out_dir' + SELF_INCLUDE = r'.\sysroot_myself\self_include_files' + SELF_INCLUDE_OLD = r'.\sysroot_myself\self_include_files_old' + SELF_INCLUDE_NEW = r'.\sysroot_myself\self_include_files_new' + SYSROOT = r'.\sysroot_myself' RESULT_HEAD_NAME = "result_total.xlsx" PARSER_DIRECT_EXCEL_NAME = 'parser_direct_data.xlsx' FILE_LEVEL_API_DATA = r'.\api_kit_c.json' -- Gitee