mirror of
https://gitee.com/openharmony/interface_sdk_c
synced 2024-11-23 14:50:20 +00:00
CAPI-DIFF工具结果新旧版本内容列中内容要与js一致,CAPI-统计工具结果增加开源/闭源/三方库API列
Signed-off-by: zhangwuf <zhangwu47@huawei.com>
This commit is contained in:
parent
f0093b53ab
commit
dcd5de6a23
@ -324,6 +324,7 @@ def parse_file_result(result, data_type=0):
|
||||
for root_node in result:
|
||||
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
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,9 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import openpyxl
|
||||
from typedef.parser.parser import DifferApiRegular, DifferApiInfor
|
||||
|
||||
|
||||
def compare_json_file(generate_json, original_json): # 获取对比结果
|
||||
@ -66,10 +68,25 @@ def filter_compare(analytic_data): # 获取函数和变量
|
||||
return result_api
|
||||
|
||||
|
||||
def difference_api(api_data: dict):
|
||||
api_name = api_data['name']
|
||||
differ_infor = DifferApiInfor.THIRD_PARTY_API.value
|
||||
closed_pattern = DifferApiRegular.CLOSED_SOURCE_API_REGULAR.value
|
||||
open_pattern = DifferApiRegular.OPEN_SOURCE_API_REGULAR.value
|
||||
if re.search(closed_pattern, api_name, flags=re.IGNORECASE):
|
||||
differ_infor = DifferApiInfor.CLOSED_SOURCE_API.value
|
||||
elif re.search(open_pattern, api_name, flags=re.IGNORECASE):
|
||||
differ_infor = DifferApiInfor.OPEN_SOURCE_API.value
|
||||
|
||||
return differ_infor
|
||||
|
||||
|
||||
def get_result_api(file_data, result_api):
|
||||
if 'children' in file_data:
|
||||
for item1 in file_data["children"]: # 抛开根节点
|
||||
if (item1["kind"] == 'FUNCTION_DECL' or item1["kind"] == 'VAR_DECL') and item1["is_extern"]:
|
||||
differ_infor = difference_api(item1)
|
||||
item1['differ_infor'] = differ_infor
|
||||
item = filter_func(item1)
|
||||
result_api.append(item)
|
||||
|
||||
@ -133,7 +150,8 @@ def collated_api_data(api_data: list):
|
||||
api.get('kit_name'),
|
||||
api.get('location_path'),
|
||||
api.get('sub_system'),
|
||||
api.get('unique_id')
|
||||
api.get('unique_id'),
|
||||
api.get('differ_infor')
|
||||
]
|
||||
collated_data_total.append(collated_data)
|
||||
return collated_data_total
|
||||
@ -143,7 +161,7 @@ def generate_excel(array, name, generate_json_unique, original_json_unique):
|
||||
first_line_infor = ['模块名', '类名', '方法名', '函数', '类型', '起始版本',
|
||||
'废弃版本', 'syscap', '错误码', '是否为系统API', '模型限制',
|
||||
'权限', '是否支持跨平台', '是否支持卡片应用', '是否支持高阶API',
|
||||
'装饰器', 'kit', '文件路径', '子系统', '接口全路径']
|
||||
'装饰器', 'kit', '文件路径', '子系统', '接口全路径', '开源/闭源/三方库API']
|
||||
workbook = openpyxl.Workbook()
|
||||
work_sheet1 = workbook.active
|
||||
work_sheet1.title = '对比结果'
|
||||
@ -166,7 +184,7 @@ def write_information_to_worksheet(work_sheet, information_data):
|
||||
write_data = data[0], data[1], data[2], data[3], data[4], \
|
||||
data[5], data[6], data[7], data[8], data[9], \
|
||||
data[10], data[11], data[12], data[13], data[14], \
|
||||
data[15], data[16], data[17], data[18], data[19]
|
||||
data[15], data[16], data[17], data[18], data[19], data[20]
|
||||
work_sheet.append(write_data)
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ def processing_root_parent(cursor_parent):
|
||||
return None
|
||||
|
||||
|
||||
def processing_no_child(cursor, data, last_data): # 处理没有子节点的节点
|
||||
def processing_no_child(cursor, data): # 处理没有子节点的节点
|
||||
if cursor.kind == CursorKind.INTEGER_LITERAL: # 整型字面量类型节点,没有子节点
|
||||
tokens = cursor.get_tokens()
|
||||
for token in tokens:
|
||||
@ -197,7 +197,7 @@ special_node_process = {
|
||||
}
|
||||
|
||||
|
||||
def get_api_unique_id(cursor, loc):
|
||||
def get_api_unique_id(cursor, loc, data):
|
||||
unique_id = ''
|
||||
if cursor.kind == CursorKind.MACRO_DEFINITION:
|
||||
unique_id = '{}#{}'.format(loc["location_path"], cursor.spelling)
|
||||
@ -213,6 +213,7 @@ def get_api_unique_id(cursor, loc):
|
||||
parent_name_str = ''
|
||||
elif parent_of_cursor.kind.name in struct_union_enum:
|
||||
parent_name_str = parent_of_cursor.type.spelling
|
||||
data['class_name'] = parent_of_cursor.spelling
|
||||
else:
|
||||
parent_name_str = parent_of_cursor.spelling
|
||||
except ValueError:
|
||||
@ -243,7 +244,9 @@ def processing_special_node(cursor, data, key, gn_path): # 处理需要特殊
|
||||
relative_path = os.path.relpath(location_path, gn_path) # 获取头文件相对路
|
||||
loc["location_path"] = relative_path
|
||||
data["location"] = loc
|
||||
data["unique_id"] = get_api_unique_id(cursor, loc)
|
||||
data["unique_id"] = get_api_unique_id(cursor, loc, data)
|
||||
if key == 0:
|
||||
data["unique_id"] = data["name"]
|
||||
if kind_name in special_node_process.keys():
|
||||
node_process = special_node_process[kind_name]
|
||||
node_process(cursor, data) # 调用对应节点处理函数
|
||||
@ -368,7 +371,7 @@ def ast_to_dict(cursor, current_file, last_data, gn_path, comment=None, key=0):
|
||||
else:
|
||||
if cursor.kind == CursorKind.FUNCTION_DECL: # 防止clang默认处理(对于头文件没有的情况)出现没有该键值对
|
||||
data["parm"] = []
|
||||
processing_no_child(cursor, data, last_data) # 处理没有子节点的节点
|
||||
processing_no_child(cursor, data) # 处理没有子节点的节点
|
||||
return data
|
||||
|
||||
|
||||
@ -494,10 +497,10 @@ 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): # 获取属性
|
||||
def preorder_travers_ast(cursor, comment, current_file, gn_path): # 获取属性
|
||||
previous_data = {}
|
||||
ast_dict = ast_to_dict(cursor, current_file, previous_data, gn_path, comment) # 获取节点属性
|
||||
total.append(ast_dict) # 追加到数据统计列表里面
|
||||
return ast_dict
|
||||
|
||||
|
||||
def get_start_comments(include_path): # 获取每个头文件的最开始注释
|
||||
@ -551,7 +554,7 @@ def get_start_comments(include_path): # 获取每个头文件的最开始注释
|
||||
return content
|
||||
|
||||
|
||||
def api_entrance(share_lib, include_path, gn_path, link_path=None): # 统计入口
|
||||
def api_entrance(share_lib, include_path, gn_path, link_path): # 统计入口
|
||||
# clang.cindex需要用到libclang.dll共享库 所以配置共享库
|
||||
if not Config.loaded:
|
||||
Config.set_library_file(share_lib)
|
||||
@ -569,8 +572,8 @@ def api_entrance(share_lib, include_path, gn_path, link_path=None): # 统计入
|
||||
ast_root_node = tu.cursor # 获取根节点
|
||||
matches = get_start_comments(item) # 接收文件最开始的注释
|
||||
# 前序遍历AST
|
||||
preorder_travers_ast(ast_root_node, data_total, matches, item, gn_path) # 调用处理函数
|
||||
|
||||
file_result_data = preorder_travers_ast(ast_root_node, matches, item, gn_path) # 调用处理函数
|
||||
data_total.append(file_result_data)
|
||||
iter_line_dist = iter(line_dist)
|
||||
first = next(iter_line_dist)
|
||||
array_index = int(first)
|
||||
|
@ -265,7 +265,7 @@ def find_include(link_include_path):
|
||||
link_include_path.append(dir_path)
|
||||
|
||||
|
||||
def copy_self_include(link_include_path, self_include_file, flag=-1):
|
||||
def copy_self_include(link_include_path, self_include_file):
|
||||
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))
|
||||
@ -294,7 +294,7 @@ def parser(directory_path): # 目录路径
|
||||
return data_total
|
||||
|
||||
|
||||
def parser_include_ast(dire_file_path, include_path, flag=-1): # 对于单独的.h解析接口
|
||||
def parser_include_ast(dire_file_path, include_path: list, flag=-1): # 对于单独的.h解析接口
|
||||
correct_include_path = []
|
||||
link_include_path = [dire_file_path]
|
||||
# 针对check
|
||||
@ -306,7 +306,7 @@ def parser_include_ast(dire_file_path, include_path, flag=-1): # 对于
|
||||
copy_std_lib(link_include_path)
|
||||
find_include(link_include_path)
|
||||
if len(link_include_path) <= 2:
|
||||
copy_self_include(link_include_path, dire_file_path, flag)
|
||||
copy_self_include(link_include_path, dire_file_path)
|
||||
for item in include_path:
|
||||
split_path = os.path.splitext(item)
|
||||
if split_path[1] == '.h': # 判断.h结尾
|
||||
|
@ -115,6 +115,7 @@ class Scene(enum.Enum):
|
||||
ENUM_DECL = 'ENUM_DECL'
|
||||
VAR_DECL = 'VAR_DECL'
|
||||
TYPEDEF_DECL = 'TYPEDEF_DECL'
|
||||
TRANSLATION_UNIT = 'TRANSLATION_UNIT'
|
||||
|
||||
|
||||
class TAGS(enum.Enum):
|
||||
@ -383,13 +384,17 @@ class DiffInfo:
|
||||
current_api_unique_id = ''
|
||||
is_system_api = False
|
||||
operation_diff_type: str = ''
|
||||
old_differ_content: str = ''
|
||||
new_differ_content: str = ''
|
||||
|
||||
def __init__(self, diff_type: DiffType):
|
||||
def __init__(self, diff_type: DiffType, old_differ_content, new_differ_content):
|
||||
self.diff_type = diff_type
|
||||
self.diff_message = diff_type.value
|
||||
self.set_diff_type(diff_type)
|
||||
self.set_api_modification_type(diff_type)
|
||||
self.set_operation_diff_type(diff_type)
|
||||
self.old_differ_content = old_differ_content
|
||||
self.new_differ_content = new_differ_content
|
||||
|
||||
def set_api_line(self, api_line):
|
||||
self.api_line = api_line
|
||||
@ -523,6 +528,18 @@ class DiffInfo:
|
||||
def get_operation_diff_type(self):
|
||||
return self.operation_diff_type
|
||||
|
||||
def set_old_differ_content(self, old_differ_content):
|
||||
self.old_differ_content = old_differ_content
|
||||
|
||||
def get_old_differ_content(self):
|
||||
return self.old_differ_content
|
||||
|
||||
def set_new_differ_content(self, new_differ_content):
|
||||
self.new_differ_content = new_differ_content
|
||||
|
||||
def get_new_differ_content(self):
|
||||
return self.new_differ_content
|
||||
|
||||
|
||||
class OutputJson:
|
||||
api_name: str = ''
|
||||
|
@ -75,3 +75,14 @@ class NodeKind(enum.Enum):
|
||||
ENUM_DECL = 'ENUM_DECL'
|
||||
FUNCTION_DECL = 'FUNCTION_DECL'
|
||||
VAR_DECL = 'VAR_DECL'
|
||||
|
||||
|
||||
class DifferApiRegular(enum.Enum):
|
||||
OPEN_SOURCE_API_REGULAR = r'^(OH_|ffrt|tee).*'
|
||||
CLOSED_SOURCE_API_REGULAR = r'^HMS_.*'
|
||||
|
||||
|
||||
class DifferApiInfor(enum.Enum):
|
||||
OPEN_SOURCE_API = '开源API'
|
||||
CLOSED_SOURCE_API = '闭源API'
|
||||
THIRD_PARTY_API = '三方库API'
|
||||
|
Loading…
Reference in New Issue
Block a user