Skip to content

Commit 2b38837

Browse files
committed
fix(ensure_rustc_commit): resolve repo root before running rustc -vV
If this script is sourced from a working directory outside the repo tree, rustup won't find rust-toolchain.toml and may select whatever default toolchain happens to be active, giving us the wrong commit hash. We now derive the repo root from BASH_SOURCE (two levels up from the script's own directory) and cd there before invoking rustc, so the toolchain selection stays correct regardless of the caller's CWD.
1 parent 4067da0 commit 2b38837

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tests/ui/ensure_rustc_commit.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ set -u
1313

1414
# Derive the rustc commit from the active toolchain; rust-toolchain.toml
1515
# selects the nightly, so this stays in sync automatically.
16-
RUSTC_COMMIT=$(rustc -vV | grep 'commit-hash' | cut -d' ' -f2)
16+
# Run from the repo root so rustup picks up rust-toolchain.toml even when
17+
# the caller's CWD is outside the repository.
18+
_SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
19+
_REPO_ROOT=$(cd -- "$_SCRIPT_DIR/../.." &>/dev/null && pwd)
20+
RUSTC_COMMIT=$(cd "$_REPO_ROOT" && rustc -vV | grep 'commit-hash' | cut -d' ' -f2)
1721
if [ -z "$RUSTC_COMMIT" ]; then
1822
echo "Error: Could not determine rustc commit-hash from 'rustc -vV'"
1923
exit 1

0 commit comments

Comments
 (0)