Skip to content

Commit 725c280

Browse files
committed
Fix version parsing if surrounded by other lines
1 parent c6caebf commit 725c280

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

godot-codegen/src/godot_version.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ pub struct GodotVersion {
3131
pub fn parse_godot_version(version_str: &str) -> Result<GodotVersion, Box<dyn Error>> {
3232
// Format of the string emitted by `godot --version`:
3333
// https://github.com/godot-rust/gdext/issues/118#issuecomment-1465748123
34+
// We assume that it's on a line of its own, but it may be surrounded by other lines.
3435
let regex = Regex::new(
35-
r#"(?x) # ignore whitespace and allow line comments (starting with `#`)
36+
r#"(?xm)
37+
# x: ignore whitespace and allow line comments (starting with `#`)
38+
# m: multi-line mode, ^ and $ match start and end of line
3639
^
3740
(?P<major>\d+)
3841
\.(?P<minor>\d+)
@@ -100,6 +103,13 @@ fn test_godot_versions() {
100103
("4.0.beta8.mono.custom_build.b28ddd918", 4, 0, 0, "beta8", s("b28ddd918")),
101104
("4.0.rc1.official.8843d9ad3", 4, 0, 0, "rc1", s("8843d9ad3")),
102105
("4.0.stable.arch_linux", 4, 0, 0, "stable", None),
106+
// Output from 4.0.stable on MacOS in debug mode:
107+
// https://github.com/godotengine/godot/issues/74906
108+
("arguments
109+
0: /Users/runner/work/_temp/godot_bin/godot.macos.editor.dev.x86_64
110+
1: --version
111+
Current path: /Users/runner/work/gdext/gdext/godot-core
112+
4.1.dev.custom_build.79454bfd3", 4, 1, 0, "dev", s("79454bfd3")),
103113
];
104114

105115
let bad_versions = [
@@ -110,7 +120,8 @@ fn test_godot_versions() {
110120

111121
for (full, major, minor, patch, status, custom_rev) in good_versions {
112122
let expected = GodotVersion {
113-
full_string: full.to_owned(),
123+
// Version line is last in every test at the moment.
124+
full_string: full.lines().last().unwrap().to_owned(),
114125
major,
115126
minor,
116127
patch,

0 commit comments

Comments
 (0)