Skip to content

Commit

Permalink
[tools][clang-tidy] add skip file (PaddlePaddle#56632)
Browse files Browse the repository at this point in the history
* [clang-tidy]add skip

* fix compatibility

* fix
  • Loading branch information
gouzil authored and BeingGod committed Sep 9, 2023
1 parent f733598 commit a7841af
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tools/codestyle/clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
]
Expand Down

0 comments on commit a7841af

Please sign in to comment.