From 8452039c43b7a520df6edd12a38cf24ce3c77624 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Thu, 11 Sep 2008 01:28:15 +0000 Subject: [PATCH] Issue 1681: Fix the ability of add_src_builder() to handle arbitrary 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 | 13 +++++-- src/engine/SCons/Builder.py | 6 ++- src/engine/SCons/BuilderTests.py | 3 ++ test/Builder/add_src_builder.py | 65 ++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 test/Builder/add_src_builder.py diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 1055398f..f3a7115d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,15 +10,20 @@ 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 diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 2e10a8d2..45bd99a1 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -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 diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 1b7bc380..eeb3b3f1 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -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 index 00000000..f67acc06 --- /dev/null +++ b/test/Builder/add_src_builder.py @@ -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() -- 2.26.2