Skip to content

Commit

Permalink
Ensure correct toolchain per clone. (#6054)
Browse files Browse the repository at this point in the history
Previously, if the Rust toolchain was changed, re-bootstrapping would
proceed correctly in the first clone encountering the change but it
would fail in other clones. Ensure the correct toolchain is set when
building the symlink farm (but not needing to bootstrap the toolchain)
to cover this case.
  • Loading branch information
jsirois authored Jun 29, 2018
1 parent 1be2e92 commit 2870ed4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
16 changes: 8 additions & 8 deletions build-support/bin/native/bootstrap_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../.. && pwd -P)"
# + fingerprint_data: Fingerprints the data on stdin.
source "${REPO_ROOT}/build-support/common.sh"

readonly RUST_TOOLCHAIN="1.27.0"
RUST_TOOLCHAIN="$(cat ${REPO_ROOT}/rust-toolchain)"
readonly RUST_COMPONENTS=(
"rustfmt-preview"
"rust-src"
Expand All @@ -23,7 +23,7 @@ function cargo_bin() {
"${RUSTUP}" which cargo
}

function ensure_native_build_prerequisites() {
function bootstrap_rust() {
# Control a pants-specific rust toolchain.
if [[ ! -x "${RUSTUP}" ]]
then
Expand All @@ -32,7 +32,7 @@ function ensure_native_build_prerequisites() {
local -r rustup_tmp=$(mktemp -t pants.rustup.XXXXXX)
curl https://sh.rustup.rs -sSf > ${rustup_tmp}
# NB: rustup installs itself into CARGO_HOME, but fetches toolchains into RUSTUP_HOME.
sh ${rustup_tmp} -y --no-modify-path --default-toolchain "${RUST_TOOLCHAIN}" 1>&2
sh ${rustup_tmp} -y --no-modify-path --default-toolchain none 1>&2
rm -f ${rustup_tmp}
fi

Expand All @@ -41,11 +41,11 @@ function ensure_native_build_prerequisites() {
local -r cargo_versioned="cargo-${RUST_TOOLCHAIN}-${cargo_components_fp}"
if [[ ! -x "${rust_toolchain_root}/${cargo_versioned}" ]]
then
(
cd "${REPO_ROOT}"
"${RUSTUP}" override set "${RUST_TOOLCHAIN}" >&2
)
"${RUSTUP}" component add ${RUST_COMPONENTS[@]} >&2
# If rustup was already bootstrapped against a different toolchain in the past, freshen it and
# ensure the toolchain and components we need are installed.
"${RUSTUP}" self update
"${RUSTUP}" toolchain install ${RUST_TOOLCHAIN}
"${RUSTUP}" component add --toolchain ${RUST_TOOLCHAIN} ${RUST_COMPONENTS[@]} >&2

ln -fs "$(cargo_bin)" "${rust_toolchain_root}/${cargo_versioned}"
fi
Expand Down
5 changes: 2 additions & 3 deletions build-support/bin/native/cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ REPO_ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") && cd ../../.. && pwd -P)
# Exports:
# + CARGO_HOME: The CARGO_HOME of the Pants-controlled rust toolchain.
# Exposes:
# + ensure_native_build_prerequisites: Bootstraps a Pants-controlled rust toolchain and associated
# extras.
# + bootstrap_rust: Bootstraps a Pants-controlled rust toolchain and associated extras.
source "${REPO_ROOT}/build-support/bin/native/bootstrap_rust.sh"
ensure_native_build_prerequisites >&2
bootstrap_rust >&2

download_binary="${REPO_ROOT}/build-support/bin/download_binary.sh"

Expand Down
5 changes: 2 additions & 3 deletions build-support/bin/native/rust_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../.. && pwd -P)"
# Defines:
# + CARGO_HOME: The CARGO_HOME of the Pants-controlled rust toolchain.
# Exposes:
# + ensure_native_build_prerequisites: Bootstraps a Pants-controlled rust toolchain and associated
# extras.
# + bootstrap_rust: Bootstraps a Pants-controlled rust toolchain and associated extras.
source "${REPO_ROOT}/build-support/bin/native/bootstrap_rust.sh"

if [ ! -h $0 ]; then
Expand All @@ -20,5 +19,5 @@ EOF
fi
binary="$(basename "$0")"

ensure_native_build_prerequisites >&2
bootstrap_rust >&2
exec "${CARGO_HOME}/bin/${binary}" "$@"
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.27.0
12 changes: 9 additions & 3 deletions tests/python/pants_test/pants_run_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,15 @@ def mock_buildroot(self, dirs_to_copy=None):
# N.B. BUILD.tools, contrib, 3rdparty needs to be copied vs symlinked to avoid
# symlink prefix check error in v1 and v2 engine.
files_to_copy = ('BUILD.tools',)
files_to_link = ('pants', 'pants.ini', 'pants.travis-ci.ini', '.pants.d',
'build-support', 'pants-plugins', 'src')
dirs_to_copy = ('contrib', '3rdparty') + tuple(dirs_to_copy or [])
files_to_link = ('.pants.d',
'build-support',
'pants',
'pants-plugins',
'pants.ini',
'pants.travis-ci.ini',
'rust-toolchain',
'src')
dirs_to_copy = ('3rdparty', 'contrib') + tuple(dirs_to_copy or [])

with self.temporary_workdir() as tmp_dir:
for filename in files_to_copy:
Expand Down

0 comments on commit 2870ed4

Please sign in to comment.