-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommands.sh
More file actions
executable file
·127 lines (99 loc) · 3.33 KB
/
Copy pathcommands.sh
File metadata and controls
executable file
·127 lines (99 loc) · 3.33 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -e -o pipefail
# Run commands to build and test with a feature powerset. Requires `cargo-hack` to be installed.
CARGO="${CARGO:-cargo}"
EXCLUDED_FEATURES=(internal-docs)
EXCLUDED_FEATURES_NO_STD=(std internal-docs default)
trap 'echo_err "Error occurred at $0 command: $BASH_COMMAND"' ERR
trap 'echo_err "Exiting $0"' EXIT
run_build() {
check_cargo_hack
echo_err "Running non-dev build" >&2
run_cargo_hack build
echo_err "Running dev build"
run_cargo_hack build --all-targets
}
run_test() {
check_cargo_hack
echo_err "Running non-doc tests"
run_cargo_hack test --lib --bins --tests --benches --examples
}
run_nextest() {
check_cargo_hack
echo_err "Running non-doc tests"
NEXTEST_NO_TESTS=pass run_cargo_hack nextest run --all-targets
}
run_miri() {
echo_err "Running miri"
run_cargo_std miri nextest run --all-targets -j2
}
run_doctest() {
echo_err "Running doctests with all features"
cargo test --all-features --doc
}
run_coverage() {
echo_err "Running coverage (requires nightly)"
run_cargo_std llvm-cov nextest --all-features --all-targets --lcov --output-path lcov.info
run_cargo_std llvm-cov test --all-features --doc --lcov --output-path lcov-doctest.info
echo_err "Wrote output to lcov.info and lcov-doctest.info"
}
run_build_no_std() {
local build_target="$1"
check_cargo_hack
echo_err "Building for no-std target ${build_target}"
run_cargo_hack_no_std build --target "${build_target}"
}
echo_err() {
echo "$@" >&2
}
check_cargo_hack() {
if ! $CARGO hack --version >/dev/null 2>&1; then
echo_err "cargo-hack not installed. Install it with:"
echo_err " cargo install cargo-hack"
exit 1
fi
}
run_cargo_hack() {
joined_excluded_features=$(printf ",%s" "${EXCLUDED_FEATURES[@]}")
# Strip leading comma
joined_excluded_features=${joined_excluded_features:1}
$CARGO hack --feature-powerset --exclude-features "$joined_excluded_features" "$@"
}
run_cargo_hack_no_std() {
joined_excluded_features=$(printf ",%s" "${EXCLUDED_FEATURES_NO_STD[@]}")
# Strip leading comma
joined_excluded_features=${joined_excluded_features:1}
$CARGO hack --feature-powerset --exclude-features "$joined_excluded_features" "$@"
}
run_cargo_std() {
$CARGO "$@" --features std
}
if [[ $# -eq 0 ]]; then
echo_err "Usage: commands.sh [b|build|t|test|nt|nextest|dt|doctest|miri|coverage|build-no-std]"
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
+*) CARGO="$CARGO $1" ;;
b|build) run_build ;;
t|test) run_test ;;
nt|nextest) run_nextest ;;
miri) run_miri ;;
coverage) run_coverage ;;
dt|doctest) run_doctest ;;
build-no-std)
shift;
case $1 in
--target) build_target="$2"; shift ;;
"") echo_err "Usage: commands.sh build-no-std --target <target>"; exit 1 ;;
esac
if [[ -z "${build_target:-}" ]]; then
echo_err "Usage: commands.sh build-no-std --target <target>"
exit 1
fi
run_build_no_std "$build_target" ;;
-h|--help) echo "Usage: commands.sh [b|build|t|test|nt|nextest|dt|doctest|miri|coverage|build-no-std]"; exit 0 ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done