diff options
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Builder.py | 10 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 3 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 28 | ||||
-rw-r--r-- | src/engine/SCons/SConfTests.py | 3 |
4 files changed, 32 insertions, 12 deletions
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 0f5bc76..6405da3 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -861,6 +861,16 @@ class CompositeBuilder(SCons.Util.Proxy): self.cmdgen.add_action(suffix, action) self.set_src_suffix(self.cmdgen.src_suffixes()) +def is_a_Builder(obj): + """"Returns True iff the specified obj is one of our Builder classes. + + The test is complicated a bit by the fact that CompositeBuilder + is a proxy, not a subclass of BuilderBase. + """ + return (isinstance(obj, BuilderBase) + or isinstance(obj, CompositeBuilder) + or callable(obj)) + # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index f6ba969..f840dfc 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -152,6 +152,9 @@ def _set_BUILDERS(env, key, value): except KeyError: bd = BuilderDict(kwbd, env) env._dict[key] = bd + for k, v in value.items(): + if not SCons.Builder.is_a_Builder(v): + raise SCons.Errors.UserError('%s is not a Builder.' % repr(v)) bd.update(value) def _del_SCANNERS(env, key): diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 6d91620..aa80952 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -82,7 +82,7 @@ def diff_dict(d1, d2): called_it = {} built_it = {} -class Builder: +class Builder(SCons.Builder.BuilderBase): """A dummy Builder class for testing purposes. "Building" a target is simply setting a value in the dictionary. """ @@ -1628,9 +1628,11 @@ def exists(env): assert env3['X'] == {'x1': 8, 'x2': 9}, env3['X'] assert env3['Y'] == {'y1': 10}, env3['Y'] - env4 = self.TestEnvironment(BUILDERS = {'z1' : 11}) - env4.Append(BUILDERS = {'z2' : 12}) - assert env4['BUILDERS'] == {'z1' : 11, 'z2' : 12}, env4['BUILDERS'] + z1 = Builder() + z2 = Builder() + env4 = self.TestEnvironment(BUILDERS = {'z1' : z1}) + env4.Append(BUILDERS = {'z2' : z2}) + assert env4['BUILDERS'] == {'z1' : z1, 'z2' : z2}, env4['BUILDERS'] assert hasattr(env4, 'z1') assert hasattr(env4, 'z2') @@ -1778,10 +1780,10 @@ def exists(env): assert not env1.Dictionary('ZZZ').has_key(5) # - env1 = self.TestEnvironment(BUILDERS = {'b1' : 1}) + env1 = self.TestEnvironment(BUILDERS = {'b1' : Builder()}) assert hasattr(env1, 'b1'), "env1.b1 was not set" assert env1.b1.object == env1, "b1.object doesn't point to env1" - env2 = env1.Clone(BUILDERS = {'b2' : 2}) + env2 = env1.Clone(BUILDERS = {'b2' : Builder()}) assert env2 is env2 assert env2 == env2 assert hasattr(env1, 'b1'), "b1 was mistakenly cleared from env1" @@ -2281,9 +2283,11 @@ f5: \ assert env3['X'] == {'x1': 8, 'x2' : 9}, env3['X'] assert env3['Y'] == {'y1': 10}, env3['Y'] - env4 = self.TestEnvironment(BUILDERS = {'z1' : 11}) - env4.Prepend(BUILDERS = {'z2' : 12}) - assert env4['BUILDERS'] == {'z1' : 11, 'z2' : 12}, env4['BUILDERS'] + z1 = Builder() + z2 = Builder() + env4 = self.TestEnvironment(BUILDERS = {'z1' : z1}) + env4.Prepend(BUILDERS = {'z2' : z2}) + assert env4['BUILDERS'] == {'z1' : z1, 'z2' : z2}, env4['BUILDERS'] assert hasattr(env4, 'z1') assert hasattr(env4, 'z2') @@ -2399,9 +2403,11 @@ f5: \ env2 = self.TestEnvironment(AAA = 'a', BBB = 'bbb', CCC = 'ccc') assert env1 == env2, diff_env(env1, env2) - env3 = self.TestEnvironment(BUILDERS = {'b1' : 1}) + b1 = Builder() + b2 = Builder() + env3 = self.TestEnvironment(BUILDERS = {'b1' : b1}) assert hasattr(env3, 'b1'), "b1 was not set" - env3.Replace(BUILDERS = {'b2' : 2}) + env3.Replace(BUILDERS = {'b2' : b2}) assert not hasattr(env3, 'b1'), "b1 was not cleared" assert hasattr(env3, 'b2'), "b2 was not set" diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index 5315ea3..45b6eef 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -168,7 +168,8 @@ class SConfTestCase(unittest.TestCase): sconf = self.SConf.SConf(self.scons_env, conf_dir=self.test.workpath('config.tests'), log_file=self.test.workpath('config.log')) - class MyBuilder: + import SCons.Builder + class MyBuilder(SCons.Builder.BuilderBase): def __init__(self): self.prefix = '' self.suffix = '' |