diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2020-02-03 14:45:33 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-08-21 06:30:07 -0400 |
commit | 968b4db38a717d334db9298fb7b6f6ba71d08806 (patch) | |
tree | 491226bfbfaf79f1b0ba06479e9a13f493392ab5 /scripts/check_sparse.py | |
parent | bf0e56a3ca7b6ede730ec754a95aee7f95815735 (diff) |
meson: add sparse support
Do not use cgcc; instead, extract compilation commands from compile_commands.json
and invoke sparse directly.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'scripts/check_sparse.py')
-rw-r--r-- | scripts/check_sparse.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/check_sparse.py b/scripts/check_sparse.py new file mode 100644 index 0000000000..0de7aa55d9 --- /dev/null +++ b/scripts/check_sparse.py @@ -0,0 +1,25 @@ +#! /usr/bin/env python3 + +# Invoke sparse based on the contents of compile_commands.json + +import json +import subprocess +import sys +import shlex + +def extract_cflags(shcmd): + cflags = shlex.split(shcmd) + return [x for x in cflags + if x.startswith('-D') or x.startswith('-I') or x.startswith('-W') + or x.startswith('-std=')] + +cflags = sys.argv[1:-1] +with open(sys.argv[-1], 'r') as fd: + compile_commands = json.load(fd) + +for cmd in compile_commands: + cmd = ['sparse'] + cflags + extract_cflags(cmd['command']) + [cmd['file']] + print(' '.join((shlex.quote(x) for x in cmd))) + r = subprocess.run(cmd) + if r.returncode != 0: + sys.exit(r.returncode) |