SCons: Fix build with p alias or platform auto-detection

Fixes a pre-existing bug that #44433 exposed.

It's pretty hacky, but we use `platform` in `env` both as an optional command
line option (instead it can be autodetected, or passed via the `p` alias, and
on Linux it might be overridden if you pass one of the convenience alias
values), and as the reference value for what platform we're building on.

Thus we override `env_base["platform"]` with the autodetected or validated
platform, but any call to `opts.Update(env_base)` overrides it with the
original command line option... causing e.g. #44448.

The proper fix would be to refactor all this so that we don't reuse
`env["platform"]` for platform detection (it could instead be e.g.
`env.platform` as a member variable which holds the validated value),
but for now I'm tapering over the immediate breakage.

Fixes #44448 and other breakages induced by #44433.
This commit is contained in:
Rémi Verschelde 2020-12-17 11:30:19 +01:00
parent f3dccf5891
commit 8f660393fe
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -17,6 +17,7 @@ import glsl_builders
# 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 = []
@ -43,6 +44,7 @@ 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")
@ -172,10 +174,55 @@ 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")
# Update the environment now as the "custom_modules" option may be # Update the environment to have all above options defined
# defined in a file rather than specified via the command line. # in following code (especially platform and custom_modules).
opts.Update(env_base) opts.Update(env_base)
# Platform selection: validate input, and add options.
selected_platform = ""
if env_base["platform"] != "":
selected_platform = env_base["platform"]
elif env_base["p"] != "":
selected_platform = env_base["p"]
else:
# Missing `platform` argument, try to detect platform automatically
if sys.platform.startswith("linux"):
selected_platform = "linuxbsd"
elif sys.platform == "darwin":
selected_platform = "osx"
elif sys.platform == "win32":
selected_platform = "windows"
else:
print("Could not detect platform automatically. Supported platforms:")
for x in platform_list:
print("\t" + x)
print("\nPlease run SCons again and select a valid platform: platform=<string>")
if selected_platform != "":
print("Automatically detected platform: " + selected_platform)
if selected_platform in ["linux", "bsd", "x11"]:
if selected_platform == "x11":
# Deprecated alias kept for compatibility.
print('Platform "x11" has been renamed to "linuxbsd" in Godot 4.0. Building for platform "linuxbsd".')
# Alias for convenience.
selected_platform = "linuxbsd"
# Make sure to update this to the found, valid platform as it's used through the buildsystem as the reference.
# It should always be re-set after calling `opts.Update()` otherwise it uses the original input value.
env_base["platform"] = selected_platform
# Add platform-specific options.
if selected_platform in platform_opts:
for opt in platform_opts[selected_platform]:
opts.Add(opt)
# Update the environment to take platform-specific options into account.
opts.Update(env_base)
env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
# Detect modules. # Detect modules.
modules_detected = OrderedDict() modules_detected = OrderedDict()
module_search_paths = ["modules"] # Built-in path. module_search_paths = ["modules"] # Built-in path.
@ -214,6 +261,8 @@ 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)
env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
Help(opts.GenerateHelpText(env_base))
# add default include paths # add default include paths
@ -249,52 +298,11 @@ if env_base["no_editor_splash"]:
if not env_base["deprecated"]: if not env_base["deprecated"]:
env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"]) env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"])
env_base.platforms = {}
selected_platform = ""
if env_base["platform"] != "":
selected_platform = env_base["platform"]
elif env_base["p"] != "":
selected_platform = env_base["p"]
env_base["platform"] = selected_platform
else:
# Missing `platform` argument, try to detect platform automatically
if sys.platform.startswith("linux"):
selected_platform = "linuxbsd"
elif sys.platform == "darwin":
selected_platform = "osx"
elif sys.platform == "win32":
selected_platform = "windows"
else:
print("Could not detect platform automatically. Supported platforms:")
for x in platform_list:
print("\t" + x)
print("\nPlease run SCons again and select a valid platform: platform=<string>")
if selected_platform != "":
print("Automatically detected platform: " + selected_platform)
env_base["platform"] = selected_platform
if selected_platform in ["linux", "bsd", "x11"]:
if selected_platform == "x11":
# Deprecated alias kept for compatibility.
print('Platform "x11" has been renamed to "linuxbsd" in Godot 4.0. Building for platform "linuxbsd".')
# Alias for convenience.
selected_platform = "linuxbsd"
env_base["platform"] = selected_platform
if selected_platform in platform_list: if selected_platform in platform_list:
tmppath = "./platform/" + selected_platform tmppath = "./platform/" + selected_platform
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:
@ -664,10 +672,6 @@ elif selected_platform != "":
else: else:
Exit(255) 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)