From aafa5052aa6d5093ec7b0abfe87f5c4c79f41858 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 19 Sep 2021 21:25:09 -0400 Subject: [PATCH 1/2] Unix entry points: correctly detect the availability of a python binary The "which" program is not suitable for determining the existence or location of a python binary, because it is a non-standard program that is often not installed. It is often possible to manually install it as a third-party addon anyway, but this is a very bad thing to rely on in order to get good out of the box behavior. If and when it is installed, it may display various incorrect behaviors, including unparseable output on stdout instead of stderr, outputting the contents of ~/.cshrc aliases, and more. For more details on why never to use "which", see: https://mywiki.wooledge.org/BashFAQ/081 https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250 Instead, use the POSIX 2008 mandated builtin "command -v" implemented by all valid /bin/sh implementations, including ash, bash, busybox sh, dash, ksh, mksh, and zsh. "command -v" has an actual standards body guaranteeing the format of the output, and that it is usable as a filesystem path to an executable, for all shells produced in the last 13 years. It is thus unlikely to break in the same way "which" does. --- tools/run_python.sh | 4 ++-- tools/run_python_compiler.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/run_python.sh b/tools/run_python.sh index 232f947841a40..8464d365b479d 100755 --- a/tools/run_python.sh +++ b/tools/run_python.sh @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/tools/run_python_compiler.sh b/tools/run_python_compiler.sh index adf1caa3af53d..00851011f7692 100644 --- a/tools/run_python_compiler.sh +++ b/tools/run_python_compiler.sh @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then From 5745d6ef91ca39ef1f03c6a79517baf0b2e8c54c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 19 Sep 2021 21:47:39 -0400 Subject: [PATCH 2/2] regenerate entry points from template --- em++ | 4 ++-- em-config | 4 ++-- emar | 4 ++-- embuilder | 4 ++-- emcc | 4 ++-- emcmake | 4 ++-- emconfigure | 4 ++-- emdump | 4 ++-- emdwp | 4 ++-- emmake | 4 ++-- emnm | 4 ++-- emprofile | 4 ++-- emranlib | 4 ++-- emrun | 4 ++-- emscons | 4 ++-- emsize | 4 ++-- tests/runner | 4 ++-- tools/file_packager | 4 ++-- tools/webidl_binder | 4 ++-- 19 files changed, 38 insertions(+), 38 deletions(-) diff --git a/em++ b/em++ index adf1caa3af53d..00851011f7692 100755 --- a/em++ +++ b/em++ @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/em-config b/em-config index 232f947841a40..8464d365b479d 100755 --- a/em-config +++ b/em-config @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emar b/emar index 232f947841a40..8464d365b479d 100755 --- a/emar +++ b/emar @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/embuilder b/embuilder index 232f947841a40..8464d365b479d 100755 --- a/embuilder +++ b/embuilder @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emcc b/emcc index adf1caa3af53d..00851011f7692 100755 --- a/emcc +++ b/emcc @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emcmake b/emcmake index 232f947841a40..8464d365b479d 100755 --- a/emcmake +++ b/emcmake @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emconfigure b/emconfigure index 232f947841a40..8464d365b479d 100755 --- a/emconfigure +++ b/emconfigure @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emdump b/emdump index 743fe03255675..4f6cfc2c25c65 100755 --- a/emdump +++ b/emdump @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emdwp b/emdwp index 727b147d32232..60f190e779aa4 100755 --- a/emdwp +++ b/emdwp @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emmake b/emmake index 232f947841a40..8464d365b479d 100755 --- a/emmake +++ b/emmake @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emnm b/emnm index e662d746e7839..d160da3e6492a 100755 --- a/emnm +++ b/emnm @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emprofile b/emprofile index 6a0cbc717dfb5..16678aaf9dedb 100755 --- a/emprofile +++ b/emprofile @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emranlib b/emranlib index 232f947841a40..8464d365b479d 100755 --- a/emranlib +++ b/emranlib @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emrun b/emrun index 232f947841a40..8464d365b479d 100755 --- a/emrun +++ b/emrun @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emscons b/emscons index 232f947841a40..8464d365b479d 100755 --- a/emscons +++ b/emscons @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/emsize b/emsize index 232f947841a40..8464d365b479d 100755 --- a/emsize +++ b/emsize @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/tests/runner b/tests/runner index 232f947841a40..8464d365b479d 100755 --- a/tests/runner +++ b/tests/runner @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/tools/file_packager b/tools/file_packager index 232f947841a40..8464d365b479d 100755 --- a/tools/file_packager +++ b/tools/file_packager @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then diff --git a/tools/webidl_binder b/tools/webidl_binder index 232f947841a40..8464d365b479d 100755 --- a/tools/webidl_binder +++ b/tools/webidl_binder @@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python3 2> /dev/null) + PYTHON=$(command -v python3 2> /dev/null) fi if [ -z "$PYTHON" ]; then - PYTHON=$(which python 2> /dev/null) + PYTHON=$(command -v python 2> /dev/null) fi if [ -z "$PYTHON" ]; then