diff --git a/pants b/pants index 3ae6f76..367830f 100755 --- a/pants +++ b/pants @@ -12,6 +12,10 @@ set -eou pipefail +# an arbitrary number: bump when there's a change that someone might want to query for +# (e.g. checking $(PANTS_BOOTSTRAP_TOOLS=1 ./pants version) >= ...) +SCRIPT_VERSION=1 + # Source any custom bootstrap settings for Pants from PANTS_BOOTSTRAP if it exists. : ${PANTS_BOOTSTRAP:=".pants.bootstrap"} if [[ -f "${PANTS_BOOTSTRAP}" ]]; then @@ -64,6 +68,8 @@ COLOR_GREEN="\x1b[32m" COLOR_YELLOW="\x1b[33m" COLOR_RESET="\x1b[0m" +INSTALL_URL="https://www.pantsbuild.org/docs/installation" + function log() { echo -e "$@" 1>&2 } @@ -140,7 +146,7 @@ function determine_pants_version { if [[ -z "${pants_version}" ]]; then die "Please explicitly specify the \`pants_version\` in your \`pants.toml\` under the \`[GLOBAL]\` scope. See https://pypi.org/project/pantsbuild.pants/#history for all released versions -and https://www.pantsbuild.org/docs/installation for more instructions." +and ${INSTALL_URL} for more instructions." fi pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)" pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)" @@ -387,6 +393,76 @@ function bootstrap_pants { echo "${bootstrapped}" } +function run_bootstrap_tools { + # functionality for introspecting the bootstrapping process, without actually doing it + if [[ "${PANTS_BOOTSTRAP_TOOLS}" -gt "${SCRIPT_VERSION}" ]]; then + die "$0 script (bootstrap version ${SCRIPT_VERSION}) is too old for this invocation (with PANTS_BOOTSTRAP_TOOLS=${PANTS_BOOTSTRAP_TOOLS}). +Please update it by following ${INSTALL_URL}" + fi + + case "${1:-}" in + bootstrap-cache-key) + local pants_version=$(determine_pants_version) + local python="$(determine_python_exe "${pants_version}")" + # the python above may be a shim (e.g. pyenv or homebrew), so let's get an estimate of the + # actual path, as will be symlinked in the virtualenv. (NB. virtualenv does more complicated + # things, but we at least emulate the symlink-resolution that it does.) + local python_executable_path="$("${python}" -c 'import os, sys; print(os.path.realpath(sys.executable))')" + + local requirements_file="$(mktemp)" + echo "${VIRTUALENV_REQUIREMENTS}" > "${requirements_file}" + local virtualenv_requirements_sha256="$(compute_sha256 "${python}" "${requirements_file}")" + rm "${requirements_file}" + + local parts=( + "os_name=$(uname -s)" + "arch=$(uname -m)" + "python_path=${python}" + "python_executable_path=${python_executable_path}" + # the full interpreter information, for maximum compatibility + "python_version=$("$python" --version)" + "pex_version=${_PEX_VERSION}" + "virtualenv_requirements_sha256=${virtualenv_requirements_sha256}" + "pants_version=${pants_version}" + ) + echo "${parts[*]}" + ;; + bootstrap-version) + echo "${SCRIPT_VERSION}" + ;; + help|"") + cat <