diff --git a/tools/codestyle/clang-tidy.py b/tools/codestyle/clang-tidy.py index c4d51c3974b8c6e8142dd532c4e7015da123bac5..ef1a5c76e1e4323445304355737907e7ec6ff00a 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 ]