Issue 1681: Fix the ability of add_src_builder() to handle arbitrary
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 11 Sep 2008 01:28:15 +0000 (01:28 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 11 Sep 2008 01:28:15 +0000 (01:28 +0000)
builder objects by eliminating unintentional re-use of a class
list for the src_builder attribute.

git-svn-id: http://scons.tigris.org/svn/scons/trunk@3385 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
test/Builder/add_src_builder.py [new file with mode: 0644]

index 1055398f622a9e7a958818d52f0cd784fba92ec9..f3a7115d31f7bd33657b379158ba1957f8330140 100644 (file)
 
 RELEASE 1.X - XXX
 
+  From Ian P. Cardenas:
+
+    - Fix Glob() polluting LIBPATH by returning copy of list
+
+  From Steven Knight:
+
+    - Fix the ability of the add_src_builder() method to add a new
+      source builder to any other builder.
+
   From Gary Oberbrunner:
 
     - Make Glob() sort the returned list of Files or Nodes
       to prevent spurious rebuilds.
 
-  From Ian P. Cardenas:
-
-    - Fix Glob() polluting LIBPATH by returning copy of list
-
 
 
 RELEASE 1.0.1 - Sat, 06 Sep 2008 07:29:34 -0700
index 2e10a8d2052a6d815aff0021bbfeb9b42162dec3..45bd99a1e947ed4209e8e9d3474d00da1738e74f 100644 (file)
@@ -363,7 +363,7 @@ class BuilderBase:
                         name = None,
                         chdir = _null,
                         is_explicit = 1,
-                        src_builder = [],
+                        src_builder = None,
                         ensure_suffix = False,
                         **overrides):
         if __debug__: logInstanceCreation(self, 'Builder.BuilderBase')
@@ -410,7 +410,9 @@ class BuilderBase:
             self.executor_kw['chdir'] = chdir
         self.is_explicit = is_explicit
 
-        if not SCons.Util.is_List(src_builder):
+        if src_builder is None:
+            src_builder = []
+        elif not SCons.Util.is_List(src_builder):
             src_builder = [ src_builder ]
         self.src_builder = src_builder
 
index 1b7bc380412c3267cb92026958ea786f5616d63b..eeb3b3f1bea7317d98a1ffd133bc3559a3739d60 100644 (file)
@@ -840,6 +840,9 @@ class BuilderTestCase(unittest.TestCase):
         s = map(str, tgt.sources[0].sources)
         assert s == ['aaa.bar'], s
 
+        builder3 = SCons.Builder.Builder(action='bld3')
+        assert not builder3.src_builder is builder1.src_builder
+
         builder4 = SCons.Builder.Builder(action='bld4',
                                          src_suffix='.i',
                                          suffix='_wrap.c')
diff --git a/test/Builder/add_src_builder.py b/test/Builder/add_src_builder.py
new file mode 100644 (file)
index 0000000..f67acc0
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that we can call add_src_builder() to add a builder to
+another on the fly.
+
+This used to trigger infinite recursion (issue 1681) because the
+same src_builder list object was being re-used between all Builder
+objects that weren't initialized with a separate src_builder.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+copy_out = Builder(action = Copy('$TARGET', '$SOURCE'),
+                                 suffix = '.out',
+                                 src_suffix = '.mid')
+
+copy_mid = Builder(action = Copy('$TARGET', '$SOURCE'),
+                                 suffix = '.mid', \
+                                 src_suffix = '.in')
+
+env = Environment()
+env['BUILDERS']['CopyOut'] = copy_out
+env['BUILDERS']['CopyMid'] = copy_mid
+
+copy_out.add_src_builder(copy_mid)
+
+env.CopyOut('file1.out', 'file1.in')
+""")
+
+test.write('file1.in', "file1.in\n")
+
+test.run()
+
+test.must_match('file1.mid', "file1.in\n")
+test.must_match('file1.out', "file1.in\n")
+
+test.pass_test()