hw/sd/pl181: Replace fprintf(stderr, "*\n") with error_report()
[qemu/ar7.git] / scripts / check_sparse.py
blob0de7aa55d98c002692c5809f4fa1e45ee276df9d
1 #! /usr/bin/env python3
3 # Invoke sparse based on the contents of compile_commands.json
5 import json
6 import subprocess
7 import sys
8 import shlex
10 def extract_cflags(shcmd):
11 cflags = shlex.split(shcmd)
12 return [x for x in cflags
13 if x.startswith('-D') or x.startswith('-I') or x.startswith('-W')
14 or x.startswith('-std=')]
16 cflags = sys.argv[1:-1]
17 with open(sys.argv[-1], 'r') as fd:
18 compile_commands = json.load(fd)
20 for cmd in compile_commands:
21 cmd = ['sparse'] + cflags + extract_cflags(cmd['command']) + [cmd['file']]
22 print(' '.join((shlex.quote(x) for x in cmd)))
23 r = subprocess.run(cmd)
24 if r.returncode != 0:
25 sys.exit(r.returncode)