From bba88065acde32e6f97d486c9be4b47b78565a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 14 Nov 2018 13:01:09 +0100 Subject: [PATCH 1/5] makefiles/scan-build: make RIOT_CI_BUILD visible to scan-build This is required to have reference builds context using the right RIOT_VERSION_OVERRIDE=buildtest. --- makefiles/scan-build.inc.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/makefiles/scan-build.inc.mk b/makefiles/scan-build.inc.mk index f91c691b77b5..9ac3ca917a75 100644 --- a/makefiles/scan-build.inc.mk +++ b/makefiles/scan-build.inc.mk @@ -27,6 +27,7 @@ SCANBUILD_ENV_VARS := \ QUIET \ WERROR \ RIOT_VERSION \ + RIOT_CI_BUILD \ SIZE \ TOOLCHAIN \ UNDEF \ From e3b50a6bf8327a4891286753ae8a1b2fcd29f567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 14 Nov 2018 13:01:09 +0100 Subject: [PATCH 2/5] makefiles/scan-build: Provide a per board scan-build output Update the SCANBUILD_OUTPUTDIR to be per board. Also remove un-necessary export and 'CURDIR'. --- makefiles/scan-build.inc.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefiles/scan-build.inc.mk b/makefiles/scan-build.inc.mk index 9ac3ca917a75..d95604fdfc00 100644 --- a/makefiles/scan-build.inc.mk +++ b/makefiles/scan-build.inc.mk @@ -41,7 +41,7 @@ SCANBUILD_ARGS ?= \ -analyzer-config stable-report-filename=true \ # -export SCANBUILD_OUTPUTDIR = $(CURDIR)/scan-build/ +SCANBUILD_OUTPUTDIR = scan-build/$(BOARD) # Find all variables given on the command line and recreate the command. CMDVARS := $(strip $(foreach varname, $(SCANBUILD_ENV_VARS), \ From bcf292b3d451fce183804fc558558723fa212e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 14 Nov 2018 13:01:09 +0100 Subject: [PATCH 3/5] makefiles/scan-build: Remove un-necessary ';' --- makefiles/scan-build.inc.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefiles/scan-build.inc.mk b/makefiles/scan-build.inc.mk index d95604fdfc00..cadd234a0fea 100644 --- a/makefiles/scan-build.inc.mk +++ b/makefiles/scan-build.inc.mk @@ -71,7 +71,7 @@ scan-build-analyze: clean $(Q)mkdir -p '$(SCANBUILD_OUTPUTDIR)' $(Q)env -i $(ENVVARS) \ scan-build -o '$(SCANBUILD_OUTPUTDIR)' $(SCANBUILD_ARGS) \ - make -C $(CURDIR) all $(strip $(CMDVARS)) FORCE_ASSERTS=1; + make -C $(CURDIR) all $(strip $(CMDVARS)) FORCE_ASSERTS=1 endif # BUILD_IN_DOCKER ifeq (1,$(INSIDE_DOCKER)) From ea3c1661f3ce27a44757eeedd1de4527d5a6bae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 14 Nov 2018 13:01:09 +0100 Subject: [PATCH 4/5] makefiles/scan-build: Fix 'scan-build-analyze' target This correctly defines a `scan-build-analyze` target that does not display the result webpage. `scan-build-view` has now been moved to a private target as should not be used directly. The handling of displaying the page on the host system and implementing 'scan-build-analyze' are now explicitely done with separate targets and not double implemented target when in docker or on the host that were executed twice with different implementations. --- makefiles/scan-build.inc.mk | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/makefiles/scan-build.inc.mk b/makefiles/scan-build.inc.mk index cadd234a0fea..42034222fb47 100644 --- a/makefiles/scan-build.inc.mk +++ b/makefiles/scan-build.inc.mk @@ -53,13 +53,25 @@ ENVVARS := $(strip $(foreach varname, $(SCANBUILD_ENV_VARS), \ '$(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 +.PHONY: scan-build scan-build-analyze +.PHONY: ..scan-build-view ..scan-build-analyze + +ifeq (1,$(INSIDE_DOCKER)) +# In the container just do the analysis, 'view' will be done by the host +scan-build: ..scan-build-analyze +else # INSIDE_DOCKER +scan-build: ..scan-build-view +endif # INSIDE_DOCKER + ifeq ($(BUILD_IN_DOCKER),1) +# It will trigger executing 'scan-build' or 'scan-build-analyze' with docker scan-build-analyze: ..in-docker-container else # BUILD_IN_DOCKER -scan-build-analyze: clean +scan-build-analyze: ..scan-build-analyze +endif # 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. @@ -72,12 +84,8 @@ scan-build-analyze: clean $(Q)env -i $(ENVVARS) \ scan-build -o '$(SCANBUILD_OUTPUTDIR)' $(SCANBUILD_ARGS) \ make -C $(CURDIR) all $(strip $(CMDVARS)) FORCE_ASSERTS=1 -endif # BUILD_IN_DOCKER -ifeq (1,$(INSIDE_DOCKER)) -scan-build-view: - @ -else +..scan-build-view: scan-build-analyze @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)"; \ @@ -87,4 +95,3 @@ else else \ echo "No report found"; \ fi -endif From 50f58bfb07714bc734c13f30dc2f1df6c21beaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 14 Nov 2018 13:01:09 +0100 Subject: [PATCH 5/5] makefiles/scan-build: Produce an error when doing 'scan-build-analyze' This makes doing 'scan-build-analyze' produce an error at execution if WERROR=1. When used from `scan-build` it will not procude an error to display the result webpage. --- makefiles/scan-build.inc.mk | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/makefiles/scan-build.inc.mk b/makefiles/scan-build.inc.mk index 42034222fb47..5160971c7e3c 100644 --- a/makefiles/scan-build.inc.mk +++ b/makefiles/scan-build.inc.mk @@ -34,11 +34,15 @@ SCANBUILD_ENV_VARS := \ USER \ # +# Produce errors by default at the end of compilation when warning are found +SCANBUILD_ERROR ?= $(if $(filter 1,$(WERROR)),--status-bugs) + SCANBUILD_ARGS ?= \ -analyze-headers \ --use-cc=$(CC) \ --use-c++=$(CXX) \ -analyzer-config stable-report-filename=true \ + $(SCANBUILD_ERROR) \ # SCANBUILD_OUTPUTDIR = scan-build/$(BOARD) @@ -63,6 +67,10 @@ else # INSIDE_DOCKER scan-build: ..scan-build-view endif # INSIDE_DOCKER +# Prevent 'analyze' from producing an error when doing 'scan-build' and +# still show the webpage for interractive checking. +scan-build: SCANBUILD_ERROR= + ifeq ($(BUILD_IN_DOCKER),1) # It will trigger executing 'scan-build' or 'scan-build-analyze' with docker scan-build-analyze: ..in-docker-container