-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcheck-minimal-versions.sh
executable file
·58 lines (50 loc) · 1.77 KB
/
check-minimal-versions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Check all public crates with minimal version dependencies.
#
# Usage:
# bash scripts/check-minimal-versions.sh [+toolchain] [check|test]
#
# Note:
# - This script modifies Cargo.toml and Cargo.lock while running
# - This script exits with 1 if there are any unstaged changes
# - This script requires nightly Rust and cargo-hack
#
# Refs: https://github.com/rust-lang/cargo/issues/5657
set -euo pipefail
IFS=$'\n\t'
cd "$(cd "$(dirname "${0}")" && pwd)"/..
# Decide Rust toolchain.
# Nightly is used by default if the `CI` environment variable is unset.
if [[ "${1:-}" == "+"* ]]; then
toolchain="${1}"
shift
elif [[ -z "${CI:-}" ]]; then
toolchain="+nightly"
fi
# Make sure toolchain is installed.
cargo ${toolchain:-} -V >/dev/null
# This script requires nightly Rust and cargo-hack
if [[ "${toolchain:-+nightly}" != "+nightly"* ]] || ! cargo hack -V &>/dev/null; then
echo "error: check-minimal-versions.sh requires nightly Rust and cargo-hack"
exit 1
fi
# Parse subcommand.
subcmd="${1:-check}"
if [[ ! "${subcmd}" =~ check|test ]]; then
echo "error: invalid argument \`${1}\`"
exit 1
fi
# This script modifies Cargo.toml and Cargo.lock, so make sure there are no
# unstaged changes.
git diff --exit-code
# Restore original Cargo.toml and Cargo.lock on exit.
trap 'git checkout .' EXIT
if [[ "${subcmd}" == "check" ]]; then
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
# from determining minimal versions based on dev-dependencies.
cargo hack --remove-dev-deps --workspace
fi
# Update Cargo.lock to minimal version dependencies.
cargo ${toolchain:-} update -Z minimal-versions
# Run check for all public members of the workspace.
cargo ${toolchain:-} hack "${subcmd}" --workspace --all-features --ignore-private -Z features=all