]> git.lizzy.rs Git - rust.git/blobdiff - setup-toolchain.sh
Update Clippy for MethodCall changes
[rust.git] / setup-toolchain.sh
index 012d26a1046b39f7db5ae5acc71c9c7a55d7e4a1..191ea4315a6b5a8a29e56f6440f88115c466e8b9 100755 (executable)
@@ -1,14 +1,36 @@
-#!/bin/bash
+#!/usr/bin/env bash
 # Set up the appropriate rustc toolchain
 
-cd "$(dirname "$0")" || exit
+set -e
 
-if ! command -v rustup-toolchain-install-master > /dev/null; then
-  cargo install \
-    --git https://github.com/kennytm/rustup-toolchain-install-master \
-    --bin rustup-toolchain-install-master \
-    --debug
+cd "$(dirname "$0")"
+
+RTIM_PATH=$(command -v rustup-toolchain-install-master) || INSTALLED=false
+CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}
+
+# Check if RTIM is not installed or installed in other locations not in ~/.cargo/bin
+if [[ "$INSTALLED" == false || "$RTIM_PATH" == $CARGO_HOME/bin/rustup-toolchain-install-master ]]; then
+    cargo +nightly install rustup-toolchain-install-master
+else
+    VERSION=$(rustup-toolchain-install-master -V | grep -o "[0-9.]*")
+    REMOTE=$(cargo +nightly search rustup-toolchain-install-master | grep -o "[0-9.]*")
+    echo "info: skipping updating rustup-toolchain-install-master at $RTIM_PATH"
+    echo "      current version : $VERSION"
+    echo "      remote version  : $REMOTE"
+fi
+
+RUST_COMMIT=$(git ls-remote https://github.com/rust-lang/rust master | awk '{print $1}')
+
+if rustc +master -Vv 2>/dev/null | grep -q "$RUST_COMMIT"; then
+    echo "info: master toolchain is up-to-date"
+    exit 0
+fi
+
+if [[ -n "$HOST_TOOLCHAIN" ]]; then
+    TOOLCHAIN=('--host' "$HOST_TOOLCHAIN")
+else
+    TOOLCHAIN=()
 fi
 
-rustup-toolchain-install-master -f -n master -c rustc-dev
+rustup-toolchain-install-master -f -n master "${TOOLCHAIN[@]}" -c rustc-dev -c llvm-tools -- "$RUST_COMMIT"
 rustup override set master