[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 022/150] meson: add sparse support
From: |
Paolo Bonzini |
Subject: |
[PATCH 022/150] meson: add sparse support |
Date: |
Mon, 17 Aug 2020 16:35:15 +0200 |
Do not use cgcc; instead, extract compilation commands from
compile_commands.json
and invoke sparse directly.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
Makefile | 1 +
configure | 8 ++------
meson.build | 7 +++++++
scripts/check_sparse.py | 25 +++++++++++++++++++++++++
4 files changed, 35 insertions(+), 6 deletions(-)
create mode 100644 scripts/check_sparse.py
diff --git a/Makefile b/Makefile
index 578aa99942..8288e2fbd2 100644
--- a/Makefile
+++ b/Makefile
@@ -1254,6 +1254,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 9f20bf1d36..d4172b06a7 100755
--- a/configure
+++ b/configure
@@ -3009,7 +3009,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
@@ -7810,11 +7810,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 e6f9dfb070..e15e072a8c 100644
--- a/meson.build
+++ b/meson.build
@@ -17,6 +17,13 @@ add_project_arguments(config_host['QEMU_INCLUDES'].split(),
python = import('python').find_installation()
+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
+
if host_machine.system() == 'darwin'
add_languages('objc', required: false, native: false)
endif
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)
--
2.26.2
- [PATCH 011/150] configure: do not include $(...) variables in config-host.mak, (continued)
- [PATCH 011/150] configure: do not include $(...) variables in config-host.mak, Paolo Bonzini, 2020/08/17
- [PATCH 010/150] nsis: use "make DESTDIR=" instead of "make prefix=", Paolo Bonzini, 2020/08/17
- [PATCH 012/150] configure: expand path variables for meson configure, Paolo Bonzini, 2020/08/17
- [PATCH 013/150] configure: prepare CFLAGS/CXXFLAGS/LDFLAGS for Meson, Paolo Bonzini, 2020/08/17
- [PATCH 014/150] tests/vm: include setuptools, Paolo Bonzini, 2020/08/17
- [PATCH 016/150] configure: generate Meson cross file, Paolo Bonzini, 2020/08/17
- [PATCH 017/150] build-sys hack: link with whole .fa archives, Paolo Bonzini, 2020/08/17
- [PATCH 015/150] configure: integrate Meson in the build system, Paolo Bonzini, 2020/08/17
- [PATCH 020/150] meson: enable pie, Paolo Bonzini, 2020/08/17
- [PATCH 018/150] build-sys: add meson submodule, Paolo Bonzini, 2020/08/17
- [PATCH 022/150] meson: add sparse support,
Paolo Bonzini <=
- [PATCH 019/150] meson: move summary to meson.build, Paolo Bonzini, 2020/08/17
- [PATCH 021/150] meson: use coverage option, Paolo Bonzini, 2020/08/17
- [PATCH 023/150] meson: add testsuite Makefile generator, Paolo Bonzini, 2020/08/17
- [PATCH 025/150] meson: add remaining generated tcg trace helpers, Paolo Bonzini, 2020/08/17
- [PATCH 027/150] contrib/libvhost-user: convert to Meson, Paolo Bonzini, 2020/08/17
- [PATCH 028/150] tools/virtiofsd: convert to Meson, Paolo Bonzini, 2020/08/17
- [PATCH 024/150] libqemuutil, qapi, trace: convert to meson, Paolo Bonzini, 2020/08/17
- [PATCH 026/150] meson: add version.o, Paolo Bonzini, 2020/08/17
- [PATCH 029/150] contrib/vhost-user-blk: convert to Meson, Paolo Bonzini, 2020/08/17
- [PATCH 030/150] vhost-user-scsi: add compatibility for libiscsi 1.9.0, Paolo Bonzini, 2020/08/17