forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpants
executable file
·130 lines (117 loc) · 4.25 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
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/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 in 2 modes controlled by environment variables.
#
# With no special environment variables exported, the script will create a pants.pex from local
# sources if there is none at the root of the repo and then run that.
#
# If PANTS_DEV is exported then this script will instead run pants from the live sources in this
# repo.
#
# If PANTS_PROFILE=results.pstats is exported, then this script will run pants with python profiling
# enabled. It will create a pstats file named with the value of PANTS_PROFILE that you can analyze.
#
# 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 "$@"
#
HERE=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
source ${HERE}/build-support/pants_venv
PANTS_EXE="${HERE}/src/python/pants/bin/pants_exe.py"
if [ ! -z "${PANTS_PROFILE}" ]; then
PANTS_EXE=" -m cProfile -o ${PANTS_PROFILE} ${PANTS_EXE}"
# PEX_PROFILE requires a path that is directory-ish, otherwise it blows up with a strange error
if [[ $PANTS_PROFILE != *"/"* ]]; then
PANTS_PROFILE="./${PANTS_PROFILE}"
fi
export PEX_PROFILE=${PANTS_PROFILE}
fi
PANTS_BINARY=src/python/pants/bin:pants_local_binary
PANTS_PEX="${HERE}/pants.pex"
FAILED_BOOTSTRAP_SENTINEL="${HERE}/.pants.d/BOOTSTRAP_FAILED"
PY=${PY:-$(which python2.7)}
if [[ ! -z "${WRAPPER_REQUIREMENTS}" ]]; then
PANTS_DEV=1
REQUIREMENTS=(
$(echo ${WRAPPER_REQUIREMENTS} | tr : ' ')
${REQUIREMENTS[@]}
)
fi
PANTS_SRCPATH=(
${HERE}/src/python
)
if [[ ! -z "${WRAPPER_SRCPATH}" ]]; then
PANTS_DEV=1
PANTS_SRCPATH=(
$(echo ${WRAPPER_SRCPATH} | tr : ' ')
${PANTS_SRCPATH[@]}
)
fi
PANTS_SRCPATH="$(echo ${PANTS_SRCPATH[@]} | tr ' ' :)"
function run_pants_bare() {
activate_pants_venv
PYTHONPATH="${PANTS_SRCPATH}:${PYTHONPATH}" python ${PANTS_EXE} "$@"
}
function exec_pants_bare() {
activate_pants_venv
PYTHONPATH="${PANTS_SRCPATH}:${PYTHONPATH}" exec python ${PANTS_EXE} "$@"
}
if [ ! -z "${PANTS_DEV}" ]; then
log "*** Running pants in dev mode from ${PANTS_EXE} ***"
if [[ ! -z "${WRAPPER_REQUIREMENTS}" ]]; then
log "*** with extra requirements: ${WRAPPER_REQUIREMENTS} ***"
fi
if [[ ! -z "${WRAPPER_SRCPATH}" ]]; then
log "*** with extra sources ${WRAPPER_SRCPATH} ***"
fi
exec_pants_bare "$@"
else
if [ ! -e "${PANTS_PEX}" ]; then
if [ -f ${FAILED_BOOTSTRAP_SENTINEL} ] ; then
log "Last bootstrap failed, cleaning up .pants.d"
rm -rf ${HERE}/.pants.d
fi
log "Building pants.pex to ${PANTS_PEX}..."
# TODO(John sirois): Re-plumb build such that it grabs constraints from the built python_binary
# target(s).
rm -rf ${PANTS_PEX} && \
run_pants_bare binary ${PANTS_BINARY} && \
mv -v ${HERE}/dist/pants_local_binary.pex ${PANTS_PEX} && \
chmod +x ${PANTS_PEX}
exit_status=$?
if [ $exit_status != 0 ] ; then
echo "*** Pants bootstrapping failed."
echo "This file is left as a sentinel to record that bootstrapping pants failed." \
> ${FAILED_BOOTSTRAP_SENTINEL}
exit $exit_status
fi
fi
if [ -e "${PANTS_PEX}" ]; then
exec "${PANTS_PEX}" "$@"
fi
fi