22 lines
1,017 B
Python
22 lines
1,017 B
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/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.")
|