CAPI解析增加api版本信息

Signed-off-by: zhangwuf <zhangwu47@huawei.com>
This commit is contained in:
zhangwuf 2024-04-08 17:05:14 +08:00
parent e6a7e08c39
commit 54a9c11c91
6 changed files with 40 additions and 17 deletions

View File

@ -72,7 +72,8 @@ def result_to_json(check_result):
for result in check_result:
location = f'{result.location}(line:{result.location_line}, col:{result.location_column})'
message = 'API check error of [{}]:{}'.format(result.error_type['description'], result.error_info)
txt_resul.append(OutputTxt(result.error_type['id'], result.level, location, result.file_name, message))
txt_resul.append(OutputTxt(result.error_type['id'], result.level, result.api_since,
location, result.file_name, message))
return json.dumps(txt_resul, default=lambda obj: obj.__dict__, indent=4)

View File

@ -333,7 +333,6 @@ def process_each_comment(comment_object, file_doc_info: FileDocInfo, api_info) -
def process_tag_missing(comment_object, file_doc_info: FileDocInfo, api_info):
print(api_info['kind'])
api_result_info_list = []
if api_info['kind'] not in process_tag_missing_function.keys():
return []

View File

@ -88,7 +88,6 @@ def get_parm(item, parm):
def filter_func(item):
del item["is_extern"] # 剔除is_extern键值对过滤后都是extern
del item["comment"]
del item["syscap"]
if "type_ref" in list(item.keys()):
del item["type_ref"]
if "children" in list(item.keys()):
@ -114,7 +113,9 @@ def generate_excel(array, name, only_file1, only_file2):
'kind': '节点类型',
'type': '类型',
'gn_path': 'gn文件路径',
"node_content": '节点内容',
'node_content': '节点内容',
'syscap': 'syscap值',
'since': 'since版本',
'location': '位置行',
'return_type': '返回类型',
'parm': '参数',

View File

@ -261,7 +261,8 @@ def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解
"gn_path": gn_path,
"node_content": {},
"comment": '',
"syscap": ''
"syscap": '',
"since": ''
}
get_comment(cursor, data)
if key == 0:
@ -278,6 +279,7 @@ def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解
if cursor.kind.name == CursorKind.MACRO_DEFINITION.name:
define_comment(cursor, current_file, data)
get_syscap_value(data)
get_since_value(data)
processing_special_node(cursor, data, key, gn_path) # 节点处理
children = list(cursor.get_children()) # 判断是否有子节点有就追加children没有根据情况来
if len(children) > 0:
@ -300,6 +302,8 @@ def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解
and (child.location.file.name == current_file):
processing_ast_node(child, current_file, data, name, gn_path)
else:
if cursor.kind == CursorKind.FUNCTION_DECL: # 防止clang默认处理(对于头文件没有的情况)出现没有该键值对
data["parm"] = []
processing_no_child(cursor, data) # 处理没有子节点的节点
return data
@ -310,6 +314,15 @@ def get_syscap_value(data: dict):
matches = re.search(pattern, data['comment'])
if matches:
data["syscap"] = matches.group(0)
data["syscap"] = re.sub('@syscap', '', data["syscap"], flags=re.IGNORECASE)
def get_since_value(data: dict):
if 'none_comment' != data["comment"]:
pattern = r'@(since).*?(?=\n)'
matches = re.search(pattern, data['comment'])
if matches:
data["since"] = matches.group(0).replace('@since', '')
def get_comment(cursor, data: dict):

View File

@ -246,12 +246,14 @@ def copy_std_lib(link_include_file):
std_include = StringConstant.STD_INCLUDE.value
if not os.path.exists(std_include):
shutil.copytree(StringConstant.INCLUDE_LIB.value, std_include)
link_include_file.append(std_include)
if std_include not in link_include_file:
link_include_file.append(std_include)
def find_include(link_include_path):
for dir_path, _, _ in os.walk(StringConstant.CREATE_LIB_PATH.value):
link_include_path.append(dir_path)
if dir_path not in link_include_path:
link_include_path.append(dir_path)
def copy_self_include(link_include_path, self_include_file, flag=-1):
@ -262,14 +264,12 @@ def copy_self_include(link_include_path, self_include_file, flag=-1):
else:
std_include = StringConstant.SELF_INCLUDE.value
if std_include and not os.path.exists(std_include):
shutil.copytree(self_include_file, std_include)
for dir_path, _, files in os.walk(std_include):
for file in files:
if not file.endswith('.h'):
os.remove(os.path.join(dir_path, file))
elif dir_path not in link_include_path:
if not os.path.exists(std_include):
os.makedirs(std_include)
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)
@ -301,7 +301,8 @@ def parser_include_ast(gn_file_path, include_path, flag=-1): # 对于单
copy_std_lib(link_include_path)
find_include(link_include_path)
link_include(gn_file_path, StringConstant.FUNK_NAME.value, link_include_path)
copy_self_include(link_include_path, gn_file_path, flag)
if len(link_include_path) <= 1:
copy_self_include(link_include_path, gn_file_path, flag)
modes = stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU
fd = os.open('include_file_suffix.txt', os.O_WRONLY | os.O_CREAT, mode=modes)

View File

@ -159,13 +159,15 @@ be reused please delete the extra tags.'
class OutputTxt:
id = -1
level = -1
since = ''
location = ''
file_path = ''
message = ''
def __init__(self, id_param, level_param, location_param, file_path_param, message_param):
def __init__(self, id_param, level_param, api_since, location_param, file_path_param, message_param):
self.id = id_param
self.level = level_param
self.since = api_since
self.location = location_param
self.file_path = file_path_param
self.message = message_param
@ -182,6 +184,12 @@ class OutputTxt:
def set_level(self, level_param):
self.level = level_param
def get_since(self):
return self.since
def set_since(self, api_since):
self.level = api_since
def get_location(self):
return self.location