@@ -107,22 +107,11 @@ for x in sorted(glob.glob("platform/*")):
107
107
sys .path .remove (tmppath )
108
108
sys .modules .pop ("detect" )
109
109
110
- custom_tools = ["default" ]
111
-
112
- platform_arg = ARGUMENTS .get ("platform" , ARGUMENTS .get ("p" , False ))
113
-
114
- if platform_arg == "android" :
115
- custom_tools = ["clang" , "clang++" , "as" , "ar" , "link" ]
116
- elif platform_arg == "web" :
117
- # Use generic POSIX build toolchain for Emscripten.
118
- custom_tools = ["cc" , "c++" , "ar" , "link" , "textfile" , "zip" ]
119
- elif os .name == "nt" and methods .get_cmdline_bool ("use_mingw" , False ):
120
- custom_tools = ["mingw" ]
121
-
122
110
# We let SCons build its default ENV as it includes OS-specific things which we don't
123
- # want to have to pull in manually.
111
+ # want to have to pull in manually. However we enforce no "tools", which we register
112
+ # further down after parsing our platform-specific configuration.
124
113
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
125
- env = Environment (tools = custom_tools )
114
+ env = Environment (tools = [] )
126
115
env .PrependENVPath ("PATH" , os .getenv ("PATH" ))
127
116
env .PrependENVPath ("PKG_CONFIG_PATH" , os .getenv ("PKG_CONFIG_PATH" ))
128
117
if "TERM" in os .environ : # Used for colored output.
@@ -168,11 +157,7 @@ if profile:
168
157
opts = Variables (customs , ARGUMENTS )
169
158
170
159
# Target build options
171
- if env .scons_version >= (4 , 3 ):
172
- opts .Add (["platform" , "p" ], "Target platform (%s)" % "|" .join (platform_list ), "" )
173
- else :
174
- opts .Add ("platform" , "Target platform (%s)" % "|" .join (platform_list ), "" )
175
- opts .Add ("p" , "Alias for 'platform'" , "" )
160
+ opts .Add ((["platform" , "p" ], "Target platform (%s)" % "|" .join (platform_list ), "" ))
176
161
opts .Add (EnumVariable ("target" , "Compilation target" , "editor" , ("editor" , "template_release" , "template_debug" )))
177
162
opts .Add (EnumVariable ("arch" , "CPU architecture" , "auto" , ["auto" ] + architectures , architecture_aliases ))
178
163
opts .Add (BoolVariable ("dev_build" , "Developer build with dev-only debugging code (DEV_ENABLED)" , False ))
@@ -312,10 +297,7 @@ if env["import_env_vars"]:
312
297
313
298
# Platform selection: validate input, and add options.
314
299
315
- if env .scons_version < (4 , 3 ) and not env ["platform" ]:
316
- env ["platform" ] = env ["p" ]
317
-
318
- if env ["platform" ] == "" :
300
+ if not env ["platform" ]:
319
301
# Missing `platform` argument, try to detect platform automatically
320
302
if (
321
303
sys .platform .startswith ("linux" )
@@ -330,7 +312,7 @@ if env["platform"] == "":
330
312
elif sys .platform == "win32" :
331
313
env ["platform" ] = "windows"
332
314
333
- if env ["platform" ] != "" :
315
+ if env ["platform" ]:
334
316
print (f'Automatically detected platform: { env ["platform" ]} ' )
335
317
336
318
# Deprecated aliases kept for compatibility.
@@ -352,7 +334,7 @@ if env["platform"] not in platform_list:
352
334
353
335
if env ["platform" ] == "list" :
354
336
print (text )
355
- elif env ["platform" ] == "" :
337
+ elif not env ["platform" ]:
356
338
print_error ("Could not detect platform automatically.\n " + text )
357
339
else :
358
340
print_error (f'Invalid target platform "{ env ["platform" ]} ".\n ' + text )
@@ -434,6 +416,23 @@ env.modules_detected = modules_detected
434
416
opts .Update (env , {** ARGUMENTS , ** env .Dictionary ()})
435
417
Help (opts .GenerateHelpText (env ))
436
418
419
+
420
+ # FIXME: Tool assignment happening at this stage is a direct consequence of getting the platform logic AFTER the SCons
421
+ # environment was already been constructed. Fixing this would require a broader refactor where all options are setup
422
+ # ahead of time with native validator/converter functions.
423
+ tmppath = "./platform/" + env ["platform" ]
424
+ sys .path .insert (0 , tmppath )
425
+ import detect
426
+
427
+ custom_tools = ["default" ]
428
+ try : # Platform custom tools are optional
429
+ custom_tools = detect .get_tools (env )
430
+ except AttributeError :
431
+ pass
432
+ for tool in custom_tools :
433
+ env .Tool (tool )
434
+
435
+
437
436
# add default include paths
438
437
439
438
env .Prepend (CPPPATH = ["#" ])
@@ -515,10 +514,6 @@ if not env["deprecated"]:
515
514
if env ["precision" ] == "double" :
516
515
env .Append (CPPDEFINES = ["REAL_T_IS_DOUBLE" ])
517
516
518
- tmppath = "./platform/" + env ["platform" ]
519
- sys .path .insert (0 , tmppath )
520
- import detect
521
-
522
517
# Default num_jobs to local cpu count if not user specified.
523
518
# SCons has a peculiarity where user-specified options won't be overridden
524
519
# by SetOption, so we can rely on this to know if we should use our default.
@@ -587,7 +582,7 @@ if env["dev_mode"]:
587
582
if env ["production" ]:
588
583
env ["use_static_cpp" ] = methods .get_cmdline_bool ("use_static_cpp" , True )
589
584
env ["debug_symbols" ] = methods .get_cmdline_bool ("debug_symbols" , False )
590
- if platform_arg == "android" :
585
+ if env [ "platform" ] == "android" :
591
586
env ["swappy" ] = methods .get_cmdline_bool ("swappy" , True )
592
587
# LTO "auto" means we handle the preferred option in each platform detect.py.
593
588
env ["lto" ] = ARGUMENTS .get ("lto" , "auto" )
0 commit comments