Skip to content

Commit 9d63033

Browse files
authored
Unix entry points: correctly detect the availability of a python binary (emscripten-core#15071)
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.
1 parent fdd486f commit 9d63033

21 files changed

Lines changed: 42 additions & 42 deletions

em++

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

em-config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

embuilder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emcc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emcmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emconfigure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emdump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emdwp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

emmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if [ -z "$PYTHON" ]; then
1616
fi
1717

1818
if [ -z "$PYTHON" ]; then
19-
PYTHON=$(which python3 2> /dev/null)
19+
PYTHON=$(command -v python3 2> /dev/null)
2020
fi
2121

2222
if [ -z "$PYTHON" ]; then
23-
PYTHON=$(which python 2> /dev/null)
23+
PYTHON=$(command -v python 2> /dev/null)
2424
fi
2525

2626
if [ -z "$PYTHON" ]; then

0 commit comments

Comments
 (0)