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

[clang-tidy] skip check when not find compilation db #56134

Merged
merged 1 commit into from
Aug 14, 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
15 changes: 12 additions & 3 deletions tools/codestyle/clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,19 @@
import queue


def find_compilation_database(path):
def find_compilation_database(path, result="./"):
"""Adjusts the directory until a compilation database is found."""
result = './'
while not os.path.isfile(os.path.join(result, path)):
if os.path.realpath(result) == '/':
print('Error: could not find compilation database.')
sys.exit(1)
print('Warning: could not find compilation database.')
return None
result += '../'
return os.path.realpath(result)


def make_absolute(f, directory):
"""Convert a relative file path to an absolute file path."""
if os.path.isabs(f):
return f
return os.path.normpath(os.path.join(directory, f))
Expand Down Expand Up @@ -216,6 +217,7 @@ def run_tidy(args, tmpdir, build_path, queue, lock, failed_files):


def main():
"""Runs clang-tidy over all files in a compilation database."""
parser = argparse.ArgumentParser(
description='Runs clang-tidy over all files '
'in a compilation database. Requires '
Expand Down Expand Up @@ -317,9 +319,16 @@ def main():

if args.build_path is not None:
build_path = args.build_path
if not os.path.isfile(os.path.join(build_path, db_path)):
print(
f'Warning: could not find compilation database in {build_path}, skip clang-tidy check.'
)
build_path = None
else:
# Find our database
build_path = find_compilation_database(db_path)
if build_path is None:
sys.exit(0)

try:
invocation = [args.clang_tidy_binary, '-list-checks']
Expand Down