diff --git a/.travis.yml b/.travis.yml index 1986553bf1..03dd6f76e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ addons: - python3-pip install: - pip3 install --user --upgrade mypy flake8 + - travis_wait ./check-rustfmt.sh --install script: ./test-all.sh cache: cargo: true diff --git a/check-rustfmt.sh b/check-rustfmt.sh new file mode 100755 index 0000000000..c0c99c9a91 --- /dev/null +++ b/check-rustfmt.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Usage: check-rustfmt.sh [--install] +# +# Check that the desired version of rustfmt is installed. +# +# Rustfmt is still immature enough that its formatting decisions can change +# between versions. This makes it difficult to enforce a certain style in a +# test script since not all developers will upgrade rustfmt at the same time. +# To work around this, we only verify formatting when a specific version of +# rustfmt is installed. +# +# Exits 0 if the right version of rustfmt is installed, 1 otherwise. +# +# With the --install option, also tries to install the right version. + +# This version should always be bumped to the newest version available. +VERS="0.8.3" + +if cargo install --list | grep -q "^rustfmt v$VERS"; then + exit 0 +fi + +if [ "$1" != "--install" ]; then + echo "********************************************************************" + echo "* Please install rustfmt v$VERS to verify formatting. *" + echo "* If a newer version of rustfmt is available, update this script. *" + echo "********************************************************************" + echo "$0 --install" + sleep 1 + exit 1 +fi + +echo "Installing rustfmt v$VERS." +cargo install --force --vers="$VERS" rustfmt diff --git a/cranelift/test-all.sh b/cranelift/test-all.sh index d387cae46d..07d6fa2bdd 100755 --- a/cranelift/test-all.sh +++ b/cranelift/test-all.sh @@ -22,28 +22,9 @@ function banner() { } # Run rustfmt if we have it. -# -# Rustfmt is still immature enough that its formatting decisions can change -# between versions. This makes it difficult to enforce a certain style in a -# test script since not all developers will upgrade rustfmt at the same time. -# To work around this, we only verify formatting when a specific version of -# rustfmt is installed. -# -# This version should always be bumped to the newest version available. -RUSTFMT_VERSION="0.8.3" - -if cargo install --list | grep -q "^rustfmt v$RUSTFMT_VERSION"; then +if $topdir/check-rustfmt.sh; then banner "Rust formatting" $topdir/format-all.sh --write-mode=diff -elif [ -n "$TRAVIS" ]; then - # We're running under Travis CI. - # Install rustfmt, it will be cached for the next build. - echo "Installing rustfmt v$RUSTFMT_VERSION." - cargo install --force --vers="$RUSTFMT_VERSION" rustfmt - $topdir/format-all.sh --write-mode=diff -else - echo "Please install rustfmt v$RUSTFMT_VERSION to verify formatting." - echo "If a newer version of rustfmt is available, update this script." fi # Check if any Python files have changed since we last checked them.