aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check-minimal-versions.sh45
-rwxr-xr-xscripts/ci.sh26
-rwxr-xr-xscripts/expandtest.sh35
3 files changed, 44 insertions, 62 deletions
diff --git a/scripts/check-minimal-versions.sh b/scripts/check-minimal-versions.sh
index 6c7fa7b..56fadee 100755
--- a/scripts/check-minimal-versions.sh
+++ b/scripts/check-minimal-versions.sh
@@ -3,7 +3,7 @@
# Check all public crates with minimal version dependencies.
#
# Usage:
-# bash scripts/check-minimal-versions.sh
+# bash scripts/check-minimal-versions.sh [+toolchain] [check|test]
#
# Note:
# - This script modifies Cargo.toml and Cargo.lock while running
@@ -13,19 +13,34 @@
# Refs: https://github.com/rust-lang/cargo/issues/5657
set -euo pipefail
+IFS=$'\n\t'
cd "$(cd "$(dirname "${0}")" && pwd)"/..
-if [[ "${1:-none}" == "+"* ]]; then
- toolchain="${1}"
-elif [[ "${CI:-false}" != "true" ]]; then
- cargo +nightly -V >/dev/null || exit 1
- toolchain="+nightly"
+# 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
+ 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
+elif [[ -n "${2:-}" ]]; then
+ echo "error: invalid argument: ${2}"
+ exit 1
fi
# This script modifies Cargo.toml and Cargo.lock, so make sure there are no
@@ -34,11 +49,13 @@ git diff --exit-code
# Restore original Cargo.toml and Cargo.lock on exit.
trap 'git checkout .' EXIT
-# 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
+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 -Zminimal-versions
+cargo ${toolchain:-} update -Z minimal-versions
# Run check for all public members of the workspace.
-cargo ${toolchain:-} hack check --workspace --all-features --ignore-private -Zfeatures=all
+cargo ${toolchain:-} hack "${subcmd}" --workspace --all-features --ignore-private -Z features=all
diff --git a/scripts/ci.sh b/scripts/ci.sh
index ec08568..b6a1a74 100755
--- a/scripts/ci.sh
+++ b/scripts/ci.sh
@@ -8,30 +8,30 @@
# Note: This script requires nightly Rust, rustfmt, clippy, and cargo-expand
set -euo pipefail
+IFS=$'\n\t'
-if [[ "${1:-none}" == "+"* ]]; then
- toolchain="${1}"
-else
- cargo +nightly -V >/dev/null || exit 1
- toolchain="+nightly"
+# Decide Rust toolchain. Nightly is used by default.
+toolchain="+nightly"
+if [[ "${1:-}" == "+"* ]]; then
+ toolchain="${1}"
+ shift
fi
+# Make sure toolchain is installed.
+cargo "${toolchain}" -V >/dev/null
if [[ "${toolchain:-+nightly}" != "+nightly"* ]] || ! rustfmt -V &>/dev/null || ! cargo clippy -V &>/dev/null || ! cargo expand -V &>/dev/null; then
- echo "error: ci.sh requires nightly Rust, rustfmt, clippy, and cargo-expand"
- exit 1
+ echo "error: ci.sh requires nightly Rust, rustfmt, clippy, and cargo-expand"
+ exit 1
fi
echo "Running 'cargo ${toolchain} fmt --all'"
cargo "${toolchain}" fmt --all
echo "Running 'cargo ${toolchain} clippy --all --all-targets'"
-cargo "${toolchain}" clippy --all --all-features --all-targets -Zunstable-options
+cargo "${toolchain}" clippy --all --all-features --all-targets -Z unstable-options
-echo "Running 'cargo ${toolchain} test --all --exclude expandtest'"
-TRYBUILD=overwrite cargo "${toolchain}" test --all --all-features --exclude expandtest
-
-echo "Running 'bash scripts/expandtest.sh ${toolchain}'"
-"$(cd "$(dirname "${0}")" && pwd)"/expandtest.sh "${toolchain}"
+echo "Running 'cargo ${toolchain} test --all'"
+cargo "${toolchain}" test --all --all-features
echo "Running 'cargo ${toolchain} doc --no-deps --all'"
cargo "${toolchain}" doc --no-deps --all --all-features
diff --git a/scripts/expandtest.sh b/scripts/expandtest.sh
deleted file mode 100755
index 844ace6..0000000
--- a/scripts/expandtest.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-# A script to run expandtest.
-#
-# Usage:
-# bash scripts/expandtest.sh
-#
-# Note: This script requires nightly Rust, rustfmt, and cargo-expand
-
-set -euo pipefail
-
-script_dir="$(cd "$(dirname "${0}")" && pwd)"
-
-if [[ "${1:-none}" == "+"* ]]; then
- toolchain="${1}"
-elif [[ "${CI:-false}" != "true" ]]; then
- cargo +nightly -V >/dev/null || exit 1
- toolchain="+nightly"
-fi
-
-if [[ "${toolchain:-+nightly}" != "+nightly"* ]] || ! rustfmt -V &>/dev/null || ! cargo expand -V &>/dev/null; then
- echo "error: expandtest.sh requires nightly Rust, rustfmt, and cargo-expand"
- exit 1
-fi
-
-if [[ "${CI:-false}" != "true" ]]; then
- # First, check if the compile fails for another reason.
- cargo ${toolchain} check --tests --manifest-path "${script_dir}"/../tests/expand/Cargo.toml
-
- # Next, remove the `*.expanded.rs` files to allow updating those files.
- # Refs: https://docs.rs/macrotest/1/macrotest/#updating-expandedrs
- rm -rf "${script_dir}"/../tests/expand/tests/expand/*.expanded.rs
-fi
-
-cargo ${toolchain:-} test --manifest-path "${script_dir}"/../tests/expand/Cargo.toml