diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-03-30 13:30:51 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-03-30 13:30:51 +0200 |
| commit | ca42f55539c9cc1ec7c6e1366e69acccbdb19513 (patch) | |
| tree | 6b95879cbbdfad3aa6093eea4ac462e3e803d77a | |
| parent | 4a539058f82f23f39cb758ca05226b145a2a2e17 (diff) | |
| download | mullvadvpn-ca42f55539c9cc1ec7c6e1366e69acccbdb19513.tar.xz mullvadvpn-ca42f55539c9cc1ec7c6e1366e69acccbdb19513.zip | |
Add format.sh script and reconfigure Travis
| -rw-r--r-- | .travis.yml | 6 | ||||
| -rwxr-xr-x | format.sh | 32 |
2 files changed, 34 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml index f78ed83ec7..6181134077 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,17 +12,15 @@ os: - osx before_script: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir -p $HOME/.local/bin && ln -s /usr/local/bin/greadlink $HOME/.local/bin/readlink ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir -p $HOME/.local/bin && ln -s /usr/local/bin/greadlink $HOME/.local/bin/readlink ; fi - $(./build-deps/install-build-deps.sh $HOME/build-deps) - - (cargo install rustfmt || true) - export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH - - rustfmt --version - env script: - cargo build --verbose - cargo test --all --verbose - - find . -iname "*.rs" -not -path "*/target/*" -print0 | xargs -0 -n1 rustfmt --write-mode=diff + - ./format.sh --write-mode=diff before_cache: ## zmq-sys caches the location of `libzmq`, if that location ever changes e.g. diff --git a/format.sh b/format.sh new file mode 100755 index 0000000000..e88e352fee --- /dev/null +++ b/format.sh @@ -0,0 +1,32 @@ +#! /usr/bin/env bash + +# Will make sure you have rustfmt at the version in $VERSION, then format all the source code. +# Run with --only-format as the first argument to skip checking rustfmt version. + +VERSION="0.7.1" +CMD="rustfmt" +INSTALL_CMD="cargo install --vers $VERSION --force $CMD" + +function correct_rustfmt() { + if ! which $CMD; then + echo "$CMD is not installed" >&2 + return 1 + fi + local installed_version=$($CMD --version | cut -d' ' -f1) + if [[ "$installed_version" != "$VERSION" ]]; then + echo "Wrong version of $CMD installed. Expected $VERSION, got $installed_version" >&2 + return 1 + fi + return 0 +} + +if [[ "$1" != "--only-format" ]]; then + if ! correct_rustfmt; then + echo "Installing $CMD $VERSION" + $INSTALL_CMD + fi +else + shift +fi + +find . -iname "*.rs" -not -path "*/target/*" -print0 | xargs -0 -n1 rustfmt "$@" |
