#!/usr/bin/env bash # Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). # This bootstrap script runs pants from the live sources in this repo. # # The script defaults to running with either Python 3.7 or Python 3.8. To use another Python version, # prefix the script with `PY=python3.8`. set -eo pipefail HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # Source any custom bootstrap settings for Pants from PANTS_BOOTSTRAP if it exists. : "${PANTS_BOOTSTRAP:=.pants.bootstrap}" if [[ -f "${PANTS_BOOTSTRAP}" ]]; then # shellcheck source=/dev/null source "${PANTS_BOOTSTRAP}" fi # Exposes: # + determine_python: Determine which interpreter version to use. # shellcheck source=build-support/common.sh source "${HERE}/build-support/common.sh" PY="$(determine_python)" export PY # Exposes: # + activate_pants_venv: Activate a virtualenv for pants requirements, creating it if needed. # shellcheck source=build-support/pants_venv source "${HERE}/build-support/pants_venv" # Exposes: # + bootstrap_native_code: Builds target-specific native engine binaries. # shellcheck source=build-support/bin/rust/bootstrap_code.sh source "${HERE}/build-support/bin/rust/bootstrap_code.sh" function exec_pants_bare() { PANTS_PY_EXE="${HERE}/src/python/pants/bin/pants_loader.py" PANTS_SRCPATH="${HERE}/src/python" # Redirect activation and native bootstrap to ensure that they don't interfere with stdout. activate_pants_venv 1>&2 bootstrap_native_code 1>&2 if [ -n "${PANTS_DEBUG}" ]; then if [[ "$*" != *"--no-pantsd"* ]]; then echo "Error! Must pass '--no-pantsd' when using PANTS_DEBUG" exit 1 fi DEBUG_ARGS="-m debugpy --listen 127.0.0.1:5678 --wait-for-client" echo "Will launch debugpy server at '127.0.0.1:5678' waiting for client connection." fi if [ -z "${PANTS_NO_NATIVE_CLIENT}" ]; then set +e "${NATIVE_CLIENT_BINARY}" "$@" result=$? # N.B.: The native pants client currently relies on pantsd being up. If it's not, it will fail # with exit code 75 (EX_TEMPFAIL in /usr/include/sysexits.h) and we should fall through to the # python pants client which knows how to start up pantsd. This failure takes O(1ms); so has no # appreciable impact on --no-pantsd runs. # # TODO: Split out a `pants_server` or `pants_legacy_entrypoint` from this script, and then use # the native client's support for fallback to the legacy entrypoint to remove the special # exit code case. if ((result != 75)); then exit ${result} fi set -e fi # shellcheck disable=SC2086 PYTHONPATH="${PANTS_SRCPATH}:${PYTHONPATH}" RUNNING_PANTS_FROM_SOURCES=1 NO_SCIE_WARNING=1 \ exec ${PANTS_PREPEND_ARGS:-} "$(venv_dir)/bin/python" ${DEBUG_ARGS} "${PANTS_PY_EXE}" "$@" } exec_pants_bare "$@"