Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makefiles: Reject 2>&1 >/dev/null, and weed out remaining offenders #16806

Merged
merged 2 commits into from
Apr 16, 2022

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Sep 3, 2021

Contribution description

Shell redirects in the form of 2>&1 >/dev/null do not, as one might think, redirect both stdout and err to /dev/null, but put stdout to /dev/null and redirect stderr to the process's standard output.

This adds an automated test for such redirects, and removes two more redirects that were spotted with its help.

Testing procedure

  • CI says Go
  • Adding Makefile code with 2>&1 >/dev/null trips up the static checks.

Issues/PRs references

This is a follow-up on #16775 with the unproblematic parts of #16776 (which had to be reverted; the problematic parts come up in a different PR with more caution this time).

@chrysn chrysn added Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 3, 2021
@github-actions github-actions bot added the Area: tools Area: Supplementary tools label Sep 3, 2021
@@ -57,7 +57,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 $$?))
Copy link
Contributor

@benpicco benpicco Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ifneq (0,$(shell command -v iotlab-experiment -h > /dev/null 2>&1; echo $$?))
ifneq (0,$(shell command -v iotlab-experiment -h > /dev/null; echo $$?))

why not leave stderr in place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the complexity of this is what keeps Make from being clever.

The whole line can be simplified to ifeq (,$(shell command -v iotlab-experiment)), but then this fails on every GNU Make < 4.3 (ie. every Ubuntu ever released) like what broke everything this morning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put more generally, what this PR is about is just about forcing out and fixing the particular bug of using 2>&1 >/dev/null. There is a whole other issue about unifying the which and command calls in #16807, but I'd like to keep the focus here to fixing the sequence -- especially because eagerly fixing bycatch of shell command has been disastrous before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will behave different without the stderr redirect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might; I'd need to dig up some of the old offending environments where make tries to forego the actual shell forking to evaluate it.

Once we're sure that no old make versions are around on users' systems any more (and we don't have a strict dependency there, but I'm holding off #16807 for some more time), we can reevaluate all these, but until then, I'm trying to minimally fix the errors around command.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Apr 16, 2022
@chrysn chrysn removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 16, 2022
@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Apr 16, 2022
@chrysn chrysn added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 16, 2022
@chrysn chrysn force-pushed the which-hunt-the-good-parts branch from 35b9d13 to b64a16d Compare April 16, 2022 08:03
chrysn added 2 commits April 16, 2022 10:04
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: RIOT-OS#16775
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]: RIOT-OS#16775
@chrysn chrysn force-pushed the which-hunt-the-good-parts branch from b64a16d to 25e11d9 Compare April 16, 2022 08:04
@chrysn
Copy link
Member Author

chrysn commented Apr 16, 2022

Rebased to fix merge conflicts.

@chrysn chrysn merged commit 0989cbb into RIOT-OS:master Apr 16, 2022
@chrysn chrysn deleted the which-hunt-the-good-parts branch April 16, 2022 11:03
@chrysn chrysn added this to the Release 2022.07 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants