[scripts] Update installation of dev tools

pull/36/head
Florian Dehau 7 years ago
parent c3c5109c5a
commit d2a4048e12

@ -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 =======================================

@ -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

@ -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

@ -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
Loading…
Cancel
Save