From fac71a215cfe7d6d9ecdeead81e929f62f1c3223 Mon Sep 17 00:00:00 2001 From: Aki Van Ness Date: Thu, 15 Sep 2022 05:39:17 -0400 Subject: [PATCH] misc: added clang-tidy wrapper --- misc/run-clang-tidy.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 misc/run-clang-tidy.py diff --git a/misc/run-clang-tidy.py b/misc/run-clang-tidy.py new file mode 100755 index 000000000..52db1df97 --- /dev/null +++ b/misc/run-clang-tidy.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import sys + +from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter +from pathlib import Path +from subprocess import run +from concurrent.futures import ThreadPoolExecutor + +def main() -> int: + parser = ArgumentParser( + formatter_class = ArgumentDefaultsHelpFormatter, + description = 'clang-tidy runner', + prog = 'run-clang-tidy.py', + ) + + parser.add_argument( + '--source-path', '-s', + required = True, + type = Path, + metavar = 'source_path', + help = 'Path to the source directory to run clang-tidy in' + ) + + parser.add_argument( + '--build-path', '-p', + required = True, + type = Path, + metavar = 'build_path', + help = 'Path to the build directory containing a compile_commands.json' + ) + + args = parser.parse_args() + + def glob_files(): + paths = {'backends', 'frontend', 'kernel', 'passes', 'techlibs'} + suffixes = {'cc', 'h'} + + for path in paths: + for suffix in suffixes: + yield args.source_path.glob(f'{path}/**/*.{suffix}') + + def gather_files(): + for file_glob in glob_files(): + for file in file_glob: + yield file + + extra_args = () + futures = [] + + with ThreadPoolExecutor() as pool: + for file in gather_files(): + futures.append(pool.submit( + run, ['clang-tidy', *extra_args, '-p', args.build_path, file] + )) + + return max((future.result().returncode for future in futures)) + + +if __name__ == '__main__': + sys.exit(main())