From a8bb416fb5620d89f68c73072fd7022480eb5c29 Mon Sep 17 00:00:00 2001 From: gouzil <66515297+gouzil@users.noreply.github.com> Date: Tue, 29 Aug 2023 10:37:30 +0800 Subject: [PATCH] [tools][clang-tidy] add skip file (#56632) * [clang-tidy]add skip * fix compatibility * fix --- tools/codestyle/clang-tidy.py | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/codestyle/clang-tidy.py b/tools/codestyle/clang-tidy.py index c4d51c3974b..ef1a5c76e1e 100644 --- a/tools/codestyle/clang-tidy.py +++ b/tools/codestyle/clang-tidy.py @@ -93,6 +93,53 @@ 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""" + 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 + + +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()) + res_list = [] + for entry in database: + write_in = True + for ignore_file in skip_file_list: + if ignore_file in entry["file"]: + write_in = False + break + if write_in: + res_list.append(entry) + + return res_list + + def get_tidy_invocation( f, clang_tidy_binary, @@ -348,6 +395,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 ] -- GitLab