-
Notifications
You must be signed in to change notification settings - Fork 30k
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
build: fix inability to detect correct python command in configure #32925
Conversation
The "which" utility is not guaranteed to be installed, and if it is, its behavior is not portable. Conversely, the "command -v" shell builtin is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere. Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh. Signed-off-by: Eli Schwartz <[email protected]>
This seems a high-risk change, in that verifying it across all our user's systems is not possible, we'll know if its a problem only when it breaks something that used to work, and its not clear - what actual problem is it fixing? Is there a system on which the current script doesn't work? |
Exactly the problem which I described: my system does not have the "which" thirdparty utility installed. (My system happens to be Arch Linux. The ... Furthermore, if it does exist, it might not do what you think it does. For some in-depth discussions on the topic, see https://mywiki.wooledge.org/BashFAQ/081 or https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250 ... This is not high-risk, since the configure script must be run with /bin/sh and every single /bin/sh on any system anywhere has a builtin shell feature called command -v, as long as it was produced within the last 12 years, and a number of them have had it for much, much longer.
On any POSIX 2008 compliant /bin/sh, a very old standard indeed, command -v must work, and must return a successful exit code when the searched-for command exists as a path or shell function or builtin. You will know if it is a shell function, because it will be defined in your script, which is under your control... you also know that It is literally the definition of portable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen command -v
being used as a more portable approach in other projects, so LGTM. If we want to be extra careful, we could have a double-check, something like:
WHICH=($(command -v command >/dev/null && echo "command -v" || echo "which"))
"@{WHICH[@]}" python3.8 >/dev/null && exec python3.8 "$0" "$@"
This would ensure we'll use command -v
or which
, depending on platform availability.
Using arrays is utterly unacceptable, since this is a /bin/sh script and arrays are not part of the shell command language. They're a bashism, which might work on some systems iff the system /bin/sh happens to be a symlink to bash or ksh or zsh, but this is much less likely to work than the GNU autotools has a complex boilerplate routine which uses pure shell to find programs, including routines for detecting whether the $PATH uses the But none of this is necessary unless your actual goal is, like autotools configure scripts, to support building on systems that predate POSIX. And autotools takes their portability very seriously -- they also scrupulously go to pains to use the confusingly ambiguous, deprecated
form of command substitution, instead of |
Landed in b21556d |
The "which" utility is not guaranteed to be installed, and if it is, its behavior is not portable. Conversely, the "command -v" shell builtin is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere. Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh. Signed-off-by: Eli Schwartz <[email protected]> PR-URL: nodejs#32925 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The "which" utility is not guaranteed to be installed, and if it is, its behavior is not portable. Conversely, the "command -v" shell builtin is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere. Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh. Signed-off-by: Eli Schwartz <[email protected]> PR-URL: #32925 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The "which" utility is not guaranteed to be installed, and if it is, its behavior is not portable. Conversely, the "command -v" shell builtin is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere. Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh. Signed-off-by: Eli Schwartz <[email protected]> PR-URL: #32925 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The "which" utility is not guaranteed to be installed, and if it is, its behavior is not portable.
Conversely, the "command -v" shell builtin is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.
Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes