diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-08-22 22:42:58 -0700 |
---|---|---|
committer | Rebecca Turner <rbt@sent.as> | 2024-08-28 09:52:08 -0700 |
commit | e6f2af06e6d7cc01e142c21259635094f73de104 (patch) | |
tree | ebed3837e2f5caa70929db56617de17df989f7df /meson/clang-tidy/clang-tidy-runner.py | |
parent | 4d8984420788d6253d2fd9bfa3ada92be8bfd73b (diff) |
clang-tidy: fix the fact that we are not linting headers properly
This, however, took fixing a pile of lints that we predictably missed
because of this bug.
Change-Id: I92c36feb4a03f62bc594c2051c7bd7418d13fb08
Diffstat (limited to 'meson/clang-tidy/clang-tidy-runner.py')
-rwxr-xr-x | meson/clang-tidy/clang-tidy-runner.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/meson/clang-tidy/clang-tidy-runner.py b/meson/clang-tidy/clang-tidy-runner.py new file mode 100755 index 000000000..c36e66b41 --- /dev/null +++ b/meson/clang-tidy/clang-tidy-runner.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +""" +Runs run-clang-tidy. A bit meta. Maybe it will replace run-clang-tidy one day +because the run-clang-tidy UX is so questionable. +""" + +# I hereby dedicate this script to fuck you meson. +# I cannot simply write my code to invoke a subprocess in a meson file because +# Meson corrupts backslashes in command line args to subprocesses. +# This is allegedly for "Windows support", but last time I checked Windows +# neither needs nor wants you to corrupt its command lines. +# https://github.com/mesonbuild/meson/issues/1564 + +import multiprocessing +import subprocess +import os +import sys +from pathlib import Path + + +def default_concurrency(): + return min(multiprocessing.cpu_count(), + int(os.environ.get("NIX_BUILD_CORES", "16"))) + + +def go(exe: str, plugin_path: Path, compile_commands_json_dir: Path, jobs: int, + paths: list[Path], werror: bool, fix: bool): + args = [ + # XXX: This explicitly invokes it with python because of a nixpkgs bug + # where clang-unwrapped does not patch interpreters in run-clang-tidy. + # However, making clang-unwrapped depend on python is also silly, so idk. + sys.executable, + exe, + '-quiet', + '-load', + plugin_path, + '-p', + compile_commands_json_dir, + '-j', + str(jobs), + '-header-filter', + r'src/[^/]+/.*\.hh' + ] + if werror: + args += ['-warnings-as-errors', '*'] + if fix: + args += ['-fix'] + args += ['--'] + args += paths + os.execvp(sys.executable, args) + + +def main(): + import argparse + + ap = argparse.ArgumentParser(description='Runs run-clang-tidy for you') + ap.add_argument('--jobs', + '-j', + type=int, + default=default_concurrency(), + help='Parallel linting jobs to run') + ap.add_argument('--plugin-path', + type=Path, + help='Path to the Lix clang-tidy plugin') + # FIXME: maybe we should integrate this so it just fixes the compdb for you and throws it in a tempdir? + ap.add_argument( + '--compdb-path', + type=Path, + help= + 'Path to the directory containing the fixed-up compilation database from clean_compdb' + ) + ap.add_argument('--werror', + action='store_true', + help='Warnings get turned into errors') + ap.add_argument('--fix', + action='store_true', + help='Apply fixes for warnings') + ap.add_argument('--run-clang-tidy-path', + default='run-clang-tidy', + help='Path to run-clang-tidy') + ap.add_argument('paths', nargs='*', help='Source paths to check') + args = ap.parse_args() + + go(args.run_clang_tidy_path, args.plugin_path, args.compdb_path, args.jobs, + args.paths, args.werror, args.fix) + + +if __name__ == '__main__': + main() |