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

Bjacklyn/fix keyerror when cloning override environment with boolean override GitHub #4041

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SCons/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,9 @@ def __init__(self, subject, overrides=None):

# Methods that make this class act like a proxy.
def __getattr__(self, name):
if '__subject' not in self.__dict__:
setattr(self.__dict__, '__subject', {})

attr = getattr(self.__dict__['__subject'], name)
# Here we check if attr is one of the Wrapper classes. For
# example when a pseudo-builder is being called from an
Expand All @@ -2396,6 +2399,9 @@ def __getattr__(self, name):
return attr

def __setattr__(self, name, value):
if '__subject' not in self.__dict__:
setattr(self.__dict__, '__subject', {})

setattr(self.__dict__['__subject'], name, value)

# Methods that make this class act like a dictionary.
Expand Down
11 changes: 11 additions & 0 deletions SCons/EnvironmentTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3887,6 +3887,17 @@ def test_parse_flags(self):
assert env['CPPDEFINES'] == 'FOO', env['CPPDEFINES']
assert env2['CPPDEFINES'] == ['FOO','BAR'], env2['CPPDEFINES']

def test_Clone_with_boolean_override(self):
"""Test cloning an instance of OverrideEnvironment"""
env = Environment()
env._dict = {'BOOLEAN': None}
env2 = OverrideEnvironment(env, {'BOOLEAN': True})
env3 = OverrideEnvironment(env2, {'BOOLEAN': False})

clone_env2 = env2.Clone(BOOLEAN=False)
assert clone_env2['BOOLEAN'] == False, clone_env2['BOOLEAN']
clone_env3 = env3.Clone(BOOLEAN=True)
assert clone_env3['BOOLEAN'] == True, clone_env3['BOOLEAN']


class NoSubstitutionProxyTestCase(unittest.TestCase,TestEnvironmentFixture):
Expand Down