Clone() does not honor 'variables' argument
Describe the bug As per discussion with bdbaddog on Discord around 2020-03-12, the following SConstruct does not work as expected:
vars = Variables()
vars.Add(BoolVariable('MYTEST', 'bla',default=False))
env = Environment(variables=vars)
print(env.get('MYTEST'))
env.Replace(MYTEST=True)
print(env.get('MYTEST'))
# passing variables to Clone() does not seem to have an effect
# and there is no indication of failure to update.
env1 = env.Clone(variables=vars)
# after Clone(), the expected value of MYTEST is 'False' because 'vars' has
# been passed into the clone. But we have to enforce that env1 is using the
# values from vars, not from env.
# commenting out the Update call proves this ...
vars.Update(env1)
print(env1.get('MYTEST'))``
Required information
- Link to SCons Users thread discussing your issue: None, discussed on Discord
- Version of SCons: 3.1.2
- Version of Python: 3.6.8
- Which python distribution if applicable (python.org, cygwin, anaconda, macports, brew,etc): WSL Ubuntu 18.04
- How you installed SCons: pip
- What Platform are you on? (Linux/Windows and which version): WSL Ubuntu 18.04
- How to reproduce your issue? Run the above SConstruct, the expected 3rd line printout is 'True' with vars.Update(env1) disabled - env1 should hold 'MYTEST' as False because that's the default from line 2 of the script.
- How you invoke scons (The command line you're using "scons --flags some_arguments") scons
Thanks for filing a complete Issue! Can't make any promises when we'll get to this, but we have sufficient info to properly understand the issue now.
Quick look - there's no code for it. Environment recognizes variables separate from the generic kwargs, and folds them in; Clone does not.
Re-reading my initial report and Mats' quick look makes me think that this could be handled in 2 steps:
- make
Clone()report some error/warning that it was unable to parse/evaluate provided named arguments. This behaviour was most disturbing to me when trying to passvariablesinto a clone - it took me quite a while to figure thatvariablesis ignored silently. - make
Clone()behave much asEnvironment()- to me this would be SCons'ic.
@pauschar - Unfortunately the first option you list is really not viable. As you can specify any variable to be added or overwritten(from the env being cloned) to the cloned env.