aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-02-03 14:45:33 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2020-08-21 06:30:07 -0400
commit968b4db38a717d334db9298fb7b6f6ba71d08806 (patch)
tree491226bfbfaf79f1b0ba06479e9a13f493392ab5
parentbf0e56a3ca7b6ede730ec754a95aee7f95815735 (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>
-rw-r--r--Makefile1
-rwxr-xr-xconfigure8
-rw-r--r--meson.build7
-rw-r--r--scripts/check_sparse.py25
4 files changed, 35 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index ba8413d809..81c9642a30 100644
--- a/Makefile
+++ b/Makefile
@@ -1261,6 +1261,7 @@ endif
$(call print-help,install,Install QEMU, documentation and tools)
$(call print-help,ctags/TAGS,Generate tags file for editors)
$(call print-help,cscope,Generate cscope index)
+ $(call print-help,sparse,Run sparse on the QEMU source)
@echo ''
@$(if $(TARGET_DIRS), \
echo 'Architecture specific targets:'; \
diff --git a/configure b/configure
index 41d3b973b4..79bcf8a681 100755
--- a/configure
+++ b/configure
@@ -3058,7 +3058,7 @@ fi
##########################################
# Sparse probe
if test "$sparse" != "no" ; then
- if has cgcc; then
+ if has sparse; then
sparse=yes
else
if test "$sparse" = "yes" ; then
@@ -7859,11 +7859,7 @@ echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
echo "QEMU_INCLUDES=$QEMU_INCLUDES" >> $config_host_mak
if test "$sparse" = "yes" ; then
- echo "CC := REAL_CC=\"\$(CC)\" cgcc" >> $config_host_mak
- echo "CPP := REAL_CC=\"\$(CPP)\" cgcc" >> $config_host_mak
- echo "CXX := REAL_CC=\"\$(CXX)\" cgcc" >> $config_host_mak
- echo "HOST_CC := REAL_CC=\"\$(HOST_CC)\" cgcc" >> $config_host_mak
- echo "QEMU_CFLAGS += -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_host_mak
+ echo "SPARSE_CFLAGS = -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-non-pointer-null" >> $config_host_mak
fi
echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
diff --git a/meson.build b/meson.build
index 1a56ac8b26..86219e500a 100644
--- a/meson.build
+++ b/meson.build
@@ -25,6 +25,13 @@ if host_machine.system() == 'darwin'
add_languages('objc', required: false, native: false)
endif
+if 'SPARSE_CFLAGS' in config_host
+ run_target('sparse',
+ command: [find_program('scripts/check_sparse.py'),
+ config_host['SPARSE_CFLAGS'].split(),
+ 'compile_commands.json'])
+endif
+
configure_file(input: files('scripts/ninjatool.py'),
output: 'ninjatool',
configuration: config_host)
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)