@@ -5,6 +5,7 @@ import platform
5
5
import sys
6
6
import subprocess
7
7
from binding_generator import scons_generate_bindings , scons_emit_files
8
+ from SCons .Errors import UserError
8
9
9
10
EnsureSConsVersion (4 , 0 )
10
11
@@ -15,6 +16,28 @@ def add_sources(sources, dir, extension):
15
16
sources .append (dir + "/" + f )
16
17
17
18
19
+ def normalize_path (val ):
20
+ return val if os .path .isabs (val ) else os .path .join (env .Dir ("#" ).abspath , val )
21
+
22
+
23
+ def validate_api_file (key , val , env ):
24
+ if not os .path .isfile (normalize_path (val )):
25
+ raise UserError ("GDExtension API file ('%s') does not exist: %s" % (key , val ))
26
+
27
+
28
+ def validate_gdextension_dir (key , val , env ):
29
+ if not os .path .isdir (normalize_path (val )):
30
+ raise UserError ("GDExtension directory ('%s') does not exist: %s" % (key , val ))
31
+
32
+
33
+ def get_gdextension_dir (env ):
34
+ return normalize_path (env .get ("gdextension_dir" , env .Dir ("gdextension" ).abspath ))
35
+
36
+
37
+ def get_api_file (env ):
38
+ return normalize_path (env .get ("custom_api_file" , os .path .join (get_gdextension_dir (env ), "extension_api.json" )))
39
+
40
+
18
41
# Try to detect the host platform automatically.
19
42
# This is used if no `platform` argument is passed
20
43
if sys .platform .startswith ("linux" ):
@@ -80,17 +103,17 @@ opts.Add(
80
103
opts .Add (
81
104
PathVariable (
82
105
"gdextension_dir" ,
83
- "Path to the directory containing GDExtension interface header and API JSON file" ,
84
- "gdextension" ,
85
- PathVariable . PathIsDir ,
106
+ "Path to a custom directory containing GDExtension interface header and API JSON file" ,
107
+ None ,
108
+ validate_gdextension_dir ,
86
109
)
87
110
)
88
111
opts .Add (
89
112
PathVariable (
90
113
"custom_api_file" ,
91
114
"Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
92
115
None ,
93
- PathVariable . PathIsFile ,
116
+ validate_api_file ,
94
117
)
95
118
)
96
119
opts .Add (
@@ -186,16 +209,10 @@ if env["float"] == "64":
186
209
187
210
# Generate bindings
188
211
env .Append (BUILDERS = {"GenerateBindings" : Builder (action = scons_generate_bindings , emitter = scons_emit_files )})
189
- json_api_file = ""
190
-
191
- if "custom_api_file" in env :
192
- json_api_file = env ["custom_api_file" ]
193
- else :
194
- json_api_file = os .path .join (os .getcwd (), env ["gdextension_dir" ], "extension_api.json" )
195
212
196
213
bindings = env .GenerateBindings (
197
214
env .Dir ("." ),
198
- [json_api_file , os .path .join (env [ "gdextension_dir" ] , "gdextension_interface.h" ), "binding_generator.py" ],
215
+ [get_api_file ( env ) , os .path .join (get_gdextension_dir ( env ) , "gdextension_interface.h" ), "binding_generator.py" ],
199
216
)
200
217
201
218
scons_cache_path = os .environ .get ("SCONS_CACHE" )
@@ -209,7 +226,7 @@ if env["generate_bindings"]:
209
226
NoCache (bindings )
210
227
211
228
# Includes
212
- env .Append (CPPPATH = [[env .Dir (d ) for d in [env [ "gdextension_dir" ] , "include" , os .path .join ("gen" , "include" )]]])
229
+ env .Append (CPPPATH = [[env .Dir (d ) for d in [get_gdextension_dir ( env ) , "include" , os .path .join ("gen" , "include" )]]])
213
230
214
231
# Sources to compile
215
232
sources = []
0 commit comments