diff options
author | Steven Knight <knight@baldmt.com> | 2001-12-14 00:13:24 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2001-12-14 00:13:24 (GMT) |
commit | c4227cb69b70b6fe1b9d1783bdbd9530d0c526ce (patch) | |
tree | fe5bc371a3fb21b9cb224d6b75c0ed51ab0c560d /src/engine | |
parent | 6df6db482f39e2a36f69b48f2240f49b29ab762a (diff) | |
download | SCons-c4227cb69b70b6fe1b9d1783bdbd9530d0c526ce.zip SCons-c4227cb69b70b6fe1b9d1783bdbd9530d0c526ce.tar.gz SCons-c4227cb69b70b6fe1b9d1783bdbd9530d0c526ce.tar.bz2 |
Fix for copying BuilderWrapper objects within Environments (courtesy Charles Crain).
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Environment.py | 74 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 10 |
2 files changed, 48 insertions, 36 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 69455e7..9f78a65 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -76,40 +76,12 @@ class Environment: def __init__(self, **kw): import SCons.Defaults self._dict = our_deepcopy(SCons.Defaults.ConstructionEnvironment) - if kw.has_key('BUILDERS') and type(kw['BUILDERS']) != type([]): - kw['BUILDERS'] = [kw['BUILDERS']] - if kw.has_key('SCANNERS') and type(kw['SCANNERS']) != type([]): - kw['SCANNERS'] = [kw['SCANNERS']] - self._dict.update(our_deepcopy(kw)) - - class BuilderWrapper: - """Wrapper class that allows an environment to - be associated with a Builder at instantiation. - """ - def __init__(self, env, builder): - self.env = env - self.builder = builder - - def __call__(self, target = None, source = None): - return self.builder(self.env, target, source) - - # This allows a Builder to be executed directly - # through the Environment to which it's attached. - # In practice, we shouldn't need this, because - # builders actually get executed through a Node. - # But we do have a unit test for this, and can't - # yet rule out that it would be useful in the - # future, so leave it for now. - def execute(self, **kw): - kw['env'] = self - apply(self.builder.execute, (), kw) - - for b in self._dict['BUILDERS']: - setattr(self, b.name, BuilderWrapper(self, b)) - - for s in self._dict['SCANNERS']: - setattr(self, s.name, s) - + apply(self.Update, (), kw) + + def __mungeDict(self): + """Take care of any special attributes in our dictionary.""" + + def __cmp__(self, other): return cmp(self._dict, other._dict) @@ -137,6 +109,40 @@ class Environment: construction variables and/or values. """ self._dict.update(our_deepcopy(kw)) + if self._dict.has_key('BUILDERS') and \ + type(self._dict['BUILDERS']) != type([]): + self._dict['BUILDERS'] = [self._dict['BUILDERS']] + if self._dict.has_key('SCANNERS') and \ + type(self._dict['SCANNERS']) != type([]): + self._dict['SCANNERS'] = [self._dict['SCANNERS']] + + class BuilderWrapper: + """Wrapper class that allows an environment to + be associated with a Builder at instantiation. + """ + def __init__(self, env, builder): + self.env = env + self.builder = builder + + def __call__(self, target = None, source = None): + return self.builder(self.env, target, source) + + # This allows a Builder to be executed directly + # through the Environment to which it's attached. + # In practice, we shouldn't need this, because + # builders actually get executed through a Node. + # But we do have a unit test for this, and can't + # yet rule out that it would be useful in the + # future, so leave it for now. + def execute(self, **kw): + kw['env'] = self.env + apply(self.builder.execute, (), kw) + + for b in self._dict['BUILDERS']: + setattr(self, b.name, BuilderWrapper(self, b)) + + for s in self._dict['SCANNERS']: + setattr(self, s.name, s) def Depends(self, target, dependency): """Explicity specify that 'target's depend on 'dependency'.""" diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 3ba8ad4..65eb510 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -87,7 +87,8 @@ class EnvironmentTestCase(unittest.TestCase): assert built_it['out1'] built_it = {} - env3 = Environment(BUILDERS = [b1, b2]) + env3 = Environment() + env3.Update(BUILDERS = [b1, b2]) env3.builder1.execute(target = 'out1') env3.builder2.execute(target = 'out2') env3.builder1.execute(target = 'out3') @@ -95,6 +96,10 @@ class EnvironmentTestCase(unittest.TestCase): assert built_it['out2'] assert built_it['out3'] + env4 = env3.Copy() + assert env4.builder1.env is env4 + assert env4.builder2.env is env4 + def test_Scanners(self): """Test Scanner execution through different environments @@ -118,7 +123,8 @@ class EnvironmentTestCase(unittest.TestCase): assert scanned_it['out1'] scanned_it = {} - env3 = Environment(SCANNERS = [s1, s2]) + env3 = Environment() + env3.Update(SCANNERS = [s1, s2]) env3.scanner1.scan(filename = 'out1') env3.scanner2.scan(filename = 'out2') env3.scanner1.scan(filename = 'out3') |