@@ -4,11 +4,19 @@ import os
44import  platform 
55import  sys 
66import  subprocess 
7+ from  typing  import  TYPE_CHECKING 
78from  binding_generator  import  scons_generate_bindings , scons_emit_files 
9+ from  SCons .Script  import  Environment 
810from  SCons .Errors  import  UserError 
11+ from  SCons .Variables  import  BoolVariable , EnumVariable , PathVariable 
912
1013EnsureSConsVersion (4 , 0 )
1114
15+ try :
16+  Import ("env" )
17+ except :
18+  pass 
19+ 
1220
1321def  add_sources (sources , dir , extension ):
1422 for  f  in  os .listdir (dir ):
5361
5462# Default tools with no platform defaults to gnu toolchain. 
5563# We apply platform specific toolchains via our custom tools. 
56- env  =  Environment (tools = ["default" ], PLATFORM = "" )
64+ if  not  "env"  in  globals () or  TYPE_CHECKING :
65+  env  =  Environment (tools = ["default" ], PLATFORM = "" )
5766env .PrependENVPath ("PATH" , os .getenv ("PATH" ))
5867
5968# Default num_jobs to local cpu count if not user specified. 
@@ -87,9 +96,9 @@ opts = Variables(customs, ARGUMENTS)
8796platforms  =  ("linux" , "macos" , "windows" , "android" , "ios" , "javascript" )
8897opts .Add (
8998 EnumVariable (
90-  "platform" ,
91-  "Target platform" ,
92-  default_platform ,
99+  key = "platform" ,
100+  help = "Target platform" ,
101+  default = env . get ( "platform" ,  default_platform ) ,
93102 allowed_values = platforms ,
94103 ignorecase = 2 ,
95104 )
@@ -99,31 +108,53 @@ opts.Add(
99108# Godot release templates are only compatible with "template_release" builds. 
100109# For this reason, we default to template_debug builds, unlike Godot which defaults to editor builds. 
101110opts .Add (
102-  EnumVariable ("target" , "Compilation target" , "template_debug" , ("editor" , "template_release" , "template_debug" ))
111+  EnumVariable (
112+  key = "target" ,
113+  help = "Compilation target" ,
114+  default = env .get ("target" , "template_debug" ),
115+  allowed_values = ("editor" , "template_release" , "template_debug" ),
116+  )
103117)
104118opts .Add (
105119 PathVariable (
106-  "gdextension_dir" ,
107-  "Path to a custom directory containing GDExtension interface header and API JSON file" ,
108-  None ,
109-  validate_gdextension_dir ,
120+  key = "gdextension_dir" ,
121+  help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
122+  default = env . get ( "gdextension_dir" ,  None ) ,
123+  validator = validate_gdextension_dir ,
110124 )
111125)
112126opts .Add (
113127 PathVariable (
114-  "custom_api_file" ,
115-  "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
116-  None ,
117-  validate_api_file ,
128+  key = "custom_api_file" ,
129+  help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
130+  default = env .get ("custom_api_file" , None ),
131+  validator = validate_api_file ,
132+  )
133+ )
134+ opts .Add (
135+  BoolVariable (
136+  key = "generate_bindings" ,
137+  help = "Force GDExtension API bindings generation. Auto-detected by default." ,
138+  default = env .get ("generate_bindings" , False ),
118139 )
119140)
120141opts .Add (
121-  BoolVariable ("generate_bindings" , "Force GDExtension API bindings generation. Auto-detected by default." , False )
142+  BoolVariable (
143+  key = "generate_template_get_node" ,
144+  help = "Generate a template version of the Node class's get_node." ,
145+  default = env .get ("generate_template_get_node" , True ),
146+  )
122147)
123- opts .Add (BoolVariable ("generate_template_get_node" , "Generate a template version of the Node class's get_node." , True ))
124148
125- opts .Add (BoolVariable ("build_library" , "Build the godot-cpp library." , True ))
126- opts .Add (EnumVariable ("precision" , "Set the floating-point precision level" , "single" , ("single" , "double" )))
149+ opts .Add (BoolVariable (key = "build_library" , help = "Build the godot-cpp library." , default = env .get ("build_library" , True )))
150+ opts .Add (
151+  EnumVariable (
152+  key = "precision" ,
153+  help = "Set the floating-point precision level" ,
154+  default = env .get ("precision" , "single" ),
155+  allowed_values = ("single" , "double" ),
156+  )
157+ )
127158
128159# Add platform options 
129160tools  =  {}
@@ -149,7 +180,15 @@ architecture_aliases = {
149180 "ppc" : "ppc32" ,
150181 "ppc64le" : "ppc64" ,
151182}
152- opts .Add (EnumVariable ("arch" , "CPU architecture" , "" , architecture_array , architecture_aliases ))
183+ opts .Add (
184+  EnumVariable (
185+  key = "arch" ,
186+  help = "CPU architecture" ,
187+  default = env .get ("arch" , "" ),
188+  allowed_values = architecture_array ,
189+  map = architecture_aliases ,
190+  )
191+ )
153192
154193# Targets flags tool (optimizations, debug symbols) 
155194target_tool  =  Tool ("targets" , toolpath = ["tools" ])
0 commit comments