public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH RESEND v2] Makefile: check for cppcheck's --check-level option in cppcheck target
@ 2024-02-28 17:19 Stefano Brivio
  0 siblings, 0 replies; only message in thread
From: Stefano Brivio @ 2024-02-28 17:19 UTC (permalink / raw)
  To: passt-dev; +Cc: Rahil Bhimjiani, David Gibson

Don't run cppcheck to find out if the --check-level=exhaustive option
is available, unless we're actually going to run cppcheck later.

To avoid this, move this check under the cppcheck target, and
implement it in shell script instead of using Makefile directives,
because we can't easily implement conditionals in recipes.

Reported-by: Rahil Bhimjiani <me@rahil.rocks>
Link: https://bugs.gentoo.org/920795
Fixes: 8640d62af719 ("cppcheck: Use "exhaustive" level checking when available")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
Re-send to/with the right address for Rahil (Gentoo maintainer)

v2: Actually fetch the shell variable for cppcheck's command line

 Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index af4fa87..75f49dc 100644
--- a/Makefile
+++ b/Makefile
@@ -287,20 +287,20 @@ clang-tidy: $(SRCS) $(HEADERS)
 	-config='{CheckOptions: [{key: bugprone-suspicious-string-compare.WarnOnImplicitComparison, value: "false"}]}' \
 	--warnings-as-errors=* $(SRCS) -- $(filter-out -pie,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) -DCLANG_TIDY_58992
 
-CPPCHECK_EXHAUSTIVE :=
-ifeq ($(shell cppcheck --check-level=exhaustive /dev/null > /dev/null 2>&1; echo $$?),0)
-	CPPCHECK_EXHAUSTIVE += --check-level=exhaustive
-endif
-
 SYSTEM_INCLUDES := /usr/include $(wildcard /usr/include/$(TARGET))
 ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"),1)
 VER := $(shell $(CC) -dumpversion)
 SYSTEM_INCLUDES += /usr/lib/gcc/$(TARGET)/$(VER)/include
 endif
 cppcheck: $(SRCS) $(HEADERS)
+	if cppcheck --check-level=exhaustive /dev/null > /dev/null 2>&1; then \
+		CPPCHECK_EXHAUSTIVE="--check-level=exhaustive";		\
+	else								\
+		CPPCHECK_EXHAUSTIVE=;					\
+	fi;								\
 	cppcheck --std=c11 --error-exitcode=1 --enable=all --force	\
 	--inconclusive --library=posix --quiet				\
-	$(CPPCHECK_EXHAUSTIVE)						\
+	$${CPPCHECK_EXHAUSTIVE}						\
 	$(SYSTEM_INCLUDES:%=-I%)					\
 	$(SYSTEM_INCLUDES:%=--config-exclude=%)				\
 	$(SYSTEM_INCLUDES:%=--suppress=*:%/*)				\
-- 
@@ -287,20 +287,20 @@ clang-tidy: $(SRCS) $(HEADERS)
 	-config='{CheckOptions: [{key: bugprone-suspicious-string-compare.WarnOnImplicitComparison, value: "false"}]}' \
 	--warnings-as-errors=* $(SRCS) -- $(filter-out -pie,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) -DCLANG_TIDY_58992
 
-CPPCHECK_EXHAUSTIVE :=
-ifeq ($(shell cppcheck --check-level=exhaustive /dev/null > /dev/null 2>&1; echo $$?),0)
-	CPPCHECK_EXHAUSTIVE += --check-level=exhaustive
-endif
-
 SYSTEM_INCLUDES := /usr/include $(wildcard /usr/include/$(TARGET))
 ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version"),1)
 VER := $(shell $(CC) -dumpversion)
 SYSTEM_INCLUDES += /usr/lib/gcc/$(TARGET)/$(VER)/include
 endif
 cppcheck: $(SRCS) $(HEADERS)
+	if cppcheck --check-level=exhaustive /dev/null > /dev/null 2>&1; then \
+		CPPCHECK_EXHAUSTIVE="--check-level=exhaustive";		\
+	else								\
+		CPPCHECK_EXHAUSTIVE=;					\
+	fi;								\
 	cppcheck --std=c11 --error-exitcode=1 --enable=all --force	\
 	--inconclusive --library=posix --quiet				\
-	$(CPPCHECK_EXHAUSTIVE)						\
+	$${CPPCHECK_EXHAUSTIVE}						\
 	$(SYSTEM_INCLUDES:%=-I%)					\
 	$(SYSTEM_INCLUDES:%=--config-exclude=%)				\
 	$(SYSTEM_INCLUDES:%=--suppress=*:%/*)				\
-- 
2.39.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-28 17:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 17:19 [PATCH RESEND v2] Makefile: check for cppcheck's --check-level option in cppcheck target Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).