From f6630ff9e72fb1d61c58770b4f984e043a2f31bc Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 24 Aug 2023 19:10:43 +0800 Subject: [PATCH 1/3] [clang-tidy]add skip --- tools/codestyle/clang-tidy.py | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tools/codestyle/clang-tidy.py b/tools/codestyle/clang-tidy.py index c4d51c3974b8c6..dda032e86f98a2 100644 --- a/tools/codestyle/clang-tidy.py +++ b/tools/codestyle/clang-tidy.py @@ -93,6 +93,51 @@ def make_absolute(f, directory): return os.path.normpath(os.path.join(directory, f)) +def analysis_gitignore(path, filename=".gitignore"): + """Analysis gitignore file and return ignore file list""" + f = open(path + "/" + filename, "r") + lines = f.readlines() + ignore_file_list = [] + for line in lines: + # Blank row + if line == "\n": + continue + + # explanatory note + line = line.replace("\n", "") + if "#" in line: + if line[0] != "#": + ignore_file_list.append( + line[: line.index("#")].replace(" ", "") + ) + continue + + # TODO(gouzil): support more gitignore rules + if "*" in line: + continue + + ignore_file_list.append(line.replace(" ", "")) + + f.close() + return ignore_file_list + + +def skip_check_file(database, build_path): + """Skip checking some files""" + skip_file_list = [] + skip_file_list.append(".cu") + skip_file_list.append(os.path.join(os.getcwd(), build_path)) + skip_file_list += analysis_gitignore(os.getcwd()) + for entry in database: + for ignore_file in skip_file_list: + if ignore_file in entry["file"]: + try: + database.remove(entry) + except ValueError: + pass + return database + + def get_tidy_invocation( f, clang_tidy_binary, @@ -348,6 +393,7 @@ def main(): # Load the database and extract all files. database = json.load(open(os.path.join(build_path, db_path))) + database = skip_check_file(database, build_path) files = [ make_absolute(entry['file'], entry['directory']) for entry in database ] From a2db72388f3880af235c1d13280972926b907b6d Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 25 Aug 2023 00:03:17 +0800 Subject: [PATCH 2/3] fix compatibility --- tools/codestyle/clang-tidy.py | 47 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/tools/codestyle/clang-tidy.py b/tools/codestyle/clang-tidy.py index dda032e86f98a2..2f0cafc3fc220e 100644 --- a/tools/codestyle/clang-tidy.py +++ b/tools/codestyle/clang-tidy.py @@ -95,30 +95,29 @@ def make_absolute(f, directory): def analysis_gitignore(path, filename=".gitignore"): """Analysis gitignore file and return ignore file list""" - f = open(path + "/" + filename, "r") - lines = f.readlines() - ignore_file_list = [] - for line in lines: - # Blank row - if line == "\n": - continue - - # explanatory note - line = line.replace("\n", "") - if "#" in line: - if line[0] != "#": - ignore_file_list.append( - line[: line.index("#")].replace(" ", "") - ) - continue - - # TODO(gouzil): support more gitignore rules - if "*" in line: - continue - - ignore_file_list.append(line.replace(" ", "")) - - f.close() + with open(path + "/" + filename, "r") as f: + lines = f.readlines() + ignore_file_list = [] + for line in lines: + # Blank row + if line == "\n" or line == "\r\n": + continue + + # explanatory note + line = line.replace("\n", "").strip() + if "#" in line: + if not line.startswith("#"): + ignore_file_list.append( + line[: line.index("#")].replace(" ", "") + ) + continue + + # TODO(gouzil): support more gitignore rules + if "*" in line: + continue + + ignore_file_list.append(line.replace(" ", "")) + return ignore_file_list From ba5a96ab1b7039c8f51de7410668bf7a366d3c09 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 25 Aug 2023 00:55:49 +0800 Subject: [PATCH 3/3] fix --- tools/codestyle/clang-tidy.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/codestyle/clang-tidy.py b/tools/codestyle/clang-tidy.py index 2f0cafc3fc220e..ef1a5c76e1e432 100644 --- a/tools/codestyle/clang-tidy.py +++ b/tools/codestyle/clang-tidy.py @@ -127,14 +127,17 @@ def skip_check_file(database, build_path): skip_file_list.append(".cu") skip_file_list.append(os.path.join(os.getcwd(), build_path)) skip_file_list += analysis_gitignore(os.getcwd()) + res_list = [] for entry in database: + write_in = True for ignore_file in skip_file_list: if ignore_file in entry["file"]: - try: - database.remove(entry) - except ValueError: - pass - return database + write_in = False + break + if write_in: + res_list.append(entry) + + return res_list def get_tidy_invocation(