|
12 | 12 |
|
13 | 13 | set -eou pipefail
|
14 | 14 |
|
| 15 | +# an arbitrary number: bump when there's a change that someone might want to query for |
| 16 | +# (e.g. checking $(PANTS_BOOTSTRAP_TOOLS=1 ./pants version) >= ...) |
| 17 | +SCRIPT_VERSION=1 |
| 18 | + |
15 | 19 | # Source any custom bootstrap settings for Pants from PANTS_BOOTSTRAP if it exists.
|
16 | 20 | : ${PANTS_BOOTSTRAP:=".pants.bootstrap"}
|
17 | 21 | if [[ -f "${PANTS_BOOTSTRAP}" ]]; then
|
@@ -64,6 +68,8 @@ COLOR_GREEN="\x1b[32m"
|
64 | 68 | COLOR_YELLOW="\x1b[33m"
|
65 | 69 | COLOR_RESET="\x1b[0m"
|
66 | 70 |
|
| 71 | +INSTALL_URL="https://www.pantsbuild.org/docs/installation" |
| 72 | + |
67 | 73 | function log() {
|
68 | 74 | echo -e "$@" 1>&2
|
69 | 75 | }
|
@@ -140,7 +146,7 @@ function determine_pants_version {
|
140 | 146 | if [[ -z "${pants_version}" ]]; then
|
141 | 147 | die "Please explicitly specify the \`pants_version\` in your \`pants.toml\` under the \`[GLOBAL]\` scope.
|
142 | 148 | See https://pypi.org/project/pantsbuild.pants/#history for all released versions
|
143 |
| -and https://www.pantsbuild.org/docs/installation for more instructions." |
| 149 | +and ${INSTALL_URL} for more instructions." |
144 | 150 | fi
|
145 | 151 | pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)"
|
146 | 152 | pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)"
|
@@ -387,6 +393,76 @@ function bootstrap_pants {
|
387 | 393 | echo "${bootstrapped}"
|
388 | 394 | }
|
389 | 395 |
|
| 396 | +function run_bootstrap_tools { |
| 397 | + # functionality for introspecting the bootstrapping process, without actually doing it |
| 398 | + if [[ "${PANTS_BOOTSTRAP_TOOLS}" -gt "${SCRIPT_VERSION}" ]]; then |
| 399 | + die "$0 script (bootstrap version ${SCRIPT_VERSION}) is too old for this invocation (with PANTS_BOOTSTRAP_TOOLS=${PANTS_BOOTSTRAP_TOOLS}). |
| 400 | +Please update it by following ${INSTALL_URL}" |
| 401 | + fi |
| 402 | + |
| 403 | + case "${1:-}" in |
| 404 | + bootstrap-cache-key) |
| 405 | + local pants_version=$(determine_pants_version) |
| 406 | + local python="$(determine_python_exe "${pants_version}")" |
| 407 | + # the python above may be a shim (e.g. pyenv or homebrew), so let's get an estimate of the |
| 408 | + # actual path, as will be symlinked in the virtualenv. (NB. virtualenv does more complicated |
| 409 | + # things, but we at least emulate the symlink-resolution that it does.) |
| 410 | + local python_executable_path="$("${python}" -c 'import os, sys; print(os.path.realpath(sys.executable))')" |
| 411 | + |
| 412 | + local requirements_file="$(mktemp)" |
| 413 | + echo "${VIRTUALENV_REQUIREMENTS}" > "${requirements_file}" |
| 414 | + local virtualenv_requirements_sha256="$(compute_sha256 "${python}" "${requirements_file}")" |
| 415 | + rm "${requirements_file}" |
| 416 | + |
| 417 | + local parts=( |
| 418 | + "os_name=$(uname -s)" |
| 419 | + "arch=$(uname -m)" |
| 420 | + "python_path=${python}" |
| 421 | + "python_executable_path=${python_executable_path}" |
| 422 | + # the full interpreter information, for maximum compatibility |
| 423 | + "python_version=$("$python" --version)" |
| 424 | + "pex_version=${_PEX_VERSION}" |
| 425 | + "virtualenv_requirements_sha256=${virtualenv_requirements_sha256}" |
| 426 | + "pants_version=${pants_version}" |
| 427 | + ) |
| 428 | + echo "${parts[*]}" |
| 429 | + ;; |
| 430 | + bootstrap-version) |
| 431 | + echo "${SCRIPT_VERSION}" |
| 432 | + ;; |
| 433 | + help|"") |
| 434 | + cat <<EOF |
| 435 | +Usage: PANTS_BOOTSTRAP_TOOLS=1 $0 ... |
| 436 | +
|
| 437 | +Subcommands: |
| 438 | + bootstrap-cache-key |
| 439 | + Print an opaque that can be used as a key for accurate and safe caching of |
| 440 | + the pants bootstrap directories. |
| 441 | +
|
| 442 | + (Added in bootstrap version 1.) |
| 443 | +
|
| 444 | + bootstrap-version |
| 445 | + Print a version number for the bootstrap script itself. |
| 446 | +
|
| 447 | + Distributed scripts (such as reusable CI formulae) that use these bootstrap |
| 448 | + tools should set PANTS_BOOTSTRAP_TOOLS to the minimum script version for the |
| 449 | + features they require. For example, if 'some-tool' was added in version 123: |
| 450 | +
|
| 451 | + PANTS_BOOTSTRAP_TOOLS=123 ./pants some-tool |
| 452 | +
|
| 453 | + (Added in bootstrap version 1.) |
| 454 | +EOF |
| 455 | + ;; |
| 456 | + *) |
| 457 | + die "Unknown subcommand for bootstrap tools: $1. Do you mean to run without PANTS_BOOTSTRAP_TOOLS=1? Or, update this script ($INSTALL_URL)?" |
| 458 | + esac |
| 459 | +} |
| 460 | + |
| 461 | +if [[ "${PANTS_BOOTSTRAP_TOOLS:-}" -gt 0 ]]; then |
| 462 | + run_bootstrap_tools "$@" |
| 463 | + exit 0 |
| 464 | +fi |
| 465 | + |
390 | 466 | # Ensure we operate from the context of the ./pants buildroot.
|
391 | 467 | cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
392 | 468 | pants_version="$(determine_pants_version)"
|
|
0 commit comments