Fix Builders with empty source lists. (Stanislav Baranov)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 19 Mar 2005 04:09:34 +0000 (04:09 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 19 Mar 2005 04:09:34 +0000 (04:09 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1260 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py

index d6edd56dde97a35dafb63fd60225a1bcd3ed3c4c..ae16481b5b6b4d4ebbd2c6abeb4bb3b5b74bc5f6 100644 (file)
@@ -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
index a20757e360082feca32af88041ccedc37e4f0d69..7069ef0b2627da6fb1878c8dc37ae143040315bd 100644 (file)
@@ -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)
index 8d60d335836f9d75385812d2ff33a893ac4817a9..09927f1c72d7ab74ac44f80b0a795a3034292320 100644 (file)
@@ -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: