From cadf57f8ddb95c0e87812031c6477742fad4c0e1 Mon Sep 17 00:00:00 2001 From: zhangwuf Date: Sat, 15 Jun 2024 09:47:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9diff=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=EF=BC=9Adiff=E7=BB=93=E6=9E=9C=E6=98=AF=E5=90=A6=E4=B8=BAapi?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E5=88=97=EF=BC=8C=E6=8C=89=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9A=84=E8=A6=81=E6=B1=82(=E7=AC=A6?= =?UTF-8?q?=E5=90=88=E8=A6=81=E6=B1=82=E7=9A=84=E5=87=BD=E6=95=B0=E5=92=8C?= =?UTF-8?q?=E5=8F=98=E9=87=8F)?= 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 | 25 ++++++++++++------- .../src/coreImpl/parser/parse_include.py | 19 +++++++++----- 2 files changed, 29 insertions(+), 15 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 4f937f991..d1d11a321 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 @@ -36,13 +36,9 @@ def get_not_api_kind_list(): def wrap_diff_info(old_info, new_info, diff_info: DiffInfo): - not_api_kind_list = get_not_api_kind_list() if old_info is not None: if 'temporary_name' in old_info['name']: old_info['name'] = '' - if (not diff_info.is_api_change) and 'kind' in old_info \ - and (old_info['kind'] not in not_api_kind_list): - diff_info.set_is_api_change(True) diff_info.set_api_name(old_info['name']) diff_info.set_api_type(old_info['kind']) diff_info.set_api_line(old_info['location']['location_line']) @@ -63,9 +59,6 @@ def wrap_diff_info(old_info, new_info, diff_info: DiffInfo): if new_info is not None: if 'temporary_name' in new_info['name']: new_info['name'] = '' - if (not diff_info.is_api_change) and 'kind' in new_info \ - and (new_info['kind'] not in not_api_kind_list): - diff_info.set_is_api_change(True) diff_info.set_api_name(new_info['name']) diff_info.set_api_type(new_info['kind']) diff_info.set_api_line(new_info['location']['location_line']) @@ -108,8 +101,6 @@ def get_member_result_diff(old_target, new_target): def get_initial_result_obj(diff_type: DiffType, new_node, old_node=None): result_message_obj = DiffInfo(diff_type) - if 'kind' in new_node and 'MACRO_DEFINITION' != new_node['kind']: - result_message_obj.set_is_api_change(True) return result_message_obj @@ -587,6 +578,12 @@ def collect_change_data_total(data: dict, diff_info_list): change_data_total.append(diff_info_list) +def set_is_api_change_result(result_data, key_extern): + for element in result_data: + if key_extern: + element.set_is_api_change(True) + + def judgment_entrance(old, new, data_type=0): """ Args: @@ -595,25 +592,35 @@ def judgment_entrance(old, new, data_type=0): data_type(int): 数据处理类型。1-文件新增或删除;0-其他 """ diff_info_list = [] + key_extern = False if old is None and new is None: return diff_info_list if old is None: + if 'is_extern' in new and new['is_extern']: + key_extern = True diff_type = DiffType.ADD_FILE if data_type == 1 else DiffType.ADD_API diff_info_list.append(wrap_diff_info(old, new, DiffInfo(diff_type))) + set_is_api_change_result(diff_info_list, key_extern) if diff_type == DiffType.ADD_API: collect_change_data_total(new, diff_info_list) return diff_info_list if new is None: + if 'is_extern' in old and old['is_extern']: + key_extern = True diff_type = DiffType.REDUCE_FILE if data_type == 1 else DiffType.REDUCE_API diff_info_list.append(wrap_diff_info(old, new, DiffInfo(diff_type))) if diff_type == DiffType.REDUCE_API: + set_is_api_change_result(diff_info_list, key_extern) collect_change_data_total(old, diff_info_list) return diff_info_list kind = new['kind'] + if 'is_extern' in old and old['is_extern']: + key_extern = True diff_info_list.extend(process_comment_str(old, new)) if kind in process_data: diff_info_list.extend(process_data[kind](old, new)) if diff_info_list: + set_is_api_change_result(diff_info_list, key_extern) collect_change_data_total(new, diff_info_list) return diff_info_list 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 70c446b0f..9ec8750a9 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py @@ -195,16 +195,23 @@ special_node_process = { def get_api_unique_id(cursor, loc): parent_of_cursor = cursor.semantic_parent + struct_union_enum = [NodeKind.STRUCT_DECL.value, NodeKind.UNION_DECL.value, + NodeKind.ENUM_DECL.value] unique_id = '' if parent_of_cursor: + unique_name = cursor.spelling if parent_of_cursor.kind == CursorKind.TRANSLATION_UNIT: parent_name_str = '' + elif parent_of_cursor.kind.name in struct_union_enum: + parent_name_str = parent_of_cursor.type.spelling else: parent_name_str = parent_of_cursor.spelling + if cursor.kind.name in struct_union_enum: + unique_name = cursor.type.spelling if not parent_name_str: - unique_id = '{}#{}'.format(loc["location_path"], cursor.spelling) + unique_id = '{}#{}'.format(loc["location_path"], unique_name) else: - unique_id = '{}#{}#{}'.format(loc["location_path"], parent_name_str, cursor.spelling) + unique_id = '{}#{}#{}'.format(loc["location_path"], parent_name_str, unique_name) return unique_id @@ -318,7 +325,7 @@ def parser_data_assignment(cursor, current_file, gn_path=None, comment=None, key return data -def ast_to_dict(cursor, current_file, last_data, gn_path=None, comment=None, key=0): # 解析数据的整理 +def ast_to_dict(cursor, current_file, last_data, gn_path, comment=None, key=0): # 解析数据的整理 # 通用赋值 data = parser_data_assignment(cursor, current_file, gn_path, comment, key) if last_data: @@ -474,7 +481,7 @@ def processing_ast_node(child, current_file, data, name, gn_path): data[name].append(child_data) -def preorder_travers_ast(cursor, total, comment, current_file, gn_path=None): # 获取属性 +def preorder_travers_ast(cursor, total, comment, current_file, gn_path): # 获取属性 previous_data = {} ast_dict = ast_to_dict(cursor, current_file, previous_data, gn_path, comment) # 获取节点属性 total.append(ast_dict) # 追加到数据统计列表里面 @@ -524,7 +531,7 @@ def open_file(include_path): return content -def api_entrance(share_lib, include_path, gn_path=None, link_path=None): # 统计入口 +def api_entrance(share_lib, include_path, gn_path, link_path=None): # 统计入口 # clang.cindex需要用到libclang.dll共享库 所以配置共享库 if not Config.loaded: Config.set_library_file(share_lib) @@ -547,7 +554,7 @@ def api_entrance(share_lib, include_path, gn_path=None, link_path=None): # 统 return data_total -def get_include_file(include_file_path, link_path, gn_path=None): # 库路径、.h文件路径、链接头文件路径 +def get_include_file(include_file_path, link_path, gn_path): # 库路径、.h文件路径、链接头文件路径 # libclang.dll库路径 libclang_path = StringConstant.LIB_CLG_PATH.value # c头文件的路径