2
0
Эх сурвалжийг харах

SCons: Add only selected platform's opts to env

Otherwise we can get situations where platform-specific opts with the same name
can override each other depending on the order at which platforms are parsed,
as was the case with `use_static_cpp` in Linux/Windows.

Fixes #44304.

This also has the added benefit that the `scons --help` output will now only
include the options which are relevant for the selected (or detected) platform.

(cherry picked from commit 0f84d8dc497e73a8ad21ae51bc4912082f2d2454)
Rémi Verschelde 4 жил өмнө
parent
commit
60959b085d

+ 11 - 13
SConstruct

@@ -17,7 +17,6 @@ from platform_methods import run_in_subprocess
 # scan possible build platforms
 # scan possible build platforms
 
 
 platform_list = []  # list of platforms
 platform_list = []  # list of platforms
-platform_opts = {}  # options for each platform
 platform_flags = {}  # flags for each platform
 platform_flags = {}  # flags for each platform
 
 
 active_platforms = []
 active_platforms = []
@@ -44,7 +43,6 @@ for x in sorted(glob.glob("platform/*")):
         x = x.replace("platform/", "")  # rest of world
         x = x.replace("platform/", "")  # rest of world
         x = x.replace("platform\\", "")  # win32
         x = x.replace("platform\\", "")  # win32
         platform_list += [x]
         platform_list += [x]
-        platform_opts[x] = detect.get_opts()
         platform_flags[x] = detect.get_flags()
         platform_flags[x] = detect.get_flags()
     sys.path.remove(tmppath)
     sys.path.remove(tmppath)
     sys.modules.pop("detect")
     sys.modules.pop("detect")
@@ -113,7 +111,6 @@ opts.Add(EnumVariable("target", "Compilation target", "debug", ("debug", "releas
 opts.Add(EnumVariable("optimize", "Optimization type", "speed", ("speed", "size")))
 opts.Add(EnumVariable("optimize", "Optimization type", "speed", ("speed", "size")))
 opts.Add(BoolVariable("tools", "Build the tools (a.k.a. the Godot editor)", True))
 opts.Add(BoolVariable("tools", "Build the tools (a.k.a. the Godot editor)", True))
 opts.Add(BoolVariable("use_lto", "Use link-time optimization", False))
 opts.Add(BoolVariable("use_lto", "Use link-time optimization", False))
-opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise epsilon (debug option)", False))
 
 
 # Components
 # Components
 opts.Add(BoolVariable("deprecated", "Enable deprecated features", True))
 opts.Add(BoolVariable("deprecated", "Enable deprecated features", True))
@@ -130,7 +127,6 @@ opts.Add(BoolVariable("werror", "Treat compiler warnings as errors", False))
 opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False))
 opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False))
 opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all generated binary files", "")
 opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all generated binary files", "")
 opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False))
 opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False))
-opts.Add(EnumVariable("macports_clang", "Build using Clang from MacPorts", "no", ("no", "5.0", "devel")))
 opts.Add(
 opts.Add(
     BoolVariable(
     BoolVariable(
         "split_libmodules",
         "split_libmodules",
@@ -142,9 +138,9 @@ opts.Add(BoolVariable("disable_3d", "Disable 3D nodes for a smaller executable",
 opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False))
 opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False))
 opts.Add(BoolVariable("no_editor_splash", "Don't use the custom splash screen for the editor", False))
 opts.Add(BoolVariable("no_editor_splash", "Don't use the custom splash screen for the editor", False))
 opts.Add("system_certs_path", "Use this path as SSL certificates default for editor (for package maintainers)", "")
 opts.Add("system_certs_path", "Use this path as SSL certificates default for editor (for package maintainers)", "")
+opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise epsilon (debug option)", False))
 
 
 # Thirdparty libraries
 # Thirdparty libraries
-# opts.Add(BoolVariable('builtin_assimp', "Use the built-in Assimp library", True))
 opts.Add(BoolVariable("builtin_bullet", "Use the built-in Bullet library", True))
 opts.Add(BoolVariable("builtin_bullet", "Use the built-in Bullet library", True))
 opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundles", True))
 opts.Add(BoolVariable("builtin_certs", "Use the built-in SSL certificates bundles", True))
 opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
 opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
@@ -176,13 +172,6 @@ opts.Add("CFLAGS", "Custom flags for the C compiler")
 opts.Add("CXXFLAGS", "Custom flags for the C++ compiler")
 opts.Add("CXXFLAGS", "Custom flags for the C++ compiler")
 opts.Add("LINKFLAGS", "Custom flags for the linker")
 opts.Add("LINKFLAGS", "Custom flags for the linker")
 
 
-# add platform specific options
-
-for k in platform_opts.keys():
-    opt_list = platform_opts[k]
-    for o in opt_list:
-        opts.Add(o)
-
 # Update the environment now as the "custom_modules" option may be
 # Update the environment now as the "custom_modules" option may be
 # defined in a file rather than specified via the command line.
 # defined in a file rather than specified via the command line.
 opts.Update(env_base)
 opts.Update(env_base)
@@ -225,7 +214,6 @@ methods.write_modules(modules_detected)
 
 
 # Update the environment again after all the module options are added.
 # Update the environment again after all the module options are added.
 opts.Update(env_base)
 opts.Update(env_base)
-Help(opts.GenerateHelpText(env_base))
 
 
 # add default include paths
 # add default include paths
 
 
@@ -297,6 +285,12 @@ if selected_platform in platform_list:
     sys.path.insert(0, tmppath)
     sys.path.insert(0, tmppath)
     import detect
     import detect
 
 
+    # Add platform-specific options.
+    for opt in detect.get_opts():
+        opts.Add(opt)
+    opts.Update(env_base)
+    Help(opts.GenerateHelpText(env_base))
+
     if "create" in dir(detect):
     if "create" in dir(detect):
         env = detect.create(env_base)
         env = detect.create(env_base)
     else:
     else:
@@ -629,6 +623,10 @@ elif selected_platform != "":
     else:
     else:
         sys.exit(255)
         sys.exit(255)
 
 
+else:
+    # Update help to include options.
+    Help(opts.GenerateHelpText(env_base))
+
 # The following only makes sense when the 'env' is defined, and assumes it is.
 # The following only makes sense when the 'env' is defined, and assumes it is.
 if "env" in locals():
 if "env" in locals():
     methods.show_progress(env)
     methods.show_progress(env)

+ 0 - 3
platform/iphone/detect.py

@@ -12,7 +12,6 @@ def get_name():
 
 
 
 
 def can_build():
 def can_build():
-
     if sys.platform == "darwin":
     if sys.platform == "darwin":
         if get_darwin_sdk_version("iphone") < 13.0:
         if get_darwin_sdk_version("iphone") < 13.0:
             print("Detected iOS SDK version older than 13")
             print("Detected iOS SDK version older than 13")
@@ -43,14 +42,12 @@ def get_opts():
 
 
 
 
 def get_flags():
 def get_flags():
-
     return [
     return [
         ("tools", False),
         ("tools", False),
     ]
     ]
 
 
 
 
 def configure(env):
 def configure(env):
-
     ## Build type
     ## Build type
 
 
     if env["target"].startswith("release"):
     if env["target"].startswith("release"):

+ 1 - 3
platform/osx/detect.py

@@ -12,7 +12,6 @@ def get_name():
 
 
 
 
 def can_build():
 def can_build():
-
     if sys.platform == "darwin" or ("OSXCROSS_ROOT" in os.environ):
     if sys.platform == "darwin" or ("OSXCROSS_ROOT" in os.environ):
         return True
         return True
 
 
@@ -25,6 +24,7 @@ def get_opts():
     return [
     return [
         ("osxcross_sdk", "OSXCross SDK version", "darwin14"),
         ("osxcross_sdk", "OSXCross SDK version", "darwin14"),
         ("MACOS_SDK_PATH", "Path to the macOS SDK", ""),
         ("MACOS_SDK_PATH", "Path to the macOS SDK", ""),
+        EnumVariable("macports_clang", "Build using Clang from MacPorts", "no", ("no", "5.0", "devel")),
         EnumVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", "yes", ("yes", "no")),
         EnumVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", "yes", ("yes", "no")),
         BoolVariable("separate_debug_symbols", "Create a separate file containing debugging symbols", False),
         BoolVariable("separate_debug_symbols", "Create a separate file containing debugging symbols", False),
         BoolVariable("use_ubsan", "Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)", False),
         BoolVariable("use_ubsan", "Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)", False),
@@ -34,12 +34,10 @@ def get_opts():
 
 
 
 
 def get_flags():
 def get_flags():
-
     return []
     return []
 
 
 
 
 def configure(env):
 def configure(env):
-
     ## Build type
     ## Build type
 
 
     if env["target"] == "release":
     if env["target"] == "release":

+ 0 - 2
platform/server/detect.py

@@ -21,7 +21,6 @@ def get_program_suffix():
 
 
 
 
 def can_build():
 def can_build():
-
     if os.name != "posix":
     if os.name != "posix":
         return False
         return False
 
 
@@ -45,7 +44,6 @@ def get_opts():
 
 
 
 
 def get_flags():
 def get_flags():
-
     return []
     return []
 
 
 
 

+ 0 - 2
platform/uwp/detect.py

@@ -30,7 +30,6 @@ def get_opts():
 
 
 
 
 def get_flags():
 def get_flags():
-
     return [
     return [
         ("tools", False),
         ("tools", False),
         ("xaudio2", True),
         ("xaudio2", True),
@@ -39,7 +38,6 @@ def get_flags():
 
 
 
 
 def configure(env):
 def configure(env):
-
     env.msvc = True
     env.msvc = True
 
 
     if env["bits"] != "default":
     if env["bits"] != "default":

+ 1 - 3
platform/windows/detect.py

@@ -67,7 +67,7 @@ def get_opts():
         EnumVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", "yes", ("yes", "no")),
         EnumVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", "yes", ("yes", "no")),
         BoolVariable("separate_debug_symbols", "Create a separate file containing debugging symbols", False),
         BoolVariable("separate_debug_symbols", "Create a separate file containing debugging symbols", False),
         ("msvc_version", "MSVC version to use. Ignored if VCINSTALLDIR is set in shell env.", None),
         ("msvc_version", "MSVC version to use. Ignored if VCINSTALLDIR is set in shell env.", None),
-        BoolVariable("use_mingw", "Use the Mingw compiler, even if MSVC is installed. Only used on Windows.", False),
+        BoolVariable("use_mingw", "Use the Mingw compiler, even if MSVC is installed.", False),
         BoolVariable("use_llvm", "Use the LLVM compiler", False),
         BoolVariable("use_llvm", "Use the LLVM compiler", False),
         BoolVariable("use_thinlto", "Use ThinLTO", False),
         BoolVariable("use_thinlto", "Use ThinLTO", False),
         BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True),
         BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True),
@@ -75,12 +75,10 @@ def get_opts():
 
 
 
 
 def get_flags():
 def get_flags():
-
     return []
     return []
 
 
 
 
 def build_res_file(target, source, env):
 def build_res_file(target, source, env):
-
     if env["bits"] == "32":
     if env["bits"] == "32":
         cmdbase = env["mingw_prefix_32"]
         cmdbase = env["mingw_prefix_32"]
     else:
     else:

+ 0 - 3
platform/x11/detect.py

@@ -13,7 +13,6 @@ def get_name():
 
 
 
 
 def can_build():
 def can_build():
-
     if os.name != "posix" or sys.platform == "darwin":
     if os.name != "posix" or sys.platform == "darwin":
         return False
         return False
 
 
@@ -81,12 +80,10 @@ def get_opts():
 
 
 
 
 def get_flags():
 def get_flags():
-
     return []
     return []
 
 
 
 
 def configure(env):
 def configure(env):
-
     ## Build type
     ## Build type
 
 
     if env["target"] == "release":
     if env["target"] == "release":