-
Notifications
You must be signed in to change notification settings - Fork 210
/
check.sh
executable file
·117 lines (106 loc) · 3.46 KB
/
check.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
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
#!/bin/bash
# Small utility to run tests locally
# Similar to minimal-ci
# No args specified: do everything
if [ "$#" -eq 0 ]; then
args=("fmt" "clippy" "test" "itest")
else
args=("$@")
fi
# --help menu
for arg in "${args[@]}"; do
if [ "$arg" == "--help" ]; then
echo "Usage: check.sh [<commands>]"
echo ""
echo "Each specified command will be run (until one fails)."
echo "If no commands are specified, all checks are run (no doc; may take several minutes)."
echo ""
echo "Commands:"
echo " fmt format code, fail if bad"
echo " clippy validate clippy lints"
echo " test run unit tests (no Godot)"
echo " itest run integration tests (Godot)"
echo " doc generate docs for 'gdnative' crate"
echo " dok generate docs and open in browser"
echo ""
echo "Examples:"
echo " check.sh fmt clippy"
echo " check.sh"
exit 0
fi
done
# For integration tests
function findGodot() {
# User-defined GODOT_BIN
if [ -n "$GODOT_BIN" ]; then
echo "Found GODOT_BIN env var ($GODOT_BIN)"
godotBin="$GODOT_BIN"
# Executable in path
elif command -v godot &>/dev/null; then
echo "Found 'godot' executable"
godotBin="godot"
# Special case for Windows when there is a .bat file
# Also consider that 'cmd /c' would need 'cmd //c' (https://stackoverflow.com/q/21357813)
elif
# Godot returns 255 for older versions, but 0 for newer ones
godot.bat --version
[[ $? -eq 255 || $? -eq 0 ]]
then
echo "Found 'godot.bat' script"
godotBin="godot.bat"
# Error case
else
echo "Godot executable not found"
exit 2
fi
}
features="gdnative/async,gdnative/serde"
itest_toggled_features="gdnative/inventory,no-manual-register"
cmds=()
for arg in "${args[@]}"; do
case "$arg" in
fmt)
cmds+=("cargo fmt --all -- --check")
;;
clippy)
cmds+=("cargo clippy --workspace --features $features -- -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented -D warnings")
;;
test)
cmds+=("cargo test --features $features")
;;
itest)
findGodot
cmds+=("cargo build --manifest-path test/Cargo.toml --features $features")
cmds+=("cp target/debug/*gdnative_test* test/project/lib/")
cmds+=("$godotBin --path test/project")
cmds+=("cargo build --manifest-path test/Cargo.toml --features $features,$itest_toggled_features")
cmds+=("cp target/debug/*gdnative_test* test/project/lib/")
cmds+=("$godotBin --path test/project")
;;
doc)
cmds+=("cargo doc --lib -p gdnative --no-deps --features $features")
;;
dok)
cmds+=("cargo doc --lib -p gdnative --no-deps --features $features --open")
;;
*)
echo "Unrecognized command '$arg'"
exit 2
;;
esac
done
RED='\033[1;31m'
GREEN='\033[1;36m'
END='\033[0m'
for cmd in "${cmds[@]}"; do
echo "> $cmd"
$cmd || {
printf "$RED\n=========================="
printf "\ngodot-rust checker FAILED."
printf "\n==========================\n$END"
exit 1
}
done
printf "$GREEN\n=============================="
printf "\ngodot-rust checker SUCCESSFUL."
printf "\n==============================\n$END"