Add "WITH_STATIC_ANALYZER=1 m/mm/mmm/mma/mmma ..."
The new option WITH_STATIC_ANALYZER=1 instructs build system to run static analyzer via "clang --analyze" on a successful build. If analyzer finds any issue, instruction to open report is displayed. See http://clang-analyzer.llvm.org/scan-build.html for details. WITH_STATIC_ANALYZER trumps WITH_SYNTAX_CHECK if both exist. Project use lots of GCC extensions (eg. nested function) not supported by clang may opt out by adding LOCAL_NO_STATIC_ANALYZER:=true Change-Id: I9970560560bd52ce5f0fd7129c3488629627c735
This commit is contained in:
parent
a62334edaf
commit
906cb78168
|
@ -174,6 +174,10 @@ ifeq ($(strip $(WITH_SYNTAX_CHECK)),)
|
|||
LOCAL_NO_SYNTAX_CHECK := true
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
|
||||
LOCAL_NO_STATIC_ANALYZER := true
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
|
||||
my_syntax_arch := host
|
||||
else
|
||||
|
@ -187,9 +191,13 @@ ifeq ($(strip $(LOCAL_CC)),)
|
|||
LOCAL_CC := $($(my_prefix)CC)
|
||||
endif
|
||||
endif
|
||||
ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
|
||||
LOCAL_CC := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(LOCAL_CC)"
|
||||
else
|
||||
ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
|
||||
LOCAL_CC := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(LOCAL_CC)"
|
||||
endif
|
||||
endif
|
||||
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
|
||||
|
||||
ifeq ($(strip $(LOCAL_CXX)),)
|
||||
|
@ -199,9 +207,13 @@ ifeq ($(strip $(LOCAL_CXX)),)
|
|||
LOCAL_CXX := $($(my_prefix)CXX)
|
||||
endif
|
||||
endif
|
||||
ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
|
||||
LOCAL_CXX := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(LOCAL_CXX)"
|
||||
else
|
||||
ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
|
||||
LOCAL_CXX := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(LOCAL_CXX)"
|
||||
endif
|
||||
endif
|
||||
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
|
||||
|
||||
# TODO: support a mix of standard extensions so that this isn't necessary
|
||||
|
|
|
@ -138,6 +138,7 @@ LOCAL_PREBUILT_MODULE_FILE:=
|
|||
LOCAL_POST_INSTALL_CMD:=
|
||||
LOCAL_DIST_BUNDLED_BINARIES:=
|
||||
LOCAL_NO_SYNTAX_CHECK:=
|
||||
LOCAL_NO_STATIC_ANALYZER:=
|
||||
|
||||
# Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
|
||||
# iterate over thousands of entries every time.
|
||||
|
|
|
@ -247,8 +247,22 @@ TARGET_TOOLCHAIN_ROOT := $(patsubst %/, %, $(dir $(TARGET_TOOLCHAIN_ROOT)))
|
|||
TARGET_TOOLCHAIN_ROOT := $(wildcard $(TARGET_TOOLCHAIN_ROOT))
|
||||
endif
|
||||
|
||||
# Disable WITH_SYNTAX_CHECK if tool can't be found
|
||||
# Normalize WITH_STATIC_ANALYZER and WITH_SYNTAX_CHECK
|
||||
ifeq ($(strip $(WITH_STATIC_ANALYZER)),0)
|
||||
WITH_STATIC_ANALYZER :=
|
||||
endif
|
||||
ifeq ($(strip $(WITH_SYNTAX_CHECK)),0)
|
||||
WITH_SYNTAX_CHECK :=
|
||||
endif
|
||||
|
||||
# Disable WITH_STATIC_ANALYZER and WITH_SYNTAX_CHECK if tool can't be found
|
||||
SYNTAX_TOOLS_PREFIX := prebuilts/clang/$(HOST_PREBUILT_TAG)/host/3.3/bin
|
||||
ifneq ($(strip $(WITH_STATIC_ANALYZER)),)
|
||||
ifeq ($(wildcard $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer),)
|
||||
$(warning *** Disable WITH_STATIC_ANALYZER because $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer does not exist)
|
||||
WITH_STATIC_ANALYZER :=
|
||||
endif
|
||||
endif
|
||||
ifneq ($(strip $(WITH_SYNTAX_CHECK)),)
|
||||
ifeq ($(wildcard $(SYNTAX_TOOLS_PREFIX)/ccc-syntax),)
|
||||
$(warning *** Disable WITH_SYNTAX_CHECK because $(SYNTAX_TOOLS_PREFIX)/ccc-syntax does not exist)
|
||||
|
@ -256,6 +270,14 @@ ifneq ($(strip $(WITH_SYNTAX_CHECK)),)
|
|||
endif
|
||||
endif
|
||||
|
||||
# WITH_STATIC_ANALYZER trumps WITH_SYNTAX_CHECK
|
||||
ifneq ($(strip $(WITH_STATIC_ANALYZER)),)
|
||||
ifneq ($(strip $(WITH_SYNTAX_CHECK)),)
|
||||
$(warning *** Disable WITH_SYNTAX_CHECK in the presence of static analyzer WITH_STATIC_ANALYZER)
|
||||
WITH_SYNTAX_CHECK :=
|
||||
endif
|
||||
endif
|
||||
|
||||
# Pick a Java compiler.
|
||||
include $(BUILD_SYSTEM)/combo/javac.mk
|
||||
|
||||
|
|
43
envsetup.sh
43
envsetup.sh
|
@ -603,11 +603,26 @@ function gettop
|
|||
fi
|
||||
}
|
||||
|
||||
# Return driver for "make", if any (eg. static analyzer)
|
||||
function getdriver()
|
||||
{
|
||||
local T="$1"
|
||||
test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
|
||||
if [ -n "$WITH_STATIC_ANALYZER" ]; then
|
||||
echo "\
|
||||
$T/prebuilts/clang/linux-x86/host/3.3/tools/scan-build/scan-build \
|
||||
--use-analyzer $T/prebuilts/clang/linux-x86/host/3.3/bin/clang \
|
||||
--status-bugs \
|
||||
--top=$T"
|
||||
fi
|
||||
}
|
||||
|
||||
function m()
|
||||
{
|
||||
T=$(gettop)
|
||||
local T=$(gettop)
|
||||
local DRV=$(getdriver $T)
|
||||
if [ "$T" ]; then
|
||||
make -C $T -f build/core/main.mk $@
|
||||
$DRV make -C $T -f build/core/main.mk $@
|
||||
else
|
||||
echo "Couldn't locate the top of the tree. Try setting TOP."
|
||||
fi
|
||||
|
@ -632,13 +647,14 @@ function findmakefile()
|
|||
|
||||
function mm()
|
||||
{
|
||||
local T=$(gettop)
|
||||
local DRV=$(getdriver $T)
|
||||
# If we're sitting in the root of the build tree, just do a
|
||||
# normal make.
|
||||
if [ -f build/core/envsetup.mk -a -f Makefile ]; then
|
||||
make $@
|
||||
$DRV make $@
|
||||
else
|
||||
# Find the closest Android.mk file.
|
||||
T=$(gettop)
|
||||
local M=$(findmakefile)
|
||||
# Remove the path to top as the makefilepath needs to be relative
|
||||
local M=`echo $M|sed 's:'$T'/::'`
|
||||
|
@ -647,14 +663,15 @@ function mm()
|
|||
elif [ ! "$M" ]; then
|
||||
echo "Couldn't locate a makefile from the current directory."
|
||||
else
|
||||
ONE_SHOT_MAKEFILE=$M make -C $T -f build/core/main.mk all_modules $@
|
||||
ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk all_modules $@
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function mmm()
|
||||
{
|
||||
T=$(gettop)
|
||||
local T=$(gettop)
|
||||
local DRV=$(getdriver $T)
|
||||
if [ "$T" ]; then
|
||||
local MAKEFILE=
|
||||
local MODULES=
|
||||
|
@ -694,7 +711,7 @@ function mmm()
|
|||
fi
|
||||
fi
|
||||
done
|
||||
ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
|
||||
ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
|
||||
else
|
||||
echo "Couldn't locate the top of the tree. Try setting TOP."
|
||||
fi
|
||||
|
@ -702,21 +719,23 @@ function mmm()
|
|||
|
||||
function mma()
|
||||
{
|
||||
local T=$(gettop)
|
||||
local DRV=$(getdriver $T)
|
||||
if [ -f build/core/envsetup.mk -a -f Makefile ]; then
|
||||
make $@
|
||||
$DRV make $@
|
||||
else
|
||||
T=$(gettop)
|
||||
if [ ! "$T" ]; then
|
||||
echo "Couldn't locate the top of the tree. Try setting TOP."
|
||||
fi
|
||||
local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
|
||||
make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
|
||||
$DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
|
||||
fi
|
||||
}
|
||||
|
||||
function mmma()
|
||||
{
|
||||
T=$(gettop)
|
||||
local T=$(gettop)
|
||||
local DRV=$(getdriver $T)
|
||||
if [ "$T" ]; then
|
||||
local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
|
||||
local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
|
||||
|
@ -743,7 +762,7 @@ function mmma()
|
|||
esac
|
||||
fi
|
||||
done
|
||||
make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
|
||||
$DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
|
||||
else
|
||||
echo "Couldn't locate the top of the tree. Try setting TOP."
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue