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 ad8ff44000f7ffb60a8f697bf0c4f33877d0fab1..1ca5cbcb4b21c2291f6b387626d57cbf919adfe4 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,29 @@ 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: + 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'] 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 f9a94a7cee2ead5f1661873681543235f6ed81cf..dd5a1bab583924aa0bf26b2483dad9283a9b0c76 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 1cbd015fcc79f7cffe0953b374abeef3c011a1bb..82133f4fd23fad7fce0ff7efb37f36e22c14ba7b 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'