From d94b4e0ec19d24535ad9b5a477704ffac097c1e9 Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 16 Apr 2022 10:02:56 +0200 Subject: [PATCH 1/2] makefiles: Reject `2>&1 > /dev/null` While this could theoretically be desired, it's usually just a mishap. It is unlikely that legitimate cases will be needed in the build system; if so, they can exclude themselves. See-Also: https://github.com/RIOT-OS/RIOT/pull/16775 --- dist/tools/buildsystem_sanity_check/check.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dist/tools/buildsystem_sanity_check/check.sh b/dist/tools/buildsystem_sanity_check/check.sh index a7ebe0f18c..d152251381 100755 --- a/dist/tools/buildsystem_sanity_check/check.sh +++ b/dist/tools/buildsystem_sanity_check/check.sh @@ -349,6 +349,19 @@ check_no_riot_config() { | error_with_message "Don't push RIOT_CONFIG_* definitions upstream. Rather define configuration via Kconfig" } +check_stderr_null() { + local patterns=() + local pathspec=() + + patterns+=(-e '2>[[:blank:]]*&1[[:blank:]]*>[[:blank:]]*/dev/null') + + pathspec+=('Makefile*') + pathspec+=('**/Makefile*') + pathspec+=('**/*.mk') + git -C "${RIOTBASE}" grep -n "${patterns[@]}" -- "${pathspec[@]}" \ + | error_with_message "Redirecting stderr and stdout to /dev/null is \`>/dev/null 2>&1\`; the other way round puts the old stderr to the new stdout." +} + error_on_input() { ! grep '' } @@ -369,6 +382,7 @@ all_checks() { check_no_usemodules_in_makefile_include check_no_pkg_source_local check_no_riot_config + check_stderr_null } main() { From 25e11d99b199b32459e7b89f465dcbdf1f4f74a9 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 3 Sep 2021 13:24:39 +0200 Subject: [PATCH 2/2] make: Sort >/dev/null and 2>&1 when used with command This is a follow-up for [16775], and was not caught there as that search was limited to `which`. Note that while this line can be simplified, the redirects ensure that GNU Make < 4.3 will not optimize it into its own built-in shell that does not know `command`. [16775]: https://github.com/RIOT-OS/RIOT/pull/16775 --- dist/testbed-support/makefile.iotlab.single.inc.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/testbed-support/makefile.iotlab.single.inc.mk b/dist/testbed-support/makefile.iotlab.single.inc.mk index bc22940a71..6f35fcee40 100644 --- a/dist/testbed-support/makefile.iotlab.single.inc.mk +++ b/dist/testbed-support/makefile.iotlab.single.inc.mk @@ -51,7 +51,7 @@ endif IOTLAB_AUTH ?= $(HOME)/.iotlabrc IOTLAB_USER ?= $(shell cut -f1 -d: $(IOTLAB_AUTH)) -ifneq (0,$(shell command -v iotlab-experiment -h 2>&1 > /dev/null ; echo $$?)) +ifneq (0,$(shell command -v iotlab-experiment -h > /dev/null 2>&1; echo $$?)) $(info $(COLOR_RED)'iotlab-experiment' command is not available \ please consider installing it from \ https://pypi.python.org/pypi/iotlabcli$(COLOR_RESET)) @@ -60,7 +60,7 @@ endif ifeq (iotlab-a8-m3,$(BOARD)) ifneq (,$(filter flash% reset,$(MAKECMDGOALS))) - ifneq (0,$(shell command -v iotlab-ssh -h 2>&1 > /dev/null ; echo $$?)) + ifneq (0,$(shell command -v iotlab-ssh -h > /dev/null 2>&1; echo $$?)) $(info $(COLOR_RED)'iotlab-ssh' command is not available \ please consider installing it from \ https://pypi.python.org/pypi/iotlabsshcli$(COLOR_RESET))