xtc/tools/analyze.py

24 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Run Clang's path-sensitive analyzer; any diagnostic fails the audit."""
import pathlib
import shutil
import subprocess
import sys
if not shutil.which("clang"):
sys.exit("clang is required for make analyze")
jack = subprocess.run(["pkg-config", "--cflags", "jack"], capture_output=True, text=True) if shutil.which("pkg-config") else None
for source in sys.argv[1:]:
flags = []
if source == "src/plugin/modern.c":
flags = ["-isystem", "third_party/clap/include", "-isystem", "third_party/vst3"]
if source == "src/backend/jack_backend.c" and jack and jack.returncode == 0:
import shlex
flags = ["-DXTC_HAVE_JACK", *shlex.split(jack.stdout)]
result = subprocess.run(["clang", "--analyze", "-std=c99", "-Iinclude",
"-Xanalyzer", "-analyzer-output=text", *flags,
str(pathlib.Path(source))], capture_output=True, text=True)
if result.returncode or result.stderr:
sys.stderr.write(result.stdout + result.stderr)
sys.exit(result.returncode or 1)
print("Clang static analysis passed for all core sources.")