From 131b315f7630ad6f46f7e29b02a9467947617297 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 19 Mar 2005 04:09:34 +0000 Subject: [PATCH] Fix Builders with empty source lists. (Stanislav Baranov) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1260 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 2 ++ src/engine/SCons/Builder.py | 10 ++++++++-- src/engine/SCons/BuilderTests.py | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index d6edd56d..ae16481b 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -29,6 +29,8 @@ RELEASE 0.97 - XXX - Make it possible to support with custom Alias (sub-)classes. + - Allow Builders to take empty source lists when called. + From Timothee Besset: - Add support for Objective C/C++ .m and .mm file suffixes (for diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index a20757e3..7069ef0b 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -152,6 +152,9 @@ class DictCmdGenerator(SCons.Util.Selector): self[suffix] = action def __call__(self, target, source, env, for_signature): + if not source: + return [] + ext = None for src in map(str, source): my_ext = SCons.Util.splitext(src)[1] @@ -506,8 +509,11 @@ class BuilderBase: t_from_s = slist[0].target_from_source except AttributeError: raise UserError("Do not know how to create a target from source `%s'" % slist[0]) - splitext = lambda S,self=self,env=env: self.splitext(S,env) - tlist = [ t_from_s(pre, suf, splitext) ] + except IndexError: + tlist = [] + else: + splitext = lambda S,self=self,env=env: self.splitext(S,env) + tlist = [ t_from_s(pre, suf, splitext) ] else: target = _adjustixes(target, pre, suf) tlist = env.arg2nodes(target, self.target_factory) diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 8d60d335..09927f1c 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -219,6 +219,9 @@ class BuilderTestCase(unittest.TestCase): target_factory=MyNode, source_factory=MyNode) + tgt = builder(env, source=[]) + assert tgt == [], tgt + n1 = MyNode("n1") n2 = MyNode("n2") builder(env, target = n1, source = n2) @@ -667,6 +670,10 @@ class BuilderTestCase(unittest.TestCase): env = Environment() builder = SCons.Builder.Builder(action = function2) + + tgts = builder(env, source=[]) + assert tgts == [], tgts + tgts = builder(env, target = [outfile, outfile2], source = 'foo') for t in tgts: t.prepare() @@ -715,6 +722,9 @@ class BuilderTestCase(unittest.TestCase): src_builder = builder1, src_suffix = '.foo') + tgt = builder2(env, source=[]) + assert tgt == [], tgt + tgt = builder2(env, target='baz', source=['test.bar', 'test2.foo', 'test3.txt'])[0] assert str(tgt.sources[0]) == 'test.foo', str(tgt.sources[0]) @@ -763,15 +773,21 @@ class BuilderTestCase(unittest.TestCase): '.bar' : func_action, '$BAR_SUFFIX' : func_action, '$FOO_SUFFIX' : func_action }) + + tgt = builder(env, source=[]) + assert tgt == [], tgt assert isinstance(builder, SCons.Builder.CompositeBuilder) assert isinstance(builder.action, SCons.Action.CommandGeneratorAction) + tgt = builder(env, target='test1', source='test1.foo')[0] assert isinstance(tgt.builder, SCons.Builder.BuilderBase) assert tgt.builder.action is builder.action + tgt = builder(env, target='test2', source='test1.bar')[0] assert isinstance(tgt.builder, SCons.Builder.BuilderBase) assert tgt.builder.action is builder.action + flag = 0 tgt = builder(env, target='test3', source=['test2.bar', 'test1.foo'])[0] try: -- 2.26.2