Chih-Hung Hsieh | 127364b | 2020-10-26 16:54:29 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Check all public crates with minimal version dependencies. |
| 4 | # |
| 5 | # Usage: |
| 6 | # bash scripts/check-minimal-versions.sh |
| 7 | # |
| 8 | # Note: |
| 9 | # - This script modifies Cargo.toml and Cargo.lock while running |
| 10 | # - This script exits with 1 if there are any unstaged changes |
| 11 | # - This script requires nightly Rust and cargo-hack |
| 12 | # |
| 13 | # Refs: https://github.com/rust-lang/cargo/issues/5657 |
| 14 | |
| 15 | set -euo pipefail |
| 16 | |
| 17 | cd "$(cd "$(dirname "${0}")" && pwd)"/.. |
| 18 | |
| 19 | if [[ "${1:-none}" == "+"* ]]; then |
| 20 | toolchain="${1}" |
| 21 | elif [[ "${CI:-false}" != "true" ]]; then |
| 22 | cargo +nightly -V >/dev/null || exit 1 |
| 23 | toolchain="+nightly" |
| 24 | fi |
| 25 | |
| 26 | if [[ "${toolchain:-+nightly}" != "+nightly"* ]] || ! cargo hack -V &>/dev/null; then |
| 27 | echo "error: check-minimal-versions.sh requires nightly Rust and cargo-hack" |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | # This script modifies Cargo.toml and Cargo.lock, so make sure there are no |
| 32 | # unstaged changes. |
| 33 | git diff --exit-code |
| 34 | # Restore original Cargo.toml and Cargo.lock on exit. |
| 35 | trap 'git checkout .' EXIT |
| 36 | |
| 37 | # Remove dev-dependencies from Cargo.toml to prevent the next `cargo update` |
| 38 | # from determining minimal versions based on dev-dependencies. |
| 39 | cargo hack --remove-dev-deps --workspace |
| 40 | |
| 41 | # Update Cargo.lock to minimal version dependencies. |
| 42 | cargo ${toolchain:-} update -Zminimal-versions |
| 43 | # Run check for all public members of the workspace. |
| 44 | cargo ${toolchain:-} hack check --workspace --all-features --ignore-private -Zfeatures=all |