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: Preserve Environment values when updating Variables #91792

Conversation

akien-mga
Copy link
Member

@akien-mga akien-mga commented May 10, 2024

Finally reading the docs for SCons.Variables.Update let me find this optional parameter, which solves the hacks and pain we've dealt with for years:

args (optional) – a dictionary of keys and values to update in env.
If omitted, uses the variables from the commandline.

By passing the environment itself, we preserve the values we've overridden in SConstruct or detect.py.

Might fix a number of reported issues.

CC @Repiteo

@akien-mga akien-mga added bug topic:buildsystem needs testing cherrypick:3.x Considered for cherry-picking into a future 3.x release cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels May 10, 2024
@akien-mga akien-mga added this to the 4.3 milestone May 10, 2024
@akien-mga akien-mga requested a review from a team as a code owner May 10, 2024 10:34
@akien-mga akien-mga force-pushed the scons-preserve-env-values-when-updating-variables branch from 8212fc1 to ad8ae4a Compare May 10, 2024 10:35
@AThousandShips
Copy link
Member

AThousandShips commented May 10, 2024

Seems to ignore some options, it makes it ignore the sanitizer args somehow

@AThousandShips

This comment was marked as outdated.

@AThousandShips
Copy link
Member

Tried a few different approaches but couldn't make it not ignore command line options, it seems unfortunately that this option doesn't allow updating from command line for some arguments, unsure how this could be fixed

@Repiteo
Copy link
Contributor

Repiteo commented May 10, 2024

It sounds like it's meant to update the command line arguments by default, but either that's excluded when passing env or the means by which they're parsed is somehow flawed on our end. Gonna do a few tests to see what makes this tick.

@AThousandShips
Copy link
Member

AThousandShips commented May 10, 2024

Tested and this seems to work:

env_copy = env.Clone()
opts.Update(env_copy)
opts.Update(env, env_copy)

Not sure how to detect the broken stuff without the handling of platform, but it seems to work, unsure if anything is missing though

Edit: Doesn't seem to correctly catch if platform option is left empty, but that might be something that can be fixed with this

Edit 2:

env_copy = env.Clone()
opts.Update(env_copy)
env_copy["platform"] = env["platform"]
opts.Update(env, env_copy)

Seems to solve that part, but feels like we're circling around to hackiness again, but unsure exactly what's missing

@akien-mga
Copy link
Member Author

How about something like this? Seems to work in a few tests, though I need to check with the follow-up PRs based on this one.

diff --git a/SConstruct b/SConstruct
index 5f1c50876e..8ce504ae2b 100644
--- a/SConstruct
+++ b/SConstruct
@@ -362,7 +362,7 @@ if env["platform"] in platform_opts:
         opts.Add(opt)
 
 # Update the environment to take platform-specific options into account.
-opts.Update(env, env)
+opts.Update(env, {**ARGUMENTS, **env})
 
 # Detect modules.
 modules_detected = OrderedDict()
@@ -422,7 +422,7 @@ for name, path in modules_detected.items():
 env.modules_detected = modules_detected
 
 # Update the environment again after all the module options are added.
-opts.Update(env, env)
+opts.Update(env, {**ARGUMENTS, **env})
 Help(opts.GenerateHelpText(env))
 
 # add default include paths

@AThousandShips
Copy link
Member

AThousandShips commented May 10, 2024

That does seem to work, it handles platform being empty correctly, will see how it behaves for other cases

Edit: It seems to work and it now handles #91791 correctly

Finally reading the docs for `SCons.Variables.Update` let me find this optional
parameter, which solves the hacks and pain we've dealt with for years:

> args (optional) – a dictionary of keys and values to update in env.
> If omitted, uses the variables from the commandline.

By passing the environment itself, we preserve the values we've overridden in
`SConstruct` or `detect.py`.
@akien-mga akien-mga force-pushed the scons-preserve-env-values-when-updating-variables branch from ad8ae4a to d4d0e34 Compare May 10, 2024 14:57
@Repiteo
Copy link
Contributor

Repiteo commented May 10, 2024

That does the trick!

@akien-mga akien-mga marked this pull request as ready for review May 10, 2024 15:18
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Works correctly in my testing

@akien-mga akien-mga merged commit 4219af2 into godotengine:master May 13, 2024
16 checks passed
@akien-mga akien-mga deleted the scons-preserve-env-values-when-updating-variables branch May 13, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:3.x Considered for cherry-picking into a future 3.x release cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release needs testing topic:buildsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants