Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion pants
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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 <<EOF
Usage: PANTS_BOOTSTRAP_TOOLS=1 $0 ...

Subcommands:
bootstrap-cache-key
Print an opaque that can be used as a key for accurate and safe caching of
the pants bootstrap directories.

(Added in bootstrap version 1.)

bootstrap-version
Print a version number for the bootstrap script itself.

Distributed scripts (such as reusable CI formulae) that use these bootstrap
tools should set PANTS_BOOTSTRAP_TOOLS to the minimum script version for the
features they require. For example, if 'some-tool' was added in version 123:

PANTS_BOOTSTRAP_TOOLS=123 ./pants some-tool

(Added in bootstrap version 1.)
EOF
;;
*)
die "Unknown subcommand for bootstrap tools: $1. Do you mean to run without PANTS_BOOTSTRAP_TOOLS=1? Or, update this script ($INSTALL_URL)?"
esac
}

if [[ "${PANTS_BOOTSTRAP_TOOLS:-}" -gt 0 ]]; then
run_bootstrap_tools "$@"
exit 0
fi

# Ensure we operate from the context of the ./pants buildroot.
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
pants_version="$(determine_pants_version)"
Expand Down
2 changes: 1 addition & 1 deletion pants.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[GLOBAL]
pants_version = "2.13.0"
pants_version = "2.14.0"
backend_packages = [
"pants.backend.docker",
"pants.backend.docker.lint.hadolint",
Expand Down