forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pants
executable file
·117 lines (101 loc) · 4.1 KB
/
pants
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
# This bootstrap script runs pants from the live sources in this repo.
#
# Further support is added for projects wrapping pants with custom external extensions. In the
# future this will work differently (see: https://github.com/pantsbuild/pants/issues/5), but
# currently pants extenders can invoke this script exporting a few environment variables to include
# the extension source and requirements for development purposes:
# WRAPPER_SRCPATH This is a colon separated list of paths containing extension sourcecode.
# WRAPPER_REQUIREMENTS This is a colon separated list of pip install compatible requirements.txt
# files.
#
# For example, with a wrapping project layed out like so:
# /src/wrapper/
# src/main/python/
# wrapper/
# ...
# dependencies/python/
# BUILD
# requirements.txt
#
# And a pantsbuild/pants clone like so:
# /src/pantsbuild-pants
#
# You could invoke pants in the wrapper with its custom extension enabled using a script like so:
# /src/wrapper/pants
# ==
# #!/usr/bin/env bash
# WRAPPER_REQUIREMENTS="/src/wrapper/dependencies/python/requirements.txt" \
# WRAPPER_SRCPATH=/src/wrapper/src/main/python \
# exec /src/pantsbuild-pants/pants "$@"
#
# The script defaults to running with either Python 3.7 or Python 3.8. To use another Python version,
# prefix the script with `PY=python3.8`.
set -eo pipefail
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Set RUN_PANTS_FROM_PEX to non-empty to cause this wrapper script to delegate directly
# to ./pants.pex. We use this in CI to avoid bootstrapping in every shard.
if [[ -n "${RUN_PANTS_FROM_PEX}" ]]; then
exec "${HERE}/pants.pex" "$@"
fi
# Otherwise, run directly from sources, bootstrapping if needed.
# Exposes:
# + determine_python: Determine which interpreter version to use.
# shellcheck source=build-support/common.sh
source "${HERE}/build-support/common.sh"
PY="$(determine_python)"
export PY
# Exposes:
# + activate_pants_venv: Activate a virtualenv for pants requirements, creating it if needed.
# shellcheck source=build-support/pants_venv
source "${HERE}/build-support/pants_venv"
# Exposes:
# + bootstrap_native_code: Builds target-specific native engine binaries.
# shellcheck source=build-support/bin/rust/bootstrap_code.sh
source "${HERE}/build-support/bin/rust/bootstrap_code.sh"
PANTS_EXE="${HERE}/src/python/pants/bin/pants_loader.py"
if [[ -n "${WRAPPER_REQUIREMENTS}" ]]; then
# WONTFIX: fixing the array expansion is too difficult to be worth it. See https://github.com/koalaman/shellcheck/wiki/SC2207.
# shellcheck disable=SC2207
REQUIREMENTS=(
$(echo "${WRAPPER_REQUIREMENTS}" | tr : ' ')
"${REQUIREMENTS[@]}"
)
fi
PANTS_SRCPATH=(
"${HERE}/src/python"
)
if [[ -n "${WRAPPER_SRCPATH}" ]]; then
# WONTFIX: fixing the array expansion is too difficult to be worth it. See https://github.com/koalaman/shellcheck/wiki/SC2207.
# shellcheck disable=SC2207
PANTS_SRCPATH=(
$(echo "${WRAPPER_SRCPATH}" | tr : ' ')
"${PANTS_SRCPATH[@]}"
)
fi
PANTS_SRCPATH_STR="$(echo "${PANTS_SRCPATH[@]}" | tr ' ' :)"
function exec_pants_bare() {
# Redirect activation and native bootstrap to ensure that they don't interfere with stdout.
activate_pants_venv 1>&2
bootstrap_native_code 1>&2
# Because the venv has been activated, we simply say `python` and it will use the venv's version. We cannot use
# `${PY}` because it could use the wrong interpreter if the value is an absolute path.
PYTHONPATH="${PANTS_SRCPATH_STR}:${PYTHONPATH}" RUNNING_PANTS_FROM_SOURCES=1 \
exec python "${PANTS_EXE}" "$@"
}
if [[ -n "${WRAPPER_REQUIREMENTS}" ]]; then
log "*** Running pants with extra requirements: ${WRAPPER_REQUIREMENTS} ***"
fi
if [[ -n "${WRAPPER_SRCPATH}" ]]; then
log "*** Running pants with extra sources ${WRAPPER_SRCPATH} ***"
fi
if [[ -n "$PANTS_DEV" && "$PANTS_DEV" -eq 0 ]]; then
# Unexport PANTS_DEV if explicitly set to 0.
export -n PANTS_DEV
else
# We're running against a Pants clone.
export PANTS_DEV=1
fi
exec_pants_bare "$@"