| # TODO(#7843): integration tests for failure to find python / wrong version |
| # found / error while trying to print version |
| GENERAL_FAILURE_MESSAGE="Error: The default python toolchain \ |
| (@bazel_tools//tools/python:autodetecting_toolchain) was unable to locate a \ |
| suitable Python interpreter on the target platform at execution time. Please \ |
| register an appropriate Python toolchain. See the documentation for \ |
| https://github.com/bazelbuild/bazel/blob/master/tools/python/toolchain.bzl." |
| # Try the "python%VERSION%" command name first, then fall back on "python". |
| PYTHON_BIN=$(which python%VERSION% || echo "") |
| if [[ -z "${PYTHON_BIN:-}" ]]; then |
| PYTHON_BIN=$(which python || echo "") |
| if [[ -z "${PYTHON_BIN:-}" ]]; then |
| echo "$GENERAL_FAILURE_MESSAGE" |
| echo "Failure reason: Cannot locate 'python%VERSION%' or 'python' on the \ |
| target platform's PATH, which is: |
| # Verify that we grabbed an interpreter with the right version. |
| VERSION_STR=$("$PYTHON_BIN" -V 2>&1) |
| if ! grep -q " %VERSION%\." <<< $VERSION_STR; then |
| echo "$GENERAL_FAILURE_MESSAGE" |
| echo "Failure reason: According to '$PYTHON_BIN -V', version is \ |
| '$VERSION_STR', but we need version %VERSION%" |