From 2ef72eab4534e6ca0f025b23218f71e707f8dc26 Mon Sep 17 00:00:00 2001 From: openharmony_ci/wusongbai Date: Tue, 14 May 2024 15:01:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=A7=84=E5=88=99?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E6=96=87=E4=BB=B6=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=AF=94=E5=AF=B9=E6=96=87=E4=BB=B6=E6=9C=AC?= =?UTF-8?q?=E8=BA=AB=E4=BF=A1=E6=81=AF=EF=BC=9B=E6=B7=BB=E5=8A=A0=E8=A7=84?= =?UTF-8?q?=E5=88=99=EF=BC=9A=E5=B8=B8=E9=87=8F=E4=B8=8E=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E4=BA=92=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sam_wusb --- .../src/coreImpl/diff/diff_file.py | 36 +++++++++++-------- .../src/coreImpl/diff/diff_processor_node.py | 24 +++++++++++-- .../capi_parser/src/typedef/diff/diff.py | 4 +++ 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/diff/diff_file.py b/build-tools/capi_parser/src/coreImpl/diff/diff_file.py index ad8ff4400..61479547b 100644 --- a/build-tools/capi_parser/src/coreImpl/diff/diff_file.py +++ b/build-tools/capi_parser/src/coreImpl/diff/diff_file.py @@ -128,18 +128,18 @@ def add_new_file(diff_file_path): if os.path.isdir(diff_file_path): add_file(diff_file_path) else: - result_map = parse_file_result(parser_include_ast(global_new_dir, [diff_file_path], flag=1)) + result_map = parse_file_result(parser_include_ast(global_new_dir, [diff_file_path], flag=1), 1) for new_info in result_map.values(): - diff_info_list.extend(judgment_entrance(None, new_info)) + diff_info_list.extend(judgment_entrance(None, new_info, 1)) def del_old_file(diff_file_path): if os.path.isdir(diff_file_path): del_file(diff_file_path) else: - result_map = parse_file_result(parser_include_ast(global_old_dir, [diff_file_path], flag=0)) + result_map = parse_file_result(parser_include_ast(global_old_dir, [diff_file_path], flag=0), 1) for old_info in result_map.values(): - diff_info_list.extend(judgment_entrance(old_info, None)) + diff_info_list.extend(judgment_entrance(old_info, None, 1)) def get_same_file_diff(target_file, old_file_list, new_file_list, old_dir, new_dir): @@ -176,9 +176,9 @@ def del_file(dir_path): if os.path.isdir(file_path): del_file(file_path) if get_file_ext(i) == '.h': - result_map = parse_file_result(parser_include_ast(global_old_dir, [file_path], flag=0)) + result_map = parse_file_result(parser_include_ast(global_old_dir, [file_path], flag=0), 1) for old_info in result_map.values(): - diff_info_list.extend(judgment_entrance(old_info, None)) + diff_info_list.extend(judgment_entrance(old_info, None, 1)) def add_file(dir_path): @@ -190,19 +190,25 @@ def add_file(dir_path): if os.path.isdir(file_path): add_file(file_path) if get_file_ext(i) == '.h': - result_map = parse_file_result(parser_include_ast(global_new_dir, [file_path], flag=1)) + result_map = parse_file_result(parser_include_ast(global_new_dir, [file_path], flag=1), 1) for new_info in result_map.values(): - diff_info_list.extend(judgment_entrance(None, new_info)) + diff_info_list.extend(judgment_entrance(None, new_info, 1)) -def parse_file_result(result): +def parse_file_result(result, data_type=0): + """ + Args: + result: *** + data_type(int): 数据处理类型。1-文件新增或删除;0-其他 + """ result_map = {} for root_node in result: - children_list = root_node['children'] - for children in children_list: - if children["name"] == '': - continue - result_map.setdefault(f'{children["name"]}-{children["kind"]}', children) - del root_node['children'] + if data_type != 1: + children_list = root_node['children'] + for children in children_list: + if children["name"] == '': + continue + result_map.setdefault(f'{children["name"]}-{children["kind"]}', children) + del root_node['children'] result_map.setdefault(f'{root_node["name"]}-{root_node["kind"]}', root_node) return result_map 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 f9a94a7ce..dd5a1bab5 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 @@ -388,17 +388,23 @@ def process_variable_const(old, new): diff_var_or_con = [] if 'is_const' in old: if old['is_const']: # 处理常量 + process_constant_to_variable(old, new, diff_var_or_con) # 常量改变量 process_constant_name(old, new, diff_var_or_con) # 处理常量名 process_constant_type(old, new, diff_var_or_con) # 处理常量类型 process_constant_value(old, new, diff_var_or_con) # 处理常量值 else: # 处理变量 + process_variable_to_constant(old, new, diff_var_or_con) # 变量改常量 process_variable_name(old, new, diff_var_or_con) # 处理变量名 process_variable_type(old, new, diff_var_or_con) # 处理变量类型 process_variable_value(old, new, diff_var_or_con) # 处理变量值 return diff_var_or_con +def process_variable_to_constant(old, new, diff_variable_list): + if new['is_const']: + diff_info = wrap_diff_info(old, new, DiffInfo(DiffType.VARIABLE_CHANGE_TO_CONSTANT)) + diff_variable_list.append(diff_info) def process_variable_name(old, new, diff_variable_list): if old['name'] != new['name']: @@ -430,6 +436,10 @@ def process_variable_value(old, new, diff_variable_list): DiffInfo(DiffType.VARIABLE_VALUE_CHANGE)) diff_variable_list.append(diff_info) +def process_constant_to_variable(old, new, diff_constant_list): + if not new['is_const']: + diff_info = wrap_diff_info(old, new, DiffInfo(DiffType.CONSTANT_CHANGE_TO_VARIABLE)) + diff_constant_list.append(diff_info) def process_constant_name(old, new, diff_constant_list): if old['name'] != new['name']: @@ -510,15 +520,23 @@ process_data = { } -def judgment_entrance(old, new): +def judgment_entrance(old, new, data_type=0): + """ + Args: + old: *** + new: *** + data_type(int): 数据处理类型。1-文件新增或删除;0-其他 + """ diff_info_list = [] if old is None and new is None: return diff_info_list if old is None: - diff_info_list.append(wrap_diff_info(old, new, DiffInfo(DiffType.ADD_API))) + 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))) return diff_info_list if new is None: - diff_info_list.append(wrap_diff_info(old, new, DiffInfo(DiffType.REDUCE_API))) + 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))) return diff_info_list kind = new['kind'] diff_info_list.extend(process_comment_str(old, new)) diff --git a/build-tools/capi_parser/src/typedef/diff/diff.py b/build-tools/capi_parser/src/typedef/diff/diff.py index 1cbd015fc..82133f4fd 100644 --- a/build-tools/capi_parser/src/typedef/diff/diff.py +++ b/build-tools/capi_parser/src/typedef/diff/diff.py @@ -43,6 +43,8 @@ class TAGS(enum.Enum): class DiffType(enum.Enum): DEFAULT = '' + ADD_FILE = 'add file' + REDUCE_FILE = 'delete file' ADD_API = 'add api' REDUCE_API = 'delete api' ADD_DOC = 'add doc' @@ -83,11 +85,13 @@ class DiffType(enum.Enum): VARIABLE_TYPE_CHANGE = 'change variable type' VARIABLE_VALUE_CHANGE = 'change variable value' VARIABLE_CHANGE_CONST = 'Change variable to constant' + VARIABLE_CHANGE_TO_CONSTANT = 'change variable to constant' CONSTANT_NAME_CHANGE = 'change constant name' CONSTANT_TYPE_CHANGE = 'change constant type' CONSTANT_VALUE_CHANGE = 'change constant value' CONST_CHANGE_VARIABLE = 'Change constant to variable' + CONSTANT_CHANGE_TO_VARIABLE = 'change constant to variable' TYPEDEF_NAME_TYPE_CHANGE = 'change typedef name type' -- Gitee From 774ed57674f0235480a5e00662a7db336d9308fd Mon Sep 17 00:00:00 2001 From: sam_wusb Date: Tue, 14 May 2024 19:34:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=97=A8=E7=A6=81=E5=9C=88=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E5=BA=A6=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sam_wusb --- .../capi_parser/src/coreImpl/diff/diff_file.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/diff/diff_file.py b/build-tools/capi_parser/src/coreImpl/diff/diff_file.py index 61479547b..1ca5cbcb4 100644 --- a/build-tools/capi_parser/src/coreImpl/diff/diff_file.py +++ b/build-tools/capi_parser/src/coreImpl/diff/diff_file.py @@ -204,11 +204,15 @@ def parse_file_result(result, data_type=0): result_map = {} for root_node in result: if data_type != 1: - children_list = root_node['children'] - for children in children_list: - if children["name"] == '': - continue - result_map.setdefault(f'{children["name"]}-{children["kind"]}', children) - del root_node['children'] + parse_file_result_by_child(result_map, root_node) result_map.setdefault(f'{root_node["name"]}-{root_node["kind"]}', root_node) return result_map + + +def parse_file_result_by_child(result_map, root_node): + children_list = root_node['children'] + for children in children_list: + if children["name"] == '': + continue + result_map.setdefault(f'{children["name"]}-{children["kind"]}', children) + del root_node['children'] -- Gitee