From d2a4048e122b3d8e7bf45a131a01be9e4a1a676d Mon Sep 17 00:00:00 2001 From: Florian Dehau Date: Tue, 26 Dec 2017 18:45:24 +0100 Subject: [PATCH] [scripts] Update installation of dev tools --- Makefile | 16 +++++++--- scripts/tools/clippy.sh | 22 -------------- scripts/tools/install.sh | 65 ++++++++++++++++++++++++++++++++++++++++ scripts/tools/rustfmt.sh | 22 -------------- 4 files changed, 77 insertions(+), 48 deletions(-) delete mode 100755 scripts/tools/clippy.sh create mode 100755 scripts/tools/install.sh delete mode 100755 scripts/tools/rustfmt.sh diff --git a/Makefile b/Makefile index ae7bec16..aa8eae18 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ RUSTUP_INSTALLED = $(shell command -v rustup 2> /dev/null) ifndef RUSTUP_INSTALLED CARGO = cargo else - ifdef NO_RUSTUP + ifdef CI CARGO = cargo else CARGO = rustup run $(RUST_CHANNEL) cargo @@ -32,11 +32,19 @@ help: ## Print all the available commands install-tools: install-rustfmt install-clippy ## Install tools dependencies +INSTALL_RUSTFMT = ./scripts/tools/install.sh --name=rustfmt-nightly +ifndef CI + INSTALL_RUSTFMT += --channel=nightly +endif install-rustfmt: ## Intall rustfmt - ./scripts/tools/rustfmt.sh + $(INSTALL_RUSTFMT) -install-clippy: ## Install clippy - ./scripts/tools/clippy.sh +INSTALL_CLIPPY = ./scripts/tools/install.sh --name=clippy +ifndef CI + INSTALL_CLIPPY += --channel=nightly +endif +install-clippy: ## Intall rustfmt + $(INSTALL_CLIPPY) # =============================== Build ======================================= diff --git a/scripts/tools/clippy.sh b/scripts/tools/clippy.sh deleted file mode 100755 index 71b4bbfe..00000000 --- a/scripts/tools/clippy.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -set -eu -o pipefail - -crate_name="clippy" -has_clippy=$(cargo +nightly install --list | { grep $crate_name || true; }) - -if [ -z "$has_clippy" ]; then - echo "WARN: $crate_name not found." - echo "INFO: Installing latest version from crates.io." - cargo +nightly install $crate_name -else - current_version=$(cargo +nightly clippy --version | cut -d '-' -f 1) - upstream_version=$(cargo +nightly search $crate_name | head -n 1 | cut -d ' ' -f 3 | tr -d '"') - if [ "$current_version" != "$upstream_version" ]; then - echo "WARN: New version of $crate_name available: $upstream_version (current=$current_version)" - echo "INFO: Installing latest version from crates.io." - cargo +nightly install $crate_name --force - else - echo "INFO: $crate_name is up to date" - fi -fi diff --git a/scripts/tools/install.sh b/scripts/tools/install.sh new file mode 100755 index 00000000..3f02a146 --- /dev/null +++ b/scripts/tools/install.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +set -e -o pipefail + +USAGE="$0 --name=STRING [--channel=STRING]" + +# Default values +CARGO="cargo" +NAME="" +CHANNEL="" + +# Parse args +for i in "$@"; do + case $i in + --name=*) + NAME="${i#*=}" + shift + ;; + --channel=*) + CHANNEL="${i#*=}" + shift + ;; + *) + echo $USAGE + exit 1 + ;; + esac +done + +current_version() { + local crate="$1" + $CARGO install --list | \ + grep $crate | \ + head -n 1 | \ + cut -d ' ' -f 2 | \ + sed 's/v\(.*\):/\1/g' +} + +upstream_version() { + local crate="$1" + $CARGO search $crate | \ + grep $crate | \ + head -n 1 | \ + cut -d' ' -f 3 | \ + sed 's/"//g' +} + +if [ "$NAME" == "" ]; then + echo $USAGE + exit 1 +fi + +if [ "$CHANNEL" != "" ]; then + CARGO+=" +$CHANNEL" +fi + +CURRENT_VERSION="$(current_version $NAME)" +UPSTREAM_VERSION="$(upstream_version $NAME)" + +if [ "$CURRENT_VERSION" != "$UPSTREAM_VERSION" ]; then + echo "WARN: Latest version of $NAME not installed: $CURRENT_VERSION -> $UPSTREAM_VERSION" + $CARGO install --force $NAME +else + echo "INFO: Latest version of $NAME already installed ($CURRENT_VERSION)" +fi diff --git a/scripts/tools/rustfmt.sh b/scripts/tools/rustfmt.sh deleted file mode 100755 index 4b79bc12..00000000 --- a/scripts/tools/rustfmt.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -set -eu -o pipefail - -crate_name="rustfmt-nightly" -has_rustfmt=$(cargo +nightly install --list | { grep $crate_name || true; }) - -if [ -z "$has_rustfmt" ]; then - echo "WARN: $crate_name not found." - echo "INFO: Installing latest version from crates.io." - cargo +nightly install $crate_name -else - current_version=$(rustfmt --version | cut -d '-' -f 1) - upstream_version=$(cargo +nightly search $crate_name| head -n 1 | cut -d ' ' -f 3 | tr -d '"') - if [ "$current_version" != "$upstream_version" ]; then - echo "WARN: New version of $crate_name available: $upstream_version (current=$current_version)" - echo "INFO: Installing latest version from crates.io." - cargo +nightly install $crate_name --force - else - echo "INFO: $crate_name is up to date" - fi -fi