From 0ade5e8e9050927ca025ad3a87f743e65e24f605 Mon Sep 17 00:00:00 2001 From: jwx1102601 Date: Wed, 20 Dec 2023 15:24:16 +0800 Subject: [PATCH 1/2] update clang address Signed-off-by: jwx1102601 --- .../capi_parser/src/coreImpl/check/check.py | 18 ++++++++++-------- build-tools/capi_parser/src/utils/constants.py | 8 ++++---- third_party/musl/ndk_musl_include/ctype.h | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/check/check.py b/build-tools/capi_parser/src/coreImpl/check/check.py index ce5fc5417..ac2bcf42b 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check.py +++ b/build-tools/capi_parser/src/coreImpl/check/check.py @@ -22,6 +22,9 @@ from coreImpl.parser.parser import parser_include_ast from coreImpl.check.check_syntax import check_syntax +file_path_test = [] + + def process_api_json(api_info, file_doc_info: FileDocInfo, api_result_info_list): api_result_info_list.extend(check_ndk_name(api_info)) if 'comment' in api_info.keys(): @@ -69,14 +72,11 @@ 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') + txt_resul.extend(file_path_test) + 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) @@ -89,6 +89,8 @@ def curr_entry(file_path): def get_check_result_list(file_list): check_result_list = [] for file in file_list: + global file_path_test + file_path_test.append(f'file_path: {file}') root_start = file.split('sdk_c')[0] root_path = f'{root_start}sdk_c' python_obj = parser_include_ast(root_path, [file]) diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index d8c08425f..23df32bd9 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -19,13 +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' - SELF_INCLUDE = r'.\sysroot\self_include_files' + 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" diff --git a/third_party/musl/ndk_musl_include/ctype.h b/third_party/musl/ndk_musl_include/ctype.h index fbdba6e3f..54f55f0e8 100644 --- a/third_party/musl/ndk_musl_include/ctype.h +++ b/third_party/musl/ndk_musl_include/ctype.h @@ -45,7 +45,7 @@ static __inline int __isspace(int _c) #define __NEED_locale_t #include -int isalnum_l(int, locale_t); +int isalnum_ll(int, locale_t); int isalpha_l(int, locale_t); int isblank_l(int, locale_t); int iscntrl_l(int, locale_t); -- Gitee From 4b3e7d7d8586a5a989060945fda9c77f0cd75c0b Mon Sep 17 00:00:00 2001 From: jwx1102601 Date: Sat, 23 Dec 2023 16:53:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=97=A8=E7=A6=81=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96&=E5=A2=9E=E5=8A=A0=E5=AE=8F=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jwx1102601 --- .../capi_parser/src/coreImpl/check/check.py | 32 ++++++++++--------- .../src/coreImpl/check/check_name.py | 21 +++++++++++- .../capi_parser/src/typedef/check/check.py | 32 +++++++++---------- third_party/musl/ndk_musl_include/ctype.h | 2 +- 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/check/check.py b/build-tools/capi_parser/src/coreImpl/check/check.py index ac2bcf42b..153abf9b8 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check.py +++ b/build-tools/capi_parser/src/coreImpl/check/check.py @@ -14,18 +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 -file_path_test = [] - - -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'] @@ -72,7 +69,6 @@ def write_in_txt(check_result, output_path): def result_to_json(check_result): txt_resul = [] - txt_resul.extend(file_path_test) 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) @@ -80,17 +76,17 @@ def result_to_json(check_result): 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') def get_check_result_list(file_list): check_result_list = [] for file in file_list: - global file_path_test - file_path_test.append(f'file_path: {file}') root_start = file.split('sdk_c')[0] root_path = f'{root_start}sdk_c' python_obj = parser_include_ast(root_path, [file]) @@ -99,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 c80a3dac6..ca9a6a75a 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 845e73812..ebf207ce3 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/third_party/musl/ndk_musl_include/ctype.h b/third_party/musl/ndk_musl_include/ctype.h index 54f55f0e8..fbdba6e3f 100644 --- a/third_party/musl/ndk_musl_include/ctype.h +++ b/third_party/musl/ndk_musl_include/ctype.h @@ -45,7 +45,7 @@ static __inline int __isspace(int _c) #define __NEED_locale_t #include -int isalnum_ll(int, locale_t); +int isalnum_l(int, locale_t); int isalpha_l(int, locale_t); int isblank_l(int, locale_t); int iscntrl_l(int, locale_t); -- Gitee