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

Remove which from shell invocations #16776

Merged
merged 4 commits into from
Sep 3, 2021

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Aug 24, 2021

Contribution description

The which command is being deprecated in Debian (see references below).

This moves all invocations in the build system from which to the successor command -v.

Testing procedure

Try building anything on a recent Debian sid system. While it'll fail on master, after #16775 you'll get several lines of

/usr/bin/which: this version of `which' is deprecated; use `command -v' in scripts instead.

that are gone after this patch sequence.

Any attempt to reintroduce $(shell which ...) in the Makefiles should also trigger the sanity checks of dist/tools/buildsystem_sanity_check/check.sh.

Issues/PRs references

This is a follow-up of (and based on) #16775. It was split out after some build process spew errors for not knowing command. As #16775 is blocking my workflows and I'd have to keep it around on each of my branches, I'd like to make that mergable quickly, and keep this for discussions of whether all of our users are now on platforms where command is available. (It has already been in use in some places in the build system, but these seem not to have been covered in that particular build platform).

debianutils' which, in its changelog, states:

  * The 'which' utility will be removed in the future.  Shell scripts
    often use it to check whether a command is available.  A more
    standard way to do this is with 'command -v'; for example:
      if command -v update-icon-caches >/dev/null; then
        update-icon-caches /usr/share/icons/...
      fi
    '2>/dev/null' is unnecessary when using 'command': POSIX says "no
    output shall be written" if the command isn't found.  It's also
    unnecessary for the debianutils version of 'which', and hides the
    deprecation warning.

Note that this PR does not change which to command, it just fixes the fallout of ill-sequenced redirects. That change is probably good to do, but right now this should be minimal enough to get merged quickly, and I don't want it held up in the question of whether everyone and their dog already implement POSIX command.

@github-actions github-actions bot added Area: build system Area: Build system Area: CI Area: Continuous Integration of RIOT components Area: pkg Area: External package ports Area: tools Area: Supplementary tools Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Aug 24, 2021
@chrysn chrysn added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs and removed Area: pkg Area: External package ports Area: CI Area: Continuous Integration of RIOT components Area: tools Area: Supplementary tools Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Aug 24, 2021
@chrysn
Copy link
Member Author

chrysn commented Aug 24, 2021

Checking Ubuntu versions, command -v has been supported in /bin/sh since at least 10.04 (stopped 10 years ago); playing around a bit... but would appreciate any insights.


pathspec+=('**/Makefile*')
git -C "${RIOTBASE}" grep -n "${patterns[@]}" -- "${pathspec[@]}" \
| error_with_message "Don't push PKG_SOURCE_LOCAL definitions upstream"
Copy link
Member

Choose a reason for hiding this comment

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

Wrong error message ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

In-very-deed. Thanks, fixed. (And tests generally improved, and one for the redirects of #16775 added for good measure.)

@github-actions github-actions bot added Area: CI Area: Continuous Integration of RIOT components Area: pkg Area: External package ports Area: tools Area: Supplementary tools Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms labels Aug 24, 2021
Comment on lines +359 to +360
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."
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure this can be generally assumed. I myself, actually, sometimes use 2>&1 > /dev/null where one would use &> /dev/null in bash (which is a bashism that does not work in every shell, such as dash)

Copy link
Member Author

Choose a reason for hiding this comment

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

2>&1 >/dev/null sends the old stderr to the original stdout.

>/dev/null 2>&1 does as &>/dev/null and sends both to /dev/null.

This is what caused the errors in #16776 when output to stderr was suddenly misdirected into a stdout where it was to be compared to echo $?'s "0" output.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, gotcha!

@fjmolinas
Copy link
Contributor

please rebase @chrysn

@chrysn chrysn force-pushed the shell-make-fixes-2 branch from c8dcc28 to a91d870 Compare August 27, 2021 08:45
@chrysn
Copy link
Member Author

chrysn commented Aug 27, 2021

The Python error looks like there's a stray redirect somewhere, investigating...

@github-actions github-actions bot removed the Area: CI Area: Continuous Integration of RIOT components label Aug 27, 2021
@miri64
Copy link
Member

miri64 commented Aug 27, 2021

The Python error looks like there's a stray redirect somewhere, investigating...

I think https://github.com/RIOT-OS/RIOT/pull/16776/checks?check_run_id=3445443625#step:7:47 tells the truth.

sudo apt-get install gcc-multilib

curl or wget should be added here (though I am not sure why it is needed for building hello-world 😅)

@miri64
Copy link
Member

miri64 commented Aug 27, 2021

(though I am not sure why it is needed for building hello-world 😅)

I deem this out of scope of this PR though ;-).

@chrysn
Copy link
Member Author

chrysn commented Aug 27, 2021

curl and wget not being found are the typical symptoms of a failing which (or command). PATH won't cut it as command is not an executable but a shell built-in required by POSIX to be implemented by any sh. Will look further tomorrow.

@miri64
Copy link
Member

miri64 commented Aug 28, 2021

PATH won't cut it as command is not an executable but a shell built-in required by POSIX to be implemented by any sh. Will look further tomorrow.

Yeah, I noticed that as well, that's why I removed the comment ;-)

@fjmolinas
Copy link
Contributor

(though I am not sure why it is needed for building hello-world sweat_smile)

I deem this out of scope of this PR though ;-).

taken care in #16784, lets see if no unexpected things blow up.

As the POSIX documentation[1] of `command -v` guarantees that on error
there will be no output (and there will be output in the other cases),
the tests in Makefiles were simplified to test for output equality to
the empty string.

Redirects swallowing error outputs were removed, as the command produces
no error output there (as recommended at [2]).

Existing uses of `command` are simplified as well.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
[2]: https://salsa.debian.org/debian/debianutils/-/blob/master/debian/NEWS
... as that command is deprecated at least on Debian, and a good
replacement is available in the form of `command -v`.
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
... because even though it looks like a subshell, it apparently is not
evaluated through a shell but passed right into exec.
@chrysn chrysn force-pushed the shell-make-fixes-2 branch from cea69d1 to 8664eb8 Compare September 2, 2021 14:31
@chrysn
Copy link
Member Author

chrysn commented Sep 2, 2021

For reasons I can't fathom (might be #16784, but I don't see how), the spurious errors in the Python checks are now gone.

Good to go?

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK!

@chrysn chrysn merged commit d4ed42a into RIOT-OS:master Sep 3, 2021
@chrysn chrysn deleted the shell-make-fixes-2 branch September 3, 2021 07:04
@miri64
Copy link
Member

miri64 commented Sep 3, 2021

For reasons I can't fathom (might be #16784, but I don't see how), the spurious errors in the Python checks are now gone.

That's how: #16776 (comment) wget/curl is now not a dependency anymore so the make flash called within that python script, now works without problems :-).

@miri64
Copy link
Member

miri64 commented Sep 3, 2021

Something went wrong :-/ #16020

@miri64
Copy link
Member

miri64 commented Sep 3, 2021

Why were compile tests skipped on a build system change?

@chrysn
Copy link
Member Author

chrysn commented Sep 3, 2021

Revert WIP, explaining later.

@miri64
Copy link
Member

miri64 commented Sep 3, 2021

Alternatively, there is the hard way here #16803

chrysn added a commit to chrysn-pull-requests/RIOT that referenced this pull request Sep 3, 2021
…uests/shell-make-fixes-2"

This reverts commit d4ed42a, reversing
changes made to 2bf1202.

Additions to the checks are left in place, but disabled while the
current state would not pass them.
@chrysn
Copy link
Member Author

chrysn commented Sep 3, 2021

#16804 is up now to fix the immediate fallout.

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: pkg Area: External package ports 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 CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants