@@ -34,10 +34,11 @@ Commands:
34
34
dok generate docs and open in browser
35
35
36
36
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, 4.3.1).
41
42
42
43
Examples:
43
44
check.sh fmt clippy
50
51
# Terminal color codes.
51
52
RED=' \033[1;31m'
52
53
CYAN=' \033[1;36m'
54
+ YELLOW=' \033[1;33m'
53
55
END=' \033[0m'
54
56
55
57
# ###############################################################################
@@ -61,6 +63,22 @@ function log() {
61
63
echo " $@ " >&2
62
64
}
63
65
66
+ # Converts a x.x.x version string to a feature string.
67
+ # e.g. 4.3.0 -> godot/api-4-3, 4.3.1 -> godot/api-4-3-1
68
+ function version_to_feature() {
69
+ echo " godot/api-$( echo " $1 " | sed ' s/\./-/g' | sed ' s/-0$//' ) "
70
+ }
71
+
72
+ # Validates that the given string is a valid x.x.x version string.
73
+ # Allow for .0 to be dropped (e.g. 4.3 is equivalent to 4.3.0).
74
+ function validate_version_string() {
75
+ if [[ ! " $1 " =~ ^4\. [0-9]+ (\. [0-9]+)? $ ]]; then
76
+ log " Invalid Godot version string '$1 '."
77
+ log " The version string should be in the form 'x.x.x' or 'x.x' and the major version should be at least 4."
78
+ exit 2
79
+ fi
80
+ }
81
+
64
82
# Echoes the given command to stderr, then executes it.
65
83
function run() {
66
84
# https://stackoverflow.com/a/76153233/14637
@@ -78,9 +96,10 @@ function findGodot() {
78
96
# $godotBin previously detected.
79
97
if [[ -v godotBin ]]; then
80
98
return
99
+ fi
81
100
82
101
# User-defined GODOT4_BIN.
83
- elif [[ -n " $GODOT4_BIN " ]]; then
102
+ if [[ -n " $GODOT4_BIN " ]]; then
84
103
log " Using environment variable GODOT4_BIN=$( printf %q " $GODOT4_BIN " ) "
85
104
godotBin=" $GODOT4_BIN "
86
105
@@ -95,7 +114,7 @@ function findGodot() {
95
114
log " Found 'godot4.bat' script"
96
115
godotBin=" godot4.bat"
97
116
98
- # This should come last: only use this as a last resort as `godot` may refer to a
117
+ # This should come last: only use this as a last resort as `godot` may refer to a
99
118
# Godot 3.x installation.
100
119
elif command -v godot > /dev/null; then
101
120
# Check if `godot` actually is Godot 4.x
@@ -157,7 +176,7 @@ function cmd_test() {
157
176
function cmd_itest() {
158
177
findGodot && \
159
178
run cargo build -p itest " ${extraCargoArgs[@]} " && \
160
- run " $godotBin " --path itest/godot --headless -- " [${extraArgs[@]} ]"
179
+ run " $godotBin " $GODOT_ARGS --path itest/godot --headless -- " [${extraArgs[@]} ]"
161
180
}
162
181
163
182
function cmd_doc() {
@@ -176,10 +195,11 @@ function cmd_dok() {
176
195
# `itest` compilations and `check.sh` runs. Note that this means some runs are different from CI.
177
196
extraCargoArgs=(" --no-default-features" )
178
197
cmds=()
179
- nextArgIsFilter=false
180
198
extraArgs=()
199
+ apiVersion=" "
181
200
182
- for arg in " $@ " ; do
201
+ while [[ $# -gt 0 ]]; do
202
+ arg=" $1 "
183
203
case " $arg " in
184
204
-h | --help | help)
185
205
echo " $HELP_TEXT "
@@ -196,29 +216,82 @@ for arg in "$@"; do
196
216
;;
197
217
-f | --filter)
198
218
if [[ " ${cmds[*]} " =~ itest ]]; then
199
- nextArgIsFilter=true
219
+ if [[ -z " $2 " ]]; then
220
+ log " -f/--filter requires an argument."
221
+ exit 2
222
+ fi
223
+
224
+ extraArgs+=(" $2 " )
225
+ shift
200
226
else
201
227
log " -f/--filter requires 'itest' to be specified as a command."
202
228
exit 2
203
229
fi
204
230
;;
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."
231
+ -a | --api-version)
232
+ if [[ -z " $2 " || " $2 " == -* ]]; then
233
+ log " -a/--api-version requires an argument."
211
234
exit 2
212
235
fi
236
+
237
+ apiVersion=" $2 "
238
+ validate_version_string " $apiVersion "
239
+
240
+ apiFeature=$( version_to_feature " $apiVersion " )
241
+ extraCargoArgs+=(" --features" " $apiFeature " )
242
+
243
+ log " Using Godot API version $apiVersion with feature $apiFeature "
244
+
245
+ # Remove "clippy" from the default commands if the API version is specified
246
+ # since it can produce unexpected errors.
247
+ DEFAULT_COMMANDS=(" ${DEFAULT_COMMANDS[@]/ clippy} " )
248
+
249
+ shift
250
+ ;;
251
+ * )
252
+ log " Unrecognized argument '$arg '. Use '$0 --help' to see what's available."
253
+ exit 2
213
254
;;
214
255
esac
256
+ shift
215
257
done
216
258
217
259
# Default if no commands are explicitly given.
218
260
if [[ ${# cmds[@]} -eq 0 ]]; then
219
261
cmds=(" ${DEFAULT_COMMANDS[@]} " )
220
262
fi
221
263
264
+ # Filter out any empty strings and note if clippy will be run.
265
+ filtered_commands=()
266
+ runClippy=0
267
+ for cmd in " ${cmds[@]} " ; do
268
+ if [[ -n " $cmd " ]]; then
269
+ filtered_commands+=(" $cmd " )
270
+
271
+ if [[ " $cmd " == " clippy" ]]; then
272
+ runClippy=1
273
+ fi
274
+ fi
275
+ done
276
+ cmds=(" ${filtered_commands[@]} " )
277
+
278
+ # Display warning about using clippy if an API version was provided.
279
+ if [[ " ${# apiFeature[@]} " -ne 0 ]]; then
280
+ log
281
+ # Show different warning depending on if clippy was explicitly requested.
282
+ if [[ " $runClippy " -eq 1 ]]; then
283
+ log -e " ${YELLOW} Warning: Clippy may produce unexpected errors when testing against a specific API version.${END} "
284
+ else
285
+ log -e " ${YELLOW} Warning: Clippy is disabled by default when using a specific Godot API version.${END} "
286
+ fi
287
+ log -e " ${YELLOW} For more information, see issue #1016 on GitHub:${END} "
288
+ log -e " ${CYAN} https://github.com/godot-rust/gdext/pull/1016#issuecomment-2629002047${END} "
289
+ log
290
+ fi
291
+
292
+ log " Checks to run: ${cmds[*]} "
293
+ log
294
+
222
295
# ###############################################################################
223
296
# Execution and summary
224
297
# ###############################################################################
0 commit comments