Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tools][clang-tidy] add skip file #56632

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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