Skip to content

Commit c6f32b1

Browse files
test: support switching godot versions in check.sh
Allows easily testing against a given version of Godot simply by passing a version to the -a/--api-version parameter and/or the -g/--use-gdvm parameter. -a/--api-version is used to specify the Godot API version to use for building the Rust bindings. -g/--use-gdvm indicates that the script should use gdvm to match the Godot version to the API version. It also accepts a version of Godot to use instead, which allows testing for compatibility between versions of Godot and the Rust bindings' API version. Examples: Test with Godot API version 4.2.1 and the detected version of Godot. If gdvm is installed, it will use the version of Godot that matches the API version. ./check.sh itest -a 4.2.1 Test with Godot API version 4.2.1 and Godot version 4.3.0. ./check.sh itest -g 4.3.0 -a 4.2.1 This commit also adds detection support for gdvm, such that if a user has gdvm installed, the script will use it as the path to the Godot executable, unless overridden by the GODOT4_BIN environment variable. This way it can ensure passing the --console flag to gdvm, useful for Windows users who otherwise default to the version of Godot that does not attach to the console. This also enables the version selection functionality described above.
1 parent 7461251 commit c6f32b1

File tree

1 file changed

+95
-16
lines changed

1 file changed

+95
-16
lines changed

check.sh

+95-16
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ Commands:
3434
dok generate docs and open in browser
3535
3636
Options:
37-
-h, --help print this help text
38-
--double run check with double-precision
39-
-f, --filter <arg> only run integration tests which contain any of the
40-
args (comma-separated). requires itest.
37+
-h, --help print this help text
38+
--double run check with double-precision
39+
-f, --filter <arg> only run integration tests which contain any of the
40+
args (comma-separated). requires itest.
41+
-a, --api-version <ver> specify the Godot API version to use (e.g. 4.3.0, 4.3.1).
42+
If gdvm is installed, this will also set the Godot version,
43+
unless -g/--godot-version is specified.
44+
-g, --godot-version <ver> (works only if GODOT4_BIN is not set and gdvm is in
45+
the PATH) if specified, uses gdvm to run Godot with
46+
the specified version.
4147
4248
Examples:
4349
check.sh fmt clippy
@@ -61,6 +67,21 @@ function log() {
6167
echo "$@" >&2
6268
}
6369

70+
# Converts a x.x.x version string to a feature string.
71+
# e.g. 4.3.0 -> godot/api-4-3, 4.3.1 -> godot/api-4-3-1
72+
function version_to_feature() {
73+
echo "godot/api-$(echo "$1" | sed 's/\./-/g' | sed 's/-0$//')"
74+
}
75+
76+
# Validates that the given string is a valid x.x.x version string.
77+
function validate_version_string() {
78+
if [[ ! "$1" =~ ^4\.[0-9]+\.[0-9]+$ ]]; then
79+
log "Invalid Godot version string '$1'."
80+
log "The version string should be in the form 'x.x.x' and the major version should be at least 4."
81+
exit 2
82+
fi
83+
}
84+
6485
# Echoes the given command to stderr, then executes it.
6586
function run() {
6687
# https://stackoverflow.com/a/76153233/14637
@@ -78,12 +99,34 @@ function findGodot() {
7899
# $godotBin previously detected.
79100
if [[ -v godotBin ]]; then
80101
return
102+
fi
103+
104+
gdvmArgs=()
81105

82106
# User-defined GODOT4_BIN.
83-
elif [[ -n "$GODOT4_BIN" ]]; then
107+
if [[ -n "$GODOT4_BIN" ]]; then
84108
log "Using environment variable GODOT4_BIN=$(printf %q "$GODOT4_BIN")"
85109
godotBin="$GODOT4_BIN"
86110

111+
# gdvm
112+
elif command -v gdvm >/dev/null; then
113+
log "Found 'gdvm' executable"
114+
godotBin="gdvm"
115+
gdvmArgs+=("run")
116+
117+
# If Godot version is not specified, use the API version if it is specified
118+
if [[ -n "$apiVersion" && -z "$gdvmGodotVersion" ]]; then
119+
gdvmGodotVersion="$apiVersion"
120+
121+
echo "Using Godot version that corresponds to API version $apiVersion"
122+
fi
123+
124+
if [[ -n "$gdvmGodotVersion" ]]; then
125+
gdvmArgs+=("$gdvmGodotVersion" "--force")
126+
fi
127+
128+
gdvmArgs+=("--console" "--")
129+
87130
# Executable in path.
88131
elif command -v godot4 >/dev/null; then
89132
log "Found 'godot4' executable"
@@ -95,7 +138,7 @@ function findGodot() {
95138
log "Found 'godot4.bat' script"
96139
godotBin="godot4.bat"
97140

98-
# This should come last: only use this as a last resort as `godot` may refer to a
141+
# This should come last: only use this as a last resort as `godot` may refer to a
99142
# Godot 3.x installation.
100143
elif command -v godot >/dev/null; then
101144
# Check if `godot` actually is Godot 4.x
@@ -157,7 +200,7 @@ function cmd_test() {
157200
function cmd_itest() {
158201
findGodot && \
159202
run cargo build -p itest "${extraCargoArgs[@]}" && \
160-
run "$godotBin" --path itest/godot --headless -- "[${extraArgs[@]}]"
203+
run "$godotBin" "${gdvmArgs[@]}" --path itest/godot --headless -- "[${extraArgs[@]}]"
161204
}
162205

163206
function cmd_doc() {
@@ -176,10 +219,11 @@ function cmd_dok() {
176219
# `itest` compilations and `check.sh` runs. Note that this means some runs are different from CI.
177220
extraCargoArgs=("--no-default-features")
178221
cmds=()
179-
nextArgIsFilter=false
180222
extraArgs=()
223+
apiVersion=""
181224

182-
for arg in "$@"; do
225+
while [[ $# -gt 0 ]]; do
226+
arg="$1"
183227
case "$arg" in
184228
-h | --help | help)
185229
echo "$HELP_TEXT"
@@ -196,22 +240,57 @@ for arg in "$@"; do
196240
;;
197241
-f | --filter)
198242
if [[ "${cmds[*]}" =~ itest ]]; then
199-
nextArgIsFilter=true
243+
if [[ -z "$2" ]]; then
244+
log "-f/--filter requires an argument."
245+
exit 2
246+
fi
247+
248+
extraArgs+=("$2")
249+
shift
200250
else
201251
log "-f/--filter requires 'itest' to be specified as a command."
202252
exit 2
203253
fi
204254
;;
205-
*)
206-
if $nextArgIsFilter; then
207-
extraArgs+=("$arg")
208-
nextArgIsFilter=false
209-
else
210-
log "Unrecognized argument '$arg'. Use '$0 --help' to see what's available."
255+
-a | --api-version)
256+
if [[ -z "$2" || "$2" == -* ]]; then
257+
log "-a/--api-version requires an argument."
211258
exit 2
212259
fi
260+
261+
apiVersion="$2"
262+
validate_version_string "$apiVersion"
263+
264+
apiFeature=$(version_to_feature "$apiVersion")
265+
extraCargoArgs+=("--features" "$apiFeature")
266+
267+
echo "Using Godot API version $apiVersion with feature $apiFeature"
268+
shift
269+
;;
270+
-g | --godot-version)
271+
if ! command -v gdvm >/dev/null; then
272+
log "The -g/--godot-version option requires 'gdvm' to be in the PATH."
273+
exit 2
274+
elif [[ -n "$GODOT4_BIN" ]]; then
275+
log "The -g/--godot-version option cannot be used when GODOT4_BIN is set."
276+
exit 2
277+
fi
278+
279+
if [[ -z "$2" || "$2" == -* ]]; then
280+
log "-g/--godot-version requires an argument."
281+
exit 2
282+
fi
283+
284+
validate_version_string "$2"
285+
gdvmGodotVersion="$2"
286+
shift
287+
;;
288+
*)
289+
log "Unrecognized argument '$arg'. Use '$0 --help' to see what's available."
290+
exit 2
213291
;;
214292
esac
293+
shift
215294
done
216295

217296
# Default if no commands are explicitly given.

0 commit comments

Comments
 (0)