1 #! /usr/bin/env python3
3 # Invoke sparse based on the contents of compile_commands.json
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
)
25 sys
.exit(r
.returncode
)