diff --git a/build-tools/capi_parser/src/coreImpl/check/check.py b/build-tools/capi_parser/src/coreImpl/check/check.py index ce5fc5417c6599cf136f0ae565606cb8506c303f..153abf9b80d560713808681f37c43e29ed62b033 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check.py +++ b/build-tools/capi_parser/src/coreImpl/check/check.py @@ -14,15 +14,15 @@ # limitations under the License. import json -import os -from typedef.check.check import ApiResultInfo, FileDocInfo, OutputTxt +from pathlib import Path +from typedef.check.check import FileDocInfo, OutputTxt from coreImpl.check.check_doc import process_comment, process_file_doc_info from coreImpl.check.check_name import check_file_name, check_ndk_name from coreImpl.parser.parser import parser_include_ast from coreImpl.check.check_syntax import check_syntax -def process_api_json(api_info, file_doc_info: FileDocInfo, api_result_info_list): +def process_api_json(api_info, file_doc_info, api_result_info_list): api_result_info_list.extend(check_ndk_name(api_info)) if 'comment' in api_info.keys(): comment = api_info['comment'] @@ -69,20 +69,18 @@ def write_in_txt(check_result, output_path): def result_to_json(check_result): txt_resul = [] - if len(check_result) == 0: - txt_resul.append('api_check: false') - else: - 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('api_check: false') + 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)) return json.dumps(txt_resul, default=lambda obj: obj.__dict__, indent=4) -def curr_entry(file_path): - file_list = get_md_files(file_path) - check_result_list = get_check_result_list(file_list) +def curr_entry(md_files_path): + file_list = get_md_files(md_files_path) + check_result_list = [] + if len(file_list) > 0: + check_result_list = get_check_result_list(file_list) write_in_txt(check_result_list, r'./Error.txt') @@ -97,12 +95,18 @@ def get_check_result_list(file_list): return check_result_list -def get_md_files(url): - file = open(url, "r") +def get_md_files(md_files_path): + file = open(md_files_path, "r") file_list = [] line = file.readline() while line: - file_list.append(line.splitlines()[0]) + file_path = line.splitlines()[0] + if file_path.find("sdk_c") != -1 and get_file_type(file_path) == '.h': + file_list.append(line.splitlines()[0]) line = file.readline() file.close() return file_list + + +def get_file_type(file_path): + return Path(file_path).suffix 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 c80a3dac69964706d662734ea766184953e08259..ca9a6a75a8191cb006b317d70b04d439ba2dfab8 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check_name.py +++ b/build-tools/capi_parser/src/coreImpl/check/check_name.py @@ -55,6 +55,25 @@ def check_small_hump(api_info): return processing_check_data('SMALL_HUMP', api_info) +def check_macro_definition(api_info): + api_result_info_list = [] + name = api_info['name'] + if api_info['is_def_func']: + name = api_info['def_func_name'] + result = re.match(CheckName['ALL_UPPERCASE_HUMP'].value, name) + if result is None: + api_result_info = ApiResultInfo(ErrorType.NAMING_ERRORS.value, + ErrorMessage[api_info['kind']].value.replace('$$', name), name) + api_result_info.set_location_line(api_info['location']['location_line']) + 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(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 + + def check_all_uppercase_hump(api_info): return processing_check_data('ALL_UPPERCASE_HUMP', api_info) @@ -111,7 +130,7 @@ process_tag_function = { 'VAR_DECL': check_variable_name, 'PARM_DECL': check_small_hump, 'FIELD_DECL': check_small_hump, - 'MACRO_DEFINITION': check_all_uppercase_hump, + 'MACRO_DEFINITION': check_macro_definition, 'ENUM_CONSTANT_DECL': check_all_uppercase_hump, } diff --git a/build-tools/capi_parser/src/typedef/check/check.py b/build-tools/capi_parser/src/typedef/check/check.py index 845e7381286044cf157c00d1da0853bbb56363e4..ebf207ce371cb47ae0ae6a9208bd129a582c8b30 100644 --- a/build-tools/capi_parser/src/typedef/check/check.py +++ b/build-tools/capi_parser/src/typedef/check/check.py @@ -37,67 +37,67 @@ class ErrorType(enum.Enum): 'description': '', } UNKNOW_DECORATOR = { - id: 0, + 'id': 0, 'description': 'unknow decorator', } MISSPELL_WORDS = { - id: 1, + 'id': 1, 'description': 'misspell words', } NAMING_ERRORS = { - id: 2, + 'id': 2, 'description': 'naming errors', } UNKNOW_PERMISSION = { - id: 3, + 'id': 3, 'description': 'unknow permission', } UNKNOW_SYSCAP = { - id: 4, + 'id': 4, 'description': 'unknow syscap', } UNKNOW_DEPRECATED = { - id: 5, + 'id': 5, 'description': 'unknow deprecated', } WRONG_ORDER = { - id: 6, + 'id': 6, 'description': 'wrong order', } WRONG_VALUE = { - id: 7, + 'id': 7, 'description': 'wrong value', } WRONG_SCENE = { - id: 8, + 'id': 8, 'description': 'wrong scene', } PARAMETER_ERRORS = { - id: 9, + 'id': 9, 'description': 'wrong parameter', } API_PAIR_ERRORS = { - id: 10, + 'id': 10, 'description': 'limited api pair errors', } ILLEGAL_ANY = { - id: 11, + 'id': 11, 'description': 'illegal any', } API_CHANGE_ERRORS = { - id: 12, + 'id': 12, 'description': 'api change errors', } EMPTY_TAG = { - id: 13, + 'id': 13, 'description': 'miss tag value', } ERROR_TAG = { - id: 14, + 'id': 14, 'description': 'error tag name', } SYNTAX_ERRORS = { - id: 15, + '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 b88370294744cbb915a37205bf542c46bd1c06c5..f6fe61342c8cc8cf46bd79a428bbeabd6810d131 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -19,17 +19,13 @@ import enum class StringConstant(enum.Enum): - LIB_CLG_PATH = r'D:\Environment\LLVM\bin\libclang.dll' # 共享库 + LIB_CLG_PATH = r'/home/tools/llvm/lib/libclang.so' # 共享库 FUNK_NAME = "ohos_ndk_headers" REPLACE_WAREHOUSE = '\\interface_sdk_c\\interface_sdk_c' # 拉到本地仓路径(去掉磁盘) # 拉到本地仓的三方库绝对路径 - INCLUDE_LIB = r'.\third_party\musl\ndk_musl_include' - STD_INCLUDE = r'.\sysroot\ndk_musl_include_files' - CREATE_LIB_PATH = r'.\sysroot\$ndk_headers_out_dir' - SELF_INCLUDE = r'.\sysroot\self_include_files' - SELF_INCLUDE_OLD = r'.\sysroot\self_include_files_old' - SELF_INCLUDE_NEW = r'.\sysroot\self_include_files_new' - SYSROOT = r'.\sysroot' + 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"