From a988124db967e03f49593393eb73b95b217cc389 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Thu, 29 Aug 2019 09:18:37 -0700 Subject: [PATCH] make: override scan-build for unit tests. The unit test mock macro function doesn't mesh well with the scan-build static analysis tool. So we need to reset cc to the user provided value or default before running the unit tests. Change-Id: Ib636f6e396b09f9bf1cb8f930e6befa56ce99848 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466816 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- configure | 2 +- mk/spdk.unittest.mk | 9 +++++++++ scripts/detect_cc.sh | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/configure b/configure index e4ec0a160..a670ea02d 100755 --- a/configure +++ b/configure @@ -368,7 +368,7 @@ done # Detect the compiler toolchain $rootdir/scripts/detect_cc.sh --cc="$CC" --cxx="$CXX" --lto="${CONFIG[LTO]}" --ld="$LD" --cross-prefix="${CONFIG[CROSS_PREFIX]}" > $rootdir/mk/cc.mk -CC=$(cat $rootdir/mk/cc.mk | grep "CC=" | cut -d "=" -f 2) +CC=$(cat $rootdir/mk/cc.mk | grep "DEFAULT_CC=" | cut -d "=" -f 2) CC_TYPE=$(cat $rootdir/mk/cc.mk | grep "CC_TYPE=" | cut -d "=" -f 2) BUILD_CMD=($CC -o /dev/null -x c $CPPFLAGS $CFLAGS $LDFLAGS) diff --git a/mk/spdk.unittest.mk b/mk/spdk.unittest.mk index 8ab55983a..91345aa55 100644 --- a/mk/spdk.unittest.mk +++ b/mk/spdk.unittest.mk @@ -35,6 +35,15 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk include $(SPDK_ROOT_DIR)/mk/spdk.app_vars.mk include $(SPDK_ROOT_DIR)/mk/spdk.mock.unittest.mk +# We don't want to run scan-build against the unit tests +# because it can't understand our mock function macros and +# throws false positives because of them. + +# Scan-build inserts a phony compiler by overriding the value +# of CC, so we store the original CC under DEFAULT_CC and +# re-assign it here. +override CC=$(DEFAULT_CC) + C_SRCS = $(TEST_FILE) CFLAGS += -I$(SPDK_ROOT_DIR)/lib diff --git a/scripts/detect_cc.sh b/scripts/detect_cc.sh index 7315baaa0..b8d3e433a 100755 --- a/scripts/detect_cc.sh +++ b/scripts/detect_cc.sh @@ -168,6 +168,7 @@ if [ -n "$CROSS_PREFIX" ]; then fi function set_default() { + echo "DEFAULT_$1=$2" echo "ifeq (\$(origin $1),default)" echo "$1=$2" echo "endif"