Skip to content

Commit

Permalink
Switch to command -v over which
Browse files Browse the repository at this point in the history
This fixes an issue on macOS where `which` failed to return any results
because the `PATH` wasn't propagated. `command` is more standard for
this use case as well https://github.com/koalaman/shellcheck/wiki/SC2230

Fixes bazelbuild#8414
  • Loading branch information
keith committed May 21, 2019
1 parent 1193e69 commit c242f25
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions tools/python/pywrapper_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@ die() {
exit 1
}

# Make sure PATH is exported. If we're called with PATH unset, as happens when
# we're invoked as a tool during the build, the shell will initialize its own
# PATH but not necessarily export it. This would break our call to `which`. See
# https://github.com/bazelbuild/continuous-integration/issues/578 for more
# information.
export PATH

# Try the "python%VERSION%" command name first, then fall back on "python".
PYTHON_BIN=`which python%VERSION% || echo ""`
PYTHON_BIN=`command -v python%VERSION% || echo ""`
USED_FALLBACK=0
if [ -z "${PYTHON_BIN:-}" ]; then
PYTHON_BIN=`which python || echo ""`
PYTHON_BIN=`command -v python || echo ""`
USED_FALLBACK=1
fi
if [ -z "${PYTHON_BIN:-}" ]; then
Expand Down

0 comments on commit c242f25

Please sign in to comment.