diff --git a/build-tools/capi_parser/requirements.txt b/build-tools/capi_parser/requirements.txt index e623e5c24d68c5da8aed925fa4b4411dc162084f..d4185940174f0f7c7369b30a840b57329dd7e4d5 100644 Binary files a/build-tools/capi_parser/requirements.txt and b/build-tools/capi_parser/requirements.txt differ diff --git a/build-tools/capi_parser/src/coreImpl/check/check.py b/build-tools/capi_parser/src/coreImpl/check/check.py index b7dea726e93a80d7a81629f58d668e6f9353f961..ce5fc5417c6599cf136f0ae565606cb8506c303f 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check.py +++ b/build-tools/capi_parser/src/coreImpl/check/check.py @@ -80,7 +80,8 @@ def result_to_json(check_result): return json.dumps(txt_resul, default=lambda obj: obj.__dict__, indent=4) -def curr_entry(file_list): +def curr_entry(file_path): + file_list = get_md_files(file_path) check_result_list = get_check_result_list(file_list) write_in_txt(check_result_list, r'./Error.txt') @@ -95,3 +96,13 @@ def get_check_result_list(file_list): check_result_list.extend(check_syntax(file)) return check_result_list + +def get_md_files(url): + file = open(url, "r") + file_list = [] + line = file.readline() + while line: + file_list.append(line.splitlines()[0]) + line = file.readline() + file.close() + return file_list diff --git a/build-tools/capi_parser/src/coreImpl/check/check_doc.py b/build-tools/capi_parser/src/coreImpl/check/check_doc.py index d020d5a719eca2ed7a4a419f27868201957242f8..3329e1bfc8cccc7bc37c9cb4bce859839fdc89a2 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check_doc.py +++ b/build-tools/capi_parser/src/coreImpl/check/check_doc.py @@ -38,7 +38,7 @@ def create_api_result_info_by_doc(error_type: ErrorType, error: ErrorMessage, pa error_info = error_info.replace('$$', str(param), 1) api_result_info = ApiResultInfo(error_type.value, error_info, api_info['name']) api_result_info.set_type(LogType.LOG_JSDOC.value) - api_result_info.set_level(ErrorLevel.MIDDLE.value) + api_result_info.set_level(ErrorLevel.LOW.value) if 'location' in api_info.keys(): api_result_info.set_location(api_info['location']['location_path']) api_result_info.set_location_line(api_info['location']['location_line']) diff --git a/build-tools/capi_parser/src/coreImpl/check/check_name.py b/build-tools/capi_parser/src/coreImpl/check/check_name.py index 0ef0048da637e9a68e39bb54888c2e8227c00211..c80a3dac69964706d662734ea766184953e08259 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check_name.py +++ b/build-tools/capi_parser/src/coreImpl/check/check_name.py @@ -16,7 +16,7 @@ import enum import os.path import re -from typedef.check.check import ApiResultInfo, ErrorMessage, ErrorType, LogType +from typedef.check.check import ApiResultInfo, ErrorMessage, ErrorType, LogType, ErrorLevel def check_large_hump(api_info): @@ -37,7 +37,7 @@ def check_function_name(api_info): api_result_info.set_location_column(api_info['location']['location_column']) api_result_info.set_location(api_info['location']['location_path']) api_result_info.set_type(LogType.LOG_API.value) - api_result_info.set_level(2) + api_result_info.set_level(ErrorLevel.LOW.value) api_result_info.set_file_name(api_info['location']['location_path']) api_result_info_list.append(api_result_info) return api_result_info_list @@ -73,7 +73,7 @@ def check_file_name(file_path): api_result_info.set_type(LogType.LOG_FILE.value) api_result_info.set_file_name(file_path) api_result_info.set_location(file_path) - api_result_info.set_level(2) + api_result_info.set_level(ErrorLevel.LOW.value) api_result_info_list.append(api_result_info) return api_result_info_list @@ -89,7 +89,7 @@ def processing_check_data(function_type, api_info): api_result_info.set_location_column(api_info['location']['location_column']) api_result_info.set_location(api_info['location']['location_path']) api_result_info.set_type(LogType.LOG_API.value) - api_result_info.set_level(2) + api_result_info.set_level(ErrorLevel.LOW.value) api_result_info.set_file_name(api_info['location']['location_path']) api_result_info_list.append(api_result_info) return api_result_info_list diff --git a/build-tools/capi_parser/src/coreImpl/check/check_syntax.py b/build-tools/capi_parser/src/coreImpl/check/check_syntax.py index 328b2dc23a291f95aca393ad1821397dce76f58c..b06307628cb613351867734f11e63dac596738b4 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check_syntax.py +++ b/build-tools/capi_parser/src/coreImpl/check/check_syntax.py @@ -15,7 +15,7 @@ import re import subprocess -from typedef.check.check import ApiResultInfo, ErrorMessage, ErrorType, LogType +from typedef.check.check import ApiResultInfo, ErrorMessage, ErrorType, LogType, ErrorLevel def check_syntax(file_path): @@ -44,7 +44,7 @@ def processing_data(run_result, result_file): api_result_info.set_location_column(line_column[1]) api_result_info.set_location(result_file) api_result_info.set_type(LogType.LOG_API.value) - api_result_info.set_level(2) + api_result_info.set_level(ErrorLevel.LOW.value) api_result_info.set_file_name(result_file) api_result_info_list.append(api_result_info) return api_result_info_list 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 6554ce32fab511b1ae125921a499d16816ca737e..f45f3eab232df338f785d56fa46c529ebd1a9bb3 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 @@ -343,17 +343,18 @@ def process_variable_type(old, new, diff_variable_list): def process_variable_value(old, new, diff_variable_list): if 'children' in old and 'children' in new: - if old['children'][0]['node_content']['content'] != new['children'][0]['node_content']['content']: + if len(old['children']) and len(new['children']) \ + and old['children'][0]['node_content']['content'] != new['children'][0]['node_content']['content']: diff_info = wrap_diff_info(old['children'][0], new['children'][0], DiffInfo(DiffType.VARIABLE_VALUE_CHANGE)) diff_variable_list.append(diff_info) - elif 'children' not in old and 'children' in new: + elif 'children' not in old and 'children' in new and len(new['children']): diff_info = wrap_diff_info(old, new['children'][0], DiffInfo(DiffType.VARIABLE_VALUE_CHANGE)) diff_variable_list.append(diff_info) - elif 'children' in old and 'children' not in new: + elif 'children' in old and 'children' not in new and len(old['children']): diff_info = wrap_diff_info(old['children'][0], new, DiffInfo(DiffType.VARIABLE_VALUE_CHANGE)) diff_variable_list.append(diff_info) @@ -373,7 +374,8 @@ def process_constant_type(old, new, diff_constant_list): def process_constant_value(old, new, diff_constant_list): if 'children' in old and 'children' in new: - if old['children'][0]['node_content']['content'] != new['children'][0]['node_content']['content']: + if len(old['children']) and len(new['children']) \ + and old['children'][0]['node_content']['content'] != new['children'][0]['node_content']['content']: diff_info = wrap_diff_info(old['children'][0], new['children'][0], DiffInfo(DiffType.CONSTANT_VALUE_CHANGE)) diff_constant_list.append(diff_info) 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 cf92d76c3b1e6ce17014b304c14bf5ffa6f74d56..40e02e42e48243b0de39f8cb7ac2e839275dd174 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py @@ -78,10 +78,14 @@ def get_complex_def(tokens_new, count_token, tokens, data): count_com = 0 for token_2 in tokens_new: if token_2.spelling == ')': - logo = 1 break else: count += 1 + if count != count_token: + for token in tokens_new[count:]: + if token.spelling == '{' or token.spelling == '(' or token.spelling == '##': + logo = 1 + if count_token == count: pass elif logo == 1: # 获取复合型宏定义宏名 @@ -183,10 +187,26 @@ def processing_enum(cursor, data): # 获取枚举值 def processing_def(cursor, data): # 处理宏定义 - marco_ext = cursor.extent - tokens = cursor.translation_unit.get_tokens(extent=marco_ext) # 找到对应的宏定义位置 - tokens = list(tokens) # Generator转为list - processing_complex_def(tokens, data) # 获取宏名和宏文本 + if data['node_content']['content']: + split_data = data['node_content']['content'].split() + split_data_three = data['node_content']['content'].split('\t') + if len(split_data) == 2: + pattern = r'\((.*?), (.*?)\)' + if re.search(pattern, data['node_content']['content']): + data['name'] = data['node_content']['content'] + else: + data['name'] = split_data[0] + data['text'] = split_data[1] + elif len(split_data_three) == 2: + data['name'] = split_data[0] + data['text'] = split_data[1] + else: + marco_ext = cursor.extent + tokens = cursor.translation_unit.get_tokens(extent=marco_ext) # 找到对应的宏定义位置 + tokens = list(tokens) # Generator转为list + processing_complex_def(tokens, data) # 获取宏名和宏文本 + else: + print('mar_define error, its content is none') data["type"] = "def_no_type" diff --git a/build-tools/capi_parser/src/coreImpl/parser/parser.py b/build-tools/capi_parser/src/coreImpl/parser/parser.py index 5bc825b6595c8aa93fb1bd1061e54e9abf602387..cdf69a0d04d4a55584d6b92aa58fe1bf74e2ae4f 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parser.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parser.py @@ -253,6 +253,27 @@ def find_include(link_include_path): link_include_path.append(dir_path) +def copy_self_include(link_include_file, self_include_file): + std_include = StringConstant.SELF_INCLUDE.value + if not os.path.exists(std_include): + os.makedirs(std_include) + + if self_include_file: + for item in self_include_file: + shutil.copy(item, std_include) + + link_include_file.append(std_include) + + +def delete_typedef_child(child): + if child['kind'] == 'TYPEDEF_DECL': + if 'children' in child and len(child['children']) \ + and (child['children'][0]['kind'] == 'STRUCT_DECL' + or child['children'][0]['kind'] == 'ENUM_DECL' + or child['children'][0]['kind'] == 'UNION_DECL'): + child['children'] = [] + + def parser(directory_path): # 目录路径 function_name = StringConstant.FUNK_NAME.value # 匹配的函数名 @@ -265,9 +286,14 @@ def parser(directory_path): # 目录路径 return data_total -def parser_include_ast(gn_file_path, include_path): # 对于单独的.h解析接口 +def parser_include_ast(gn_file_path, include_path, self_include=None): # 对于单独的.h解析接口 correct_include_path = [] - link_path = [StringConstant.INCLUDE_LIB.value] + + link_include_path = [] + copy_std_lib(link_include_path) + find_include(link_include_path) + copy_self_include(link_include_path, self_include) + 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) for item in include_path: @@ -278,5 +304,13 @@ def parser_include_ast(gn_file_path, include_path): # 对于单独的.h exc = 'The file does not end with.h: {}\n'.format(item) os.write(fd, exc.encode()) os.close(fd) - data = parse_include.get_include_file(correct_include_path, link_path, gn_file_path) + + data = parse_include.get_include_file(correct_include_path, link_include_path, gn_file_path) + + for item in data: + if 'children' in item: + for child in item['children']: + delete_typedef_child(child) + + shutil.rmtree(StringConstant.SELF_INCLUDE.value) return data diff --git a/build-tools/capi_parser/src/typedef/check/check.py b/build-tools/capi_parser/src/typedef/check/check.py index b5dbc4eb7342105fe760f61e4744e959d314ab15..845e7381286044cf157c00d1da0853bbb56363e4 100644 --- a/build-tools/capi_parser/src/typedef/check/check.py +++ b/build-tools/capi_parser/src/typedef/check/check.py @@ -32,67 +32,71 @@ class TAGS(enum.Enum): class ErrorType(enum.Enum): - UNKNOW_DECORATOR: { + DEFAULT = { + 'id': -1, + 'description': '', + } + UNKNOW_DECORATOR = { id: 0, 'description': 'unknow decorator', } - MISSPELL_WORDS: { + MISSPELL_WORDS = { id: 1, 'description': 'misspell words', } - NAMING_ERRORS: { + NAMING_ERRORS = { id: 2, 'description': 'naming errors', } - UNKNOW_PERMISSION: { + UNKNOW_PERMISSION = { id: 3, 'description': 'unknow permission', } - UNKNOW_SYSCAP: { + UNKNOW_SYSCAP = { id: 4, 'description': 'unknow syscap', } - UNKNOW_DEPRECATED: { + UNKNOW_DEPRECATED = { id: 5, 'description': 'unknow deprecated', } - WRONG_ORDER: { + WRONG_ORDER = { id: 6, 'description': 'wrong order', } - WRONG_VALUE: { + WRONG_VALUE = { id: 7, 'description': 'wrong value', } - WRONG_SCENE: { + WRONG_SCENE = { id: 8, 'description': 'wrong scene', } - PARAMETER_ERRORS: { + PARAMETER_ERRORS = { id: 9, 'description': 'wrong parameter', } - API_PAIR_ERRORS: { + API_PAIR_ERRORS = { id: 10, 'description': 'limited api pair errors', } - ILLEGAL_ANY: { + ILLEGAL_ANY = { id: 11, 'description': 'illegal any', } - API_CHANGE_ERRORS: { + API_CHANGE_ERRORS = { id: 12, 'description': 'api change errors', } - EMPTY_TAG: { + EMPTY_TAG = { id: 13, 'description': 'miss tag value', } - ERROR_TAG: { + ERROR_TAG = { id: 14, 'description': 'error tag name', } - SYNTAX_ERRORS: { + SYNTAX_ERRORS = { id: 15, 'description': 'syntax errors', } diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index 4142ef41fa58b126ab60d0c65a0a98442e6f8eaa..d8c08425f1fa756958ec2574c291575f5119e457 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -25,6 +25,7 @@ class StringConstant(enum.Enum): # 拉到本地仓的三方库绝对路径 INCLUDE_LIB = r'.\third_party\musl\ndk_musl_include' STD_INCLUDE = r'.\sysroot\ndk_musl_include_files' + SELF_INCLUDE = r'.\sysroot\self_include_files' RESULT_HEAD_NAME = "result_total.xlsx"