Run clang-tidy with default configuration on all files listed in the
compilation database. Note that the generated files in the build directory
have to be built first. The simplest way to achieve this is to build libVirt
first.
Example:
$ meson build && ninja -C build
$ ./scripts/run-clang-tidy.py -p build
Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
scripts/run-clang-tidy.py | 68 +++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
create mode 100755 scripts/run-clang-tidy.py
diff --git a/scripts/run-clang-tidy.py b/scripts/run-clang-tidy.py
new file mode 100755
index 0000000000..10c8b80fe0
--- /dev/null
+++ b/scripts/run-clang-tidy.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+
+import argparse
+import json
+import os
+import subprocess
+import sys
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(description="caching clang-tidy runner")
+ parser.add_argument(
+ "-p",
+ dest="build_dir",
+ default=".",
+ help="Path to build directory")
+
+ return parser.parse_args()
+
+
+def run_clang_tidy(item):
+ cmd = (
+ "clang-tidy",
+ "--warnings-as-errors=*",
+ "-p",
+ item["directory"],
+ item["file"])
+ result = subprocess.run(
+ cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True)
+ return {
+ "returncode": result.returncode,
+ "stdout": result.stdout.strip(),
+ "stderr": result.stderr.strip(),
+ }
+
+
+def worker():
+ for item in items:
+ os.chdir(item["directory"])
+
+ print(item["file"])
+
+ result = run_clang_tidy(item)
+
+ if result["returncode"] != 0:
+ findings.append(item["file"])
+ if result["stdout"]:
+ print(result["stdout"])
+ if result["stderr"]:
+ print(result["stderr"])
+
+
+args = parse_args()
+findings = list()
+
+with open(os.path.join(args.build_dir, "compile_commands.json")) as f:
+ items = json.load(f)
+
+worker()
+
+if findings:
+ print("Findings in %s file(s):" % len(findings))
+ for finding in findings:
+ print(" %s" % finding)
+ sys.exit(1)
--
2.26.2