forked from godot-rust/gdnative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.sh
executable file
·91 lines (77 loc) · 2.02 KB
/
example.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
#!/bin/bash
# Small utility to compile and run examples
# No args specified: do everything
if [ "$#" -eq 0 ]; then
args=("--help")
else
args=("$@")
fi
# --help menu
for arg in "${args[@]}"; do
if [ "$arg" == "--help" ]; then
echo "Usage: example.sh <command> <example-name>"
echo ""
echo "Commands:"
echo " run run the specified example"
echo " edit open the specified example in the editor"
echo ""
echo "Examples:"
echo " example.sh run hello-world"
exit 0
fi
done
if [ "$#" -ne 2 ]; then
echo "Both the command and the name of the example are required."
exit 1
fi
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
}
example_path="${BASH_SOURCE%/*}/examples/${args[1]}"
if ! [[ -d "$example_path" ]]; then
echo "The example ${args[1]} is not found."
exit 2
fi
findGodot
cmds=()
case "${args[0]}" in
run)
cmds+=("cargo build --manifest-path $example_path/Cargo.toml")
cmds+=("$godotBin --path $example_path")
;;
edit)
cmds+=("cargo build --manifest-path $example_path/Cargo.toml")
cmds+=("$godotBin -e --path $example_path")
;;
*)
echo "Unrecognized command '$arg'"
exit 2
;;
esac
for cmd in "${cmds[@]}"; do
echo "> $cmd"
$cmd || {
exit 1
}
done