5
5
import re
6
6
import platform
7
7
import shutil
8
- from typing import Tuple
8
+ from typing import Optional , Tuple
9
9
import subprocess
10
10
import argparse
11
11
from pathlib import Path
@@ -23,18 +23,49 @@ def log(*args, **kwargs):
23
23
print (* args , ** kwargs , file = sys .stderr )
24
24
25
25
26
+ def get_default_godot_version_from_meson (build_dir : Path ) -> str :
27
+ # Ultra lazy & fast json parsing ^^
28
+ meson_build_options = build_dir / "meson-info/intro-buildoptions.json"
29
+ version = (
30
+ meson_build_options .read_text ()
31
+ .split ('"name": "godot_version", "value": "' , 1 )[- 1 ]
32
+ .split ('"' , 1 )[0 ]
33
+ )
34
+ assert version
35
+ return version
36
+
37
+
38
+ def parse_raw_version (raw_version : str ) -> GodotBinaryVersion :
39
+ # Provided value is version information with format <major>.<minor>.<patch>[-<extra>]
40
+ match = re .match (r"^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(\w+))?$" , raw_version )
41
+ if match :
42
+ major , minor , patch , extra = match .groups ()
43
+ else :
44
+ raise ValueError (
45
+ f"`{ raw_version } ` is neither an existing file nor a valid <major>.<minor>.<patch>[-<extra>] Godot version format"
46
+ )
47
+ return (major , minor , patch , extra or "stable" )
48
+
49
+
26
50
def parse_godot_binary_hint (
27
51
godot_binary_hint : str ,
28
- ) -> Tuple [GodotBinaryPlatform , GodotBinaryVersion ]:
52
+ ) -> Tuple [GodotBinaryPlatform , Optional [ GodotBinaryVersion ] ]:
29
53
try :
30
54
build_machine , raw_version = godot_binary_hint .split (":" )
31
55
except ValueError :
32
56
build_machine = ""
33
57
raw_version = godot_binary_hint
34
- raw_version = raw_version
35
- build_machine = build_machine or platform .machine ()
36
58
37
- build_platform = f"{ platform .system ()} -{ build_machine } " .lower ()
59
+ # e.g. `build_machine == "x86"`
60
+ build_machine = (build_machine or platform .machine ()).lower ()
61
+ # e.g. `build_platform_prefix == "windows-"`
62
+ build_platform_prefix = f"{ platform .system ()} -" .lower ()
63
+ if build_machine .startswith (build_platform_prefix ):
64
+ build_platform = build_machine
65
+ else :
66
+ build_platform = build_platform_prefix + build_machine
67
+ # e.g. `build_platform == "windows-x86"`
68
+
38
69
godot_build_platform = {
39
70
"linux-x86_64" : "linux.x86_64" ,
40
71
"linux-x64" : "linux.x86_64" ,
@@ -53,20 +84,16 @@ def parse_godot_binary_hint(
53
84
f"Don't know how to download a Godot binary for your platform `{ build_platform } `"
54
85
)
55
86
56
- # Provided value is version information with format <major>.<minor>.<patch>[-<extra>]
57
- match = re .match (r"^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(\w+))?$" , raw_version )
58
- if match :
59
- major , minor , patch , extra = match .groups ()
60
- else :
61
- raise ValueError (
62
- f"`{ raw_version } ` is neither an existing file nor a valid <major>.<minor>.<patch>[-<extra>] Godot version format"
63
- )
64
- return godot_build_platform , (major , minor , patch , extra or "stable" )
87
+ # If version has not been provided, it will be determined later with `get_default_godot_version_from_meson()`
88
+ version = parse_raw_version (raw_version ) if raw_version else None
89
+ return godot_build_platform , version
65
90
66
91
67
92
def fetch_godot_binary (
68
- build_dir : Path , godot_platform : GodotBinaryPlatform , version : GodotBinaryVersion
93
+ build_dir : Path , godot_platform : GodotBinaryPlatform , version : Optional [ GodotBinaryVersion ]
69
94
) -> Path :
95
+ if not version :
96
+ version = parse_raw_version (get_default_godot_version_from_meson (build_dir ))
70
97
major , minor , patch , extra = version
71
98
strversion = f"{ major } .{ minor } .{ patch } " if patch != "0" else f"{ major } .{ minor } "
72
99
binary_name = f"Godot_v{ strversion } -{ extra } _{ godot_platform } "
0 commit comments