]> git.lizzy.rs Git - rust.git/blob - rustup-toolchain
make tests pass again
[rust.git] / rustup-toolchain
1 #!/bin/bash
2 set -e
3 # Manages a rustup toolchain called "miri".
4 #
5 # All commands set "miri" as the override toolchain for the current directory,
6 # and make the `rust-version` file match that toolchain.
7 #
8 # USAGE:
9 #
10 # ./rustup-toolchain: Update "miri" toolchain to match `rust-version` (the known-good version for this commit).
11 #
12 # ./rustup-toolchain HEAD: Update "miri" toolchain and `rust-version` file to latest rustc HEAD.
13 #
14 # ./rustup-toolchain $COMMIT: Update "miri" toolchain and `rust-version` file to match that commit.
15 #
16 # Any extra parameters are passed to `rustup-toolchain-install-master`.
17
18 # Make sure rustup-toolchain-install-master is installed.
19 if ! which rustup-toolchain-install-master >/dev/null; then
20     echo "Please install rustup-toolchain-install-master by running 'cargo install rustup-toolchain-install-master'"
21     exit 1
22 fi
23
24 # Determine new commit.
25 if [[ "$1" == "" ]]; then
26     NEW_COMMIT=$(cat rust-version)
27 elif [[ "$1" == "HEAD" ]]; then
28     NEW_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
29 else
30     NEW_COMMIT="$1"
31 fi
32 echo "$NEW_COMMIT" > rust-version
33 shift || true # don't fail if shifting fails
34
35 # Check if we already are at that commit.
36 CUR_COMMIT=$(rustc +miri --version -v 2>/dev/null | egrep "^commit-hash: " | cut -d " " -f 2)
37 if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then
38     echo "miri toolchain is already at commit $CUR_COMMIT."
39     rustup override set miri
40     exit 0
41 fi
42
43 # Install and setup new toolchain.
44 rustup toolchain uninstall miri
45 rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy "$@" -- "$NEW_COMMIT"
46 rustup override set miri
47
48 # Cleanup.
49 cargo clean
50
51 # Call 'cargo metadata' on the sources in case that changes the lockfile
52 # (which fails under some setups when it is done from inside vscode).
53 cargo metadata --format-version 1 --manifest-path "$(rustc --print sysroot)/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" >/dev/null