Merge pull request #3468 from gebart/pr/scan-build-initial
scan-build: Add make goal for running Clang static code analyzer (ccc-analyzer)
This commit is contained in:
commit
fe2225e290
@ -5,44 +5,57 @@ export DOCKER_FLAGS ?= --rm
|
|||||||
export DOCKER_MAKECMDGOALS_POSSIBLE = \
|
export DOCKER_MAKECMDGOALS_POSSIBLE = \
|
||||||
all \
|
all \
|
||||||
buildtest \
|
buildtest \
|
||||||
|
scan-build \
|
||||||
|
scan-build-analyze \
|
||||||
#
|
#
|
||||||
export DOCKER_MAKECMDGOALS = $(filter $(MAKECMDGOALS),$(DOCKER_MAKECMDGOALS_POSSIBLE))
|
export DOCKER_MAKECMDGOALS = $(filter $(MAKECMDGOALS),$(DOCKER_MAKECMDGOALS_POSSIBLE))
|
||||||
|
|
||||||
|
# Docker creates the files .dockerinit and .dockerenv in the root directory of
|
||||||
|
# the container, we check for the files to determine if we are inside a container.
|
||||||
|
ifneq (,$(wildcard /.dockerinit /.dockerenv))
|
||||||
|
export INSIDE_DOCKER := 1
|
||||||
|
else
|
||||||
|
export INSIDE_DOCKER := 0
|
||||||
|
endif
|
||||||
|
|
||||||
# Default target for building inside a Docker container if nothing was given
|
# Default target for building inside a Docker container if nothing was given
|
||||||
export DOCKER_MAKECMDGOALS ?= all
|
export DOCKER_MAKECMDGOALS ?= all
|
||||||
# List of all exported environment variables that shall be passed on to the
|
# List of all exported environment variables that shall be passed on to the
|
||||||
# Docker container, they will only be passed if they are set from the
|
# Docker container, they will only be passed if they are set from the
|
||||||
# environment, not if they are only default Makefile values.
|
# environment, not if they are only default Makefile values.
|
||||||
export DOCKER_ENV_VARS = \
|
export DOCKER_ENV_VARS = \
|
||||||
BINDIRBASE \
|
|
||||||
BOARD \
|
|
||||||
QUIET \
|
|
||||||
RIOT_VERSION \
|
|
||||||
APPDIR \
|
APPDIR \
|
||||||
BINDIR \
|
|
||||||
BUILDRELPATH \
|
|
||||||
ELFFILE \
|
|
||||||
HEXFILE \
|
|
||||||
LINKFLAGPREFIX \
|
|
||||||
CPPMIX \
|
|
||||||
PREFIX \
|
|
||||||
CC \
|
|
||||||
CXX \
|
|
||||||
CFLAGS \
|
|
||||||
CXXUWFLAGS \
|
|
||||||
CXXEXFLAGS \
|
|
||||||
AR \
|
AR \
|
||||||
ARFLAGS \
|
ARFLAGS \
|
||||||
AS \
|
AS \
|
||||||
ASFLAGS \
|
ASFLAGS \
|
||||||
|
BINDIR \
|
||||||
|
BINDIRBASE \
|
||||||
|
BOARD \
|
||||||
|
BUILDRELPATH \
|
||||||
|
BUILDTEST_MCU_GROUP \
|
||||||
|
BUILDTEST_VERBOSE \
|
||||||
|
CC \
|
||||||
|
CFLAGS \
|
||||||
|
CPPMIX \
|
||||||
|
CXX \
|
||||||
|
CXXEXFLAGS \
|
||||||
|
CXXUWFLAGS \
|
||||||
|
ELFFILE \
|
||||||
|
HEXFILE \
|
||||||
LINK \
|
LINK \
|
||||||
|
LINKFLAGPREFIX \
|
||||||
LINKFLAGS \
|
LINKFLAGS \
|
||||||
OBJCOPY \
|
OBJCOPY \
|
||||||
OFLAGS \
|
OFLAGS \
|
||||||
|
PREFIX \
|
||||||
|
QUIET \
|
||||||
|
RIOT_VERSION \
|
||||||
|
SCANBUILD_ARGS \
|
||||||
|
SCANBUILD_OUTPUTDIR \
|
||||||
SIZE \
|
SIZE \
|
||||||
|
TOOLCHAIN \
|
||||||
UNDEF \
|
UNDEF \
|
||||||
BUILDTEST_MCU_GROUP \
|
|
||||||
BUILDTEST_VERBOSE \
|
|
||||||
#
|
#
|
||||||
|
|
||||||
# Find which variables were set using the command line or the environment and
|
# Find which variables were set using the command line or the environment and
|
||||||
@ -52,7 +65,7 @@ export DOCKER_ENV_VARS = \
|
|||||||
# origin is changed to "file"
|
# origin is changed to "file"
|
||||||
DOCKER_ENVIRONMENT_CMDLINE := $(foreach varname,$(DOCKER_ENV_VARS), \
|
DOCKER_ENVIRONMENT_CMDLINE := $(foreach varname,$(DOCKER_ENV_VARS), \
|
||||||
$(if $(filter environment command,$(origin $(varname))), \
|
$(if $(filter environment command,$(origin $(varname))), \
|
||||||
-e '$(varname)=$($(varname))', \
|
-e '$(varname)=$(subst ','\'',$($(varname)))', \
|
||||||
))
|
))
|
||||||
DOCKER_ENVIRONMENT_CMDLINE := $(strip $(DOCKER_ENVIRONMENT_CMDLINE))
|
DOCKER_ENVIRONMENT_CMDLINE := $(strip $(DOCKER_ENVIRONMENT_CMDLINE))
|
||||||
|
|
||||||
@ -70,6 +83,7 @@ DOCKER_ENVIRONMENT_CMDLINE := $(strip $(DOCKER_ENVIRONMENT_CMDLINE))
|
|||||||
-v '$(RIOTCPU):$(DOCKER_BUILD_ROOT)/riotcpu' \
|
-v '$(RIOTCPU):$(DOCKER_BUILD_ROOT)/riotcpu' \
|
||||||
-v '$(RIOTBOARD):$(DOCKER_BUILD_ROOT)/riotboard' \
|
-v '$(RIOTBOARD):$(DOCKER_BUILD_ROOT)/riotboard' \
|
||||||
-v '$(RIOTPROJECT):$(DOCKER_BUILD_ROOT)/riotproject' \
|
-v '$(RIOTPROJECT):$(DOCKER_BUILD_ROOT)/riotproject' \
|
||||||
|
-v /etc/localtime:/etc/localtime:ro \
|
||||||
-e 'RIOTBASE=$(DOCKER_BUILD_ROOT)/riotbase' \
|
-e 'RIOTBASE=$(DOCKER_BUILD_ROOT)/riotbase' \
|
||||||
-e 'RIOTCPU=$(DOCKER_BUILD_ROOT)/riotcpu' \
|
-e 'RIOTCPU=$(DOCKER_BUILD_ROOT)/riotcpu' \
|
||||||
-e 'RIOTBOARD=$(DOCKER_BUILD_ROOT)/riotboard' \
|
-e 'RIOTBOARD=$(DOCKER_BUILD_ROOT)/riotboard' \
|
||||||
|
|||||||
@ -18,6 +18,9 @@ RIOTPROJECT := $(abspath $(RIOTPROJECT))
|
|||||||
# using abspath, strip etc.
|
# using abspath, strip etc.
|
||||||
include $(RIOTBASE)/Makefile.docker
|
include $(RIOTBASE)/Makefile.docker
|
||||||
|
|
||||||
|
# Static code analysis tools provided by LLVM
|
||||||
|
include $(RIOTBASE)/Makefile.scan-build
|
||||||
|
|
||||||
# Path to the current directory relative to the git root
|
# Path to the current directory relative to the git root
|
||||||
BUILDRELPATH ?= $(shell git rev-parse --show-prefix)
|
BUILDRELPATH ?= $(shell git rev-parse --show-prefix)
|
||||||
|
|
||||||
@ -54,6 +57,12 @@ ifeq (, ${JENKINS_URL})
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(OS),Darwin)
|
||||||
|
OPEN := open
|
||||||
|
else
|
||||||
|
OPEN := xdg-open
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(QUIET),1)
|
ifeq ($(QUIET),1)
|
||||||
AD=@
|
AD=@
|
||||||
MAKEFLAGS += --no-print-directory
|
MAKEFLAGS += --no-print-directory
|
||||||
|
|||||||
91
Makefile.scan-build
Normal file
91
Makefile.scan-build
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
SCANBUILD_ENV_VARS := \
|
||||||
|
APPDIR \
|
||||||
|
AR \
|
||||||
|
ARFLAGS \
|
||||||
|
AS \
|
||||||
|
ASFLAGS \
|
||||||
|
BINDIR \
|
||||||
|
BINDIRBASE \
|
||||||
|
BOARD \
|
||||||
|
BUILDRELPATH \
|
||||||
|
CC \
|
||||||
|
CFLAGS \
|
||||||
|
CPPMIX \
|
||||||
|
CXX \
|
||||||
|
CXXEXFLAGS \
|
||||||
|
CXXUWFLAGS \
|
||||||
|
ELFFILE \
|
||||||
|
HEXFILE \
|
||||||
|
HOME \
|
||||||
|
LINK \
|
||||||
|
LINKFLAGPREFIX \
|
||||||
|
LINKFLAGS \
|
||||||
|
OBJCOPY \
|
||||||
|
OFLAGS \
|
||||||
|
PATH \
|
||||||
|
PREFIX \
|
||||||
|
QUIET \
|
||||||
|
RIOT_VERSION \
|
||||||
|
SIZE \
|
||||||
|
TOOLCHAIN \
|
||||||
|
UNDEF \
|
||||||
|
USER \
|
||||||
|
#
|
||||||
|
|
||||||
|
SCANBUILD_ARGS ?= \
|
||||||
|
-analyze-headers \
|
||||||
|
--use-cc=$(CC) \
|
||||||
|
--use-c++=$(CXX) \
|
||||||
|
-analyzer-config stable-report-filename=true \
|
||||||
|
#
|
||||||
|
|
||||||
|
export SCANBUILD_OUTPUTDIR = $(CURDIR)/scan-build/
|
||||||
|
|
||||||
|
# Find all variables given on the command line and recreate the command.
|
||||||
|
CMDVARS := $(strip $(foreach varname, $(SCANBUILD_ENV_VARS), \
|
||||||
|
$(if $(filter command, $(origin $(varname))), \
|
||||||
|
'$(varname)=$(subst ','\'',$($(varname)))', \
|
||||||
|
)))
|
||||||
|
ENVVARS := $(strip $(foreach varname, $(SCANBUILD_ENV_VARS), \
|
||||||
|
$(if $(filter environment, $(origin $(varname))), \
|
||||||
|
'$(varname)=$(subst ','\'',$($(varname)))', \
|
||||||
|
)))
|
||||||
|
|
||||||
|
.PHONY: scan-build scan-build-analyze scan-build-view
|
||||||
|
scan-build: scan-build-view scan-build-analyze
|
||||||
|
scan-build-view: scan-build-analyze
|
||||||
|
ifeq ($(BUILD_IN_DOCKER),1)
|
||||||
|
scan-build-analyze: ..in-docker-container
|
||||||
|
else # BUILD_IN_DOCKER
|
||||||
|
scan-build-analyze: clean
|
||||||
|
@$(COLOR_ECHO) '$(COLOR_GREEN)Performing Clang static code analysis using toolchain "$(TOOLCHAIN)".$(COLOR_RESET)'
|
||||||
|
# ccc-analyzer needs to be told the proper -target setting for best results,
|
||||||
|
# otherwise false error reports about unknown register names etc will be produced.
|
||||||
|
# These kinds of errors can be safely ignored as long as they only come from LLVM
|
||||||
|
@if [ "$${TOOLCHAIN}" != "llvm" -a "$${BOARD}" != "native" ]; then \
|
||||||
|
$(COLOR_ECHO) '$(COLOR_YELLOW)Recommend using TOOLCHAIN=llvm for best results.$(COLOR_RESET)'; \
|
||||||
|
$(COLOR_ECHO) '$(COLOR_YELLOW)Ignore any "error: unknown register name '\''rX'\'' in asm" messages.$(COLOR_RESET)'; \
|
||||||
|
fi
|
||||||
|
$(AD)mkdir -p '$(SCANBUILD_OUTPUTDIR)'
|
||||||
|
$(AD)env -i $(ENVVARS) \
|
||||||
|
scan-build -o '$(SCANBUILD_OUTPUTDIR)' $(SCANBUILD_ARGS) \
|
||||||
|
make -C $(CURDIR) all $(strip $(CMDVARS));
|
||||||
|
endif # BUILD_IN_DOCKER
|
||||||
|
|
||||||
|
ifeq (1,$(INSIDE_DOCKER))
|
||||||
|
scan-build-view:
|
||||||
|
@
|
||||||
|
else
|
||||||
|
@echo "Showing most recent report in your web browser..."
|
||||||
|
@REPORT_FILE="$$(find '$(SCANBUILD_OUTPUTDIR)' -maxdepth 2 -mindepth 2 \
|
||||||
|
-type f -name 'index.html' 2>/dev/null | sort | tail -n 1)"; \
|
||||||
|
if [ -n "$${REPORT_FILE}" ]; then \
|
||||||
|
echo "$(OPEN) $${REPORT_FILE}"; \
|
||||||
|
$(OPEN) "$${REPORT_FILE}"; \
|
||||||
|
else \
|
||||||
|
echo "No report found"; \
|
||||||
|
fi
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Reset the default goal.
|
||||||
|
.DEFAULT_GOAL :=
|
||||||
Loading…
x
Reference in New Issue
Block a user