Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCons: Add only selected platform's opts to env #44433

Merged
merged 1 commit into from
Dec 17, 2020

Conversation

akien-mga
Copy link
Member

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.

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 godotengine#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.
@akien-mga akien-mga added bug topic:buildsystem cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Dec 16, 2020
@akien-mga akien-mga added this to the 4.0 milestone Dec 16, 2020
@akien-mga akien-mga requested a review from vnen as a code owner December 16, 2020 15:32
@@ -131,14 +128,13 @@ 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("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(EnumVariable("macports_clang", "Build using Clang from MacPorts", "no", ("no", "5.0", "devel")))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to platform/osx/detect.py. I think it should still work but I haven't tested.

The same can't be done easily for vsproj which is used in SConstruct and assumed to be in env (could be changed but that's a more significant refactoring).

# Add platform-specific options.
for opt in detect.get_opts():
opts.Add(opt)
opts.Update(env_base)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call opts.Update() three times in total when a platform is selected, and twice otherwise. I'm not sure if this has any significant impact on build time (doesn't seem to have much for scons --help on Linux at least).

On the other hand we generate the Help() only once as I remember this as being significant (CC @Xrayez to test and confirm maybe, I remember that all this is slower on Windows).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating environment and generating help text have little performance impact, it's more about parsing Python scripts, which just happens to be slow on Windows...

@akien-mga akien-mga merged commit ae03993 into godotengine:master Dec 17, 2020
@akien-mga akien-mga deleted the scons-fix-platform-opts branch December 17, 2020 08:56
@bruvzg
Copy link
Member

bruvzg commented Dec 17, 2020

Seems to break build on macOS completely, with this change env["platform"] is null, camera module build fails with ar: no archive members specified error since no source files are added, but it's still trying to link static library.

@akien-mga
Copy link
Member Author

Yep, I'll push a fix in a minute. Things were pretty brittle due to the p alias or autodetection logic, and this exposed it as a bug. CI passed because it uses platform explicitly.

akien-mga added a commit to akien-mga/godot that referenced this pull request Dec 17, 2020
Fixes a pre-existing bug that godotengine#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. godotengine#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 godotengine#44448 and other breakages induced by godotengine#44433.
@akien-mga
Copy link
Member Author

Cherry-picked for 3.2.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Dec 29, 2020
akien-mga added a commit to akien-mga/godot that referenced this pull request Dec 29, 2020
Fixes a pre-existing bug that godotengine#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. godotengine#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 godotengine#44448 and other breakages induced by godotengine#44433.

(cherry picked from commit 8f66039)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Platform-specific options in detect.py can override each other
3 participants