Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 798eb83

Browse files
author
Thomas Wunderlich
committed
Update pants shell script to latest version
Signed-off-by: Thomas Wunderlich <[email protected]>
1 parent 7127e75 commit 798eb83

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

pants

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
set -eou pipefail
1414

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+
1519
# Source any custom bootstrap settings for Pants from PANTS_BOOTSTRAP if it exists.
1620
: ${PANTS_BOOTSTRAP:=".pants.bootstrap"}
1721
if [[ -f "${PANTS_BOOTSTRAP}" ]]; then
@@ -64,6 +68,8 @@ COLOR_GREEN="\x1b[32m"
6468
COLOR_YELLOW="\x1b[33m"
6569
COLOR_RESET="\x1b[0m"
6670

71+
INSTALL_URL="https://www.pantsbuild.org/docs/installation"
72+
6773
function log() {
6874
echo -e "$@" 1>&2
6975
}
@@ -140,7 +146,7 @@ function determine_pants_version {
140146
if [[ -z "${pants_version}" ]]; then
141147
die "Please explicitly specify the \`pants_version\` in your \`pants.toml\` under the \`[GLOBAL]\` scope.
142148
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."
144150
fi
145151
pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)"
146152
pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)"
@@ -387,6 +393,76 @@ function bootstrap_pants {
387393
echo "${bootstrapped}"
388394
}
389395

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+
390466
# Ensure we operate from the context of the ./pants buildroot.
391467
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
392468
pants_version="$(determine_pants_version)"

0 commit comments

Comments
 (0)