1212
1313set -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" }
1721if [[ -f " ${PANTS_BOOTSTRAP} " ]]; then
4044
4145PANTS_BOOTSTRAP=" ${PANTS_SETUP_CACHE} /bootstrap-$( uname -s) -$( uname -m) "
4246
43- _PEX_VERSION=2.1.62
47+ _PEX_VERSION=2.1.103
4448_PEX_URL=" https://github.com/pantsbuild/pex/releases/download/v${_PEX_VERSION} /pex"
45- _PEX_EXPECTED_SHA256=" 56668b1ca147bd63141e586ffee97c7cc51ce8e6eac6c9b7a4bf1215b94396e5 "
49+ _PEX_EXPECTED_SHA256=" 4d45336511484100ae4e2bab24542a8b86b12c8cb89230463593c60d08c4b8d3 "
4650
4751VIRTUALENV_VERSION=20.4.7
4852VIRTUALENV_REQUIREMENTS=$(
@@ -64,6 +68,8 @@ COLOR_GREEN="\x1b[32m"
6468COLOR_YELLOW=" \x1b[33m"
6569COLOR_RESET=" \x1b[0m"
6670
71+ INSTALL_URL=" https://www.pantsbuild.org/docs/installation"
72+
6773function 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.
142148See 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) "
@@ -282,9 +288,13 @@ function bootstrap_pex {
282288function scrub_env_vars {
283289 # Ensure the virtualenv PEX runs as shrink-wrapped.
284290 # See: https://github.com/pantsbuild/setup/issues/105
285- if [[ -n " ${! PEX_@ } " ]]; then
286- warn " Scrubbing ${! PEX_@ } "
287- unset " ${! PEX_@ } "
291+ local -r pex_env_vars=(${! PEX_@ } )
292+ if [[ ! ${# pex_env_vars[@]} -eq 0 ]]; then
293+ local -r pex_env_vars_to_scrub=" ${pex_env_vars[@]/ PEX_ROOT} "
294+ if [[ -n " ${pex_env_vars_to_scrub[@]} " ]]; then
295+ warn " Scrubbing ${pex_env_vars_to_scrub[@]} "
296+ unset ${pex_env_vars_to_scrub[@]}
297+ fi
288298 fi
289299 # Also ensure pip doesn't think packages on PYTHONPATH
290300 # are already installed.
@@ -383,6 +393,76 @@ function bootstrap_pants {
383393 echo " ${bootstrapped} "
384394}
385395
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+
386466# Ensure we operate from the context of the ./pants buildroot.
387467cd " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd -P) "
388468pants_version=" $( determine_pants_version) "
0 commit comments