未验证 提交 662fa999 编写于 作者: W Wang Xin 提交者: GitHub

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

上级 0f5148fb
...@@ -75,18 +75,19 @@ else: ...@@ -75,18 +75,19 @@ else:
import queue import queue
def find_compilation_database(path): def find_compilation_database(path, result="./"):
"""Adjusts the directory until a compilation database is found.""" """Adjusts the directory until a compilation database is found."""
result = './' result = './'
while not os.path.isfile(os.path.join(result, path)): while not os.path.isfile(os.path.join(result, path)):
if os.path.realpath(result) == '/': if os.path.realpath(result) == '/':
print('Error: could not find compilation database.') print('Warning: could not find compilation database.')
sys.exit(1) return None
result += '../' result += '../'
return os.path.realpath(result) return os.path.realpath(result)
def make_absolute(f, directory): def make_absolute(f, directory):
"""Convert a relative file path to an absolute file path."""
if os.path.isabs(f): if os.path.isabs(f):
return f return f
return os.path.normpath(os.path.join(directory, f)) return os.path.normpath(os.path.join(directory, f))
...@@ -216,6 +217,7 @@ def run_tidy(args, tmpdir, build_path, queue, lock, failed_files): ...@@ -216,6 +217,7 @@ def run_tidy(args, tmpdir, build_path, queue, lock, failed_files):
def main(): def main():
"""Runs clang-tidy over all files in a compilation database."""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Runs clang-tidy over all files ' description='Runs clang-tidy over all files '
'in a compilation database. Requires ' 'in a compilation database. Requires '
...@@ -317,9 +319,16 @@ def main(): ...@@ -317,9 +319,16 @@ def main():
if args.build_path is not None: if args.build_path is not None:
build_path = args.build_path 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: else:
# Find our database # Find our database
build_path = find_compilation_database(db_path) build_path = find_compilation_database(db_path)
if build_path is None:
sys.exit(0)
try: try:
invocation = [args.clang_tidy_binary, '-list-checks'] invocation = [args.clang_tidy_binary, '-list-checks']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册