forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…antsbuild#8183) ## Changes to get `--chroot` working As prework to running integration tests with `--chroot` and then [remoting](pantsbuild#8113), we first must make two major changes to how we handle integration tests: 1) Having integration tests depend on `//:build_root`. This ensures that `get_buildroot()` properly resolves to the chrooted folder in `.pants.d`, rather than traversing all the way up to the original build root. 2) Using `./pants.pex` rather than `./pants` in integration tests. Because V1 strips the prefix of source roots, whereby `src/python/pants` becomes `pants`, we cannot also have a file named `pants` in the same build root. Instead, we can safely depend on `./pants.pex`. ## Autogeneration of `pants.pex` Now that we depend on `pants.pex`, it is very easy for this file to fall out-of-date and to unintentionally be testing old code. We work around this via the design in pantsbuild#8209. First, we start caching built PEXes in `~/.cache/pants`, with the ID derived from all the source files used for Pants. This allows us to quickly switch between branches without having to regenerate the PEX every time. Then, we teach `./pants` to run `bootstrap_pants_pex.sh` whenever `test` is one of the goals and it's not CI. This will ensure that the file is always up-to-date.
- Loading branch information
1 parent
21d0011
commit 684e043
Showing
12 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ out/ | |
/logs/ | ||
arc.sh | ||
BUILD.release* | ||
/pants.pex | ||
pants.ini.sitegen | ||
target | ||
GPATH | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../.. && pwd -P)" | ||
|
||
# This script is used to generate pants.pex and particularly to allow us to maintain multiple versions, | ||
# each mapped to a particular snapshot of the source code. The different versions are maintained in | ||
# the CACHE_ROOT, with the current one symlinked into the build root. This allows us to quickly | ||
# change the specific pants.pex being used. This mechanism is similar to bootstrap_code.sh. | ||
|
||
export PY="${PY:-python3}" | ||
|
||
# shellcheck source=build-support/common.sh | ||
source "${REPO_ROOT}/build-support/common.sh" | ||
# shellcheck source=build-support/pants_venv | ||
source "${REPO_ROOT}/build-support/pants_venv" | ||
# shellcheck source=build-support/bin/native/bootstrap_code.sh | ||
source "${REPO_ROOT}/build-support/bin/native/bootstrap_code.sh" | ||
|
||
readonly PANTS_PEX_CACHE_DIR="${CACHE_ROOT}/bin/pants-pex" | ||
|
||
function bootstrap_pants_pex() { | ||
local pants_pex_version | ||
pants_pex_version="$(calculate_pants_pex_current_hash)" | ||
local target_binary="${PANTS_PEX_CACHE_DIR}/pants.${pants_pex_version}.pex" | ||
|
||
if [[ ! -f "${target_binary}" ]]; then | ||
log "pants.pex is outdated or does not yet exist. Bootstrapping..." | ||
./pants --quiet binary src/python/pants/bin:pants_local_binary || exit 1 | ||
|
||
mkdir -p "$(dirname "${target_binary}")" | ||
cp dist/pants_local_binary.pex "${target_binary}" | ||
fi | ||
|
||
# Ensure that `pants.pex` uses the correct version. | ||
# NB: the V2 engine does not work if this is a symlink, so we must physically copy the file. | ||
cp "${target_binary}" pants.pex | ||
} | ||
|
||
function calculate_pants_pex_current_hash() { | ||
# NB: These folder names were found by getting all the dependencies for `pants.pex` by running | ||
# `./pants dependencies --transitive src/python/pants/bin:pants_local_binary | sort`. | ||
( | ||
cd "${REPO_ROOT}" || exit 1 | ||
(uname | ||
python --version 2>&1 | ||
git ls-files --cached --others --exclude-standard \ | ||
"${REPO_ROOT}/3rdparty/python" \ | ||
"${REPO_ROOT}/contrib/python/src/python/pants/contrib/python/checks" \ | ||
"${REPO_ROOT}/src/python" \ | ||
"${REPO_ROOT}/pants-plugins" \ | ||
| git hash-object --stdin-paths) | fingerprint_data | ||
) | ||
} | ||
|
||
# Redirect to ensure that we don't interfere with stdout. | ||
activate_pants_venv 1>&2 | ||
bootstrap_native_code 1>&2 | ||
bootstrap_pants_pex 1>&2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters