-
Notifications
You must be signed in to change notification settings - Fork 7
/
build
executable file
·67 lines (63 loc) · 1.71 KB
/
build
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
#!/usr/bin/env bash
set -e
# change to this script's directory
# credits to https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself/12197518#12197518
pushd . > /dev/null
SCRIPT_PATH="${BASH_SOURCE[0]}";
while([ -h "${SCRIPT_PATH}" ]); do
cd "`dirname "${SCRIPT_PATH}"`"
SCRIPT_PATH="$(readlink "`basename "${SCRIPT_PATH}"`")";
done
cd "`dirname "${SCRIPT_PATH}"`" > /dev/null
SCRIPT_PATH="`pwd`";
popd > /dev/null
echo "[INFO] change working directory to '$SCRIPT_PATH'"
cd "$SCRIPT_PATH"
# default config for speedcenter
BUILD_FLAGS="--release"
DO_CLEAN=1
DO_RUSTFMT=0
DO_CLIPPY=0
DO_BUILD=1
DO_TEST=0
DO_CHECK=0
while [ "$#" -ne 0 ]; do
case "$1" in
"--speedcenter") ;;
"--noclean") DO_CLEAN=0 ;;
"--debug") BUILD_FLAGS="" ;;
"--release") BUILD_FLAGS="--release" ;;
"--ci") # shortcut to emulate CI build
BUILD_FLAGS=""
DO_CLEAN=0
DO_RUSTFMT=1
DO_CLIPPY=1
DO_BUILD=0
DO_TEST=1
DO_CHECK=0
;;
*)
echo "[ERROR] invalid argument: $1" >&2
exit 1
;;
esac
shift
done
run_if() {
cond="$1"
shift
if [ "$cond" = 1 ]; then
echo "$@"
eval "$@"
else
echo "[SKIP] $@"
fi
}
run_if "$DO_CLEAN" cargo clean
run_if "$DO_RUSTFMT" cargo fmt --all -- --check
# let build fail on Clippy warnings
run_if "$DO_CLIPPY" cargo clippy --all $BUILD_FLAGS --all-targets --all-features -- -D warnings
run_if "$DO_BUILD" cargo build --all $BUILD_FLAGS
run_if "$DO_TEST" bash -c "export RUST_MIN_STACK=$((8 * 1024 * 1024)); exec cargo test --all"
# and also check tests and none-default crate features
run_if "$DO_CHECK" cargo check --all $BUILD_FLAGS