From a2ceacbe77db1b308f26454477ae3b1f1139eac8 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Mon, 6 May 2002 22:27:28 +0000 Subject: Raise an error if a builder is called multiple times for a given target, unless the builder is marked as multicall safe. (Anthony Roach) --- doc/man/scons.1 | 13 +- etc/TestCmd.py | 10 ++ src/CHANGES.txt | 7 ++ src/engine/SCons/Builder.py | 44 +++++-- src/engine/SCons/BuilderTests.py | 41 ++++--- src/engine/SCons/Defaults.py | 3 +- src/engine/SCons/Script/__init__.py | 34 +++++- test/AR.py | 6 +- test/ARFLAGS.py | 6 +- test/Alias.py | 10 ++ test/LIBPATH.py | 24 ++-- test/RANLIB.py | 6 +- test/RANLIBFLAGS.py | 6 +- test/errors.py | 8 +- test/exceptions.py | 5 +- test/long-lines.py | 13 +- test/multi.py | 236 ++++++++++++++++++++++++++++++++++++ test/option--U.py | 2 +- 18 files changed, 408 insertions(+), 66 deletions(-) create mode 100644 test/multi.py diff --git a/doc/man/scons.1 b/doc/man/scons.1 index c60cf17..a4539de 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -988,10 +988,12 @@ Returns the Node object representing the alias, which exists outside of any file system. This Node object, or the alias name, may be used as a dependency of any other target, -including another alias. +including another alias. Alias can be called multiple times for the same +alias to add additional targets to the alias. .ES env.Alias('install', ['/usr/local/bin', '/usr/local/lib']) +env.Alias('install', ['/usr/local/man']) .EE .TP @@ -1763,6 +1765,15 @@ an Action object (see the next section); or a list of any of the above. +.IP multi +Specifies whether this builder is allowed to be called multiple times for +the same target file(s). The default is 0, which means the builder +can not be called multiple times for the same target file(s). Calling a +builder multiple times for the same target simply adds additional source +files to the target; it is not allowed to change the environment associated +with the target, specify addition build arguments, or associate a different +builder with the target. + .IP prefix The prefix that will be prepended to the target file name. The value may also be a function call diff --git a/etc/TestCmd.py b/etc/TestCmd.py index 912be48..2d1c932 100644 --- a/etc/TestCmd.py +++ b/etc/TestCmd.py @@ -186,6 +186,16 @@ def match_re(lines = None, res = None): return return 1 +def match_re_dotall(lines = None, res = None): + """ + """ + if not type(lines) is type(""): + lines = join(lines, "\n") + if not type(res) is type(""): + res = join(res, "\n") + if re.compile("^" + res + "$", re.DOTALL).match(lines): + return 1 + class TestCmd: """Class TestCmd """ diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 391da3c..3797327 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,13 @@ RELEASE 0.08 - + From Anthony Roach: + + - Add a "multi" keyword argument to Builder creation that specifies + it's okay to call the builder multiple times for a target. + + - Set a "multi" on Aliases so multiple calls will append to an Alias. + From Zed Shaw: - Add an Append() method to Environments, to append values to diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index a28a31d..d73917c 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -99,18 +99,37 @@ def Builder(**kw): else: return apply(BuilderBase, (), kw) -def _init_nodes(builder, env, tlist, slist): +def _init_nodes(builder, env, args, tlist, slist): """Initialize lists of target and source nodes with all of the proper Builder information. """ + for s in slist: src_key = s.scanner_key() # the file suffix scanner = env.get_scanner(src_key) if scanner: s.source_scanner = scanner - + for t in tlist: - t.cwd = SCons.Node.FS.default_fs.getcwd() # XXX + if t.builder is not None: + if t.env != env: + raise UserError, "Two different environments were specified for the same target: %s"%str(t) + elif t.build_args != args: + raise UserError, "Two different sets of build arguments were specified for the same target: %s"%str(t) + elif builder.scanner and builder.scanner != t.target_scanner: + raise UserError, "Two different scanners were specified for the same target: %s"%str(t) + + if builder.multi: + if t.builder != builder: + if isinstance(t.builder, ListBuilder) and isinstance(builder, ListBuilder) and t.builder.builder == builder.builder: + raise UserError, "Two different target sets have a target in common: %s"%str(t) + else: + raise UserError, "Two different builders (%s and %s) were specified for the same target: %s"%(t.builder.name, builder.name, str(t)) + elif t.sources != slist: + raise UserError, "Multiple ways to build the same target were specified for: %s" % str(t) + + t.build_args = args + t.cwd = SCons.Node.FS.default_fs.getcwd() t.builder_set(builder) t.env_set(env) t.add_source(slist) @@ -181,11 +200,13 @@ class BuilderBase: target_factory = None, source_factory = None, scanner = None, - emitter = None): + emitter = None, + multi = 0): if name is None: raise UserError, "You must specify a name for the builder." self.name = name self.action = SCons.Action.Action(action) + self.multi = multi if callable(prefix): self.prefix = prefix @@ -262,18 +283,16 @@ class BuilderBase: src_suf), self.source_factory) - for t in tlist: - t.build_args = args - return tlist, slist + return tlist, slist def __call__(self, env, target = None, source = None, **kw): tlist, slist = self._create_nodes(env, kw, target, source) if len(tlist) == 1: - _init_nodes(self, env, tlist, slist) + _init_nodes(self, env, kw, tlist, slist) tlist = tlist[0] else: - _init_nodes(ListBuilder(self, env, tlist), env, tlist, slist) + _init_nodes(ListBuilder(self, env, tlist), env, kw, tlist, slist) return tlist @@ -330,7 +349,9 @@ class ListBuilder: self.builder = builder self.scanner = builder.scanner self.env = env - self.tlist = tlist + self.tlist = tlist + self.multi = builder.multi + self.name = "ListBuilder(%s)"%builder.name def execute(self, **kw): if hasattr(self, 'status'): @@ -360,6 +381,9 @@ class ListBuilder: """ return self.tlist + def __cmp__(self, other): + return cmp(self.__dict__, other.__dict__) + class MultiStepBuilder(BuilderBase): """This is a builder subclass that can build targets in multiple steps. The src_builder parameter to the constructor diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 12178ed..d7fd92d 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -38,6 +38,7 @@ import unittest import TestCmd import SCons.Builder import SCons.Errors +import SCons.Node.FS # Initial setup of the common environment for all tests, # a temporary working directory containing a @@ -680,7 +681,7 @@ class BuilderTestCase(unittest.TestCase): pass scn = TestScanner() builder = SCons.Builder.Builder(name = "builder", scanner=scn) - tgt = builder(env, target='foo', source='bar') + tgt = builder(env, target='foo2', source='bar') assert tgt.target_scanner == scn, tgt.target_scanner builder1 = SCons.Builder.Builder(name = "builder1", @@ -691,7 +692,7 @@ class BuilderTestCase(unittest.TestCase): action='foo', src_builder = builder1, scanner = scn) - tgt = builder2(env, target='baz', source='test.bar test2.foo test3.txt') + tgt = builder2(env, target='baz2', source='test.bar test2.foo test3.txt') assert tgt.target_scanner == scn, tgt.target_scanner def test_src_scanner(slf): @@ -725,45 +726,45 @@ class BuilderTestCase(unittest.TestCase): """Test emitter functions.""" def emit(target, source, env, foo=0, bar=0): if foo: - target.append("bar") + target.append("bar%d"%foo) if bar: - source.append("foo") + source.append("baz") return ( target, source ) builder = SCons.Builder.Builder(name="builder", action='foo', emitter=emit) - tgt = builder(env, target='foo', source='bar') - assert str(tgt) == 'foo', str(tgt) + tgt = builder(env, target='foo2', source='bar') + assert str(tgt) == 'foo2', str(tgt) assert str(tgt.sources[0]) == 'bar', str(tgt.sources[0]) - tgt = builder(env, target='foo', source='bar', foo=1) + tgt = builder(env, target='foo3', source='bar', foo=1) assert len(tgt) == 2, len(tgt) - assert 'foo' in map(str, tgt), map(str, tgt) - assert 'bar' in map(str, tgt), map(str, tgt) + assert 'foo3' in map(str, tgt), map(str, tgt) + assert 'bar1' in map(str, tgt), map(str, tgt) - tgt = builder(env, target='foo', source='bar', bar=1) - assert str(tgt) == 'foo', str(tgt) + tgt = builder(env, target='foo4', source='bar', bar=1) + assert str(tgt) == 'foo4', str(tgt) assert len(tgt.sources) == 2, len(tgt.sources) - assert 'foo' in map(str, tgt.sources), map(str, tgt.sources) + assert 'baz' in map(str, tgt.sources), map(str, tgt.sources) assert 'bar' in map(str, tgt.sources), map(str, tgt.sources) env2=Environment(FOO=emit) builder2=SCons.Builder.Builder(name="builder2", action='foo', emitter="$FOO") - tgt = builder2(env2, target='foo', source='bar') - assert str(tgt) == 'foo', str(tgt) + tgt = builder2(env2, target='foo5', source='bar') + assert str(tgt) == 'foo5', str(tgt) assert str(tgt.sources[0]) == 'bar', str(tgt.sources[0]) - tgt = builder2(env2, target='foo', source='bar', foo=1) + tgt = builder2(env2, target='foo6', source='bar', foo=2) assert len(tgt) == 2, len(tgt) - assert 'foo' in map(str, tgt), map(str, tgt) - assert 'bar' in map(str, tgt), map(str, tgt) + assert 'foo6' in map(str, tgt), map(str, tgt) + assert 'bar2' in map(str, tgt), map(str, tgt) - tgt = builder2(env2, target='foo', source='bar', bar=1) - assert str(tgt) == 'foo', str(tgt) + tgt = builder2(env2, target='foo7', source='bar', bar=1) + assert str(tgt) == 'foo7', str(tgt) assert len(tgt.sources) == 2, len(tgt.sources) - assert 'foo' in map(str, tgt.sources), map(str, tgt.sources) + assert 'baz' in map(str, tgt.sources), map(str, tgt.sources) assert 'bar' in map(str, tgt.sources), map(str, tgt.sources) if __name__ == "__main__": diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index cb21d81..7597169 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -318,7 +318,8 @@ def alias_builder(env, target, source): Alias = SCons.Builder.Builder(name = 'Alias', action = alias_builder, target_factory = SCons.Node.Alias.default_ans.Alias, - source_factory = SCons.Node.FS.default_fs.Entry) + source_factory = SCons.Node.FS.default_fs.Entry, + multi = 1) def get_devstudio_versions (): """ diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 105c28f..d0b17d4 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -179,13 +179,36 @@ def _scons_syntax_error(e): sys.stderr.write(line+'\n') sys.exit(2) +def find_deepest_user_frame(tb): + """ + Find the deepest stack frame that is not part of SCons. + """ + + stack = [tb] + while tb.tb_next is not None: + tb = tb.tb_next + stack.append(tb) + + stack.reverse() + + # find the deepest traceback frame that is not part + # of SCons: + for frame in stack: + filename = frame.tb_frame.f_code.co_filename + if string.find(filename, os.sep+'SCons'+os.sep) == -1: + tb = frame + break + + return tb + def _scons_user_error(e): """Handle user errors. Print out a message and a description of the - error, along with the line number and routine where it occured. + error, along with the line number and routine where it occured. + The file and line number will be the deepest stack frame that is + not part of SCons itself. """ etype, value, tb = sys.exc_info() - while tb.tb_next is not None: - tb = tb.tb_next + tb = find_deepest_user_frame(tb) lineno = traceback.tb_lineno(tb) filename = tb.tb_frame.f_code.co_filename routine = tb.tb_frame.f_code.co_name @@ -196,10 +219,11 @@ def _scons_user_error(e): def _scons_user_warning(e): """Handle user warnings. Print out a message and a description of the warning, along with the line number and routine where it occured. + The file and line number will be the deepest stack frame that is + not part of SCons itself. """ etype, value, tb = sys.exc_info() - while tb.tb_next is not None: - tb = tb.tb_next + tb = find_deepest_user_frame(tb) lineno = traceback.tb_lineno(tb) filename = tb.tb_frame.f_code.co_filename routine = tb.tb_frame.f_code.co_name diff --git a/test/AR.py b/test/AR.py index 09496eb..bd47005 100644 --- a/test/AR.py +++ b/test/AR.py @@ -53,8 +53,10 @@ bar = Environment(LIBS = ['bar'], LIBPATH = ['.'], AR = r'%s wrapper.py ' + ar) foo.Library(target = 'foo', source = 'foo.c') bar.Library(target = 'bar', source = 'bar.c') -foo.Program(target = 'f', source = 'main.c') -bar.Program(target = 'b', source = 'main.c') +obj = foo.Object('main', 'main.c') + +foo.Program(target = 'f', source = obj) +bar.Program(target = 'b', source = obj) """ % python) test.write('foo.c', r""" diff --git a/test/ARFLAGS.py b/test/ARFLAGS.py index f987a2f..5e1b365 100644 --- a/test/ARFLAGS.py +++ b/test/ARFLAGS.py @@ -55,8 +55,10 @@ bar = Environment(LIBS = ['bar'], LIBPATH = ['.'], foo.Library(target = 'foo', source = 'foo.c') bar.Library(target = 'bar', source = 'bar.c') -foo.Program(target = 'f', source = 'main.c') -bar.Program(target = 'b', source = 'main.c') +obj = foo.Object('main', 'main.c') + +foo.Program(target = 'f', source = obj) +bar.Program(target = 'b', source = obj) """ % python) test.write('foo.c', r""" diff --git a/test/Alias.py b/test/Alias.py index e6de2c0..6dae8a7 100644 --- a/test/Alias.py +++ b/test/Alias.py @@ -51,6 +51,8 @@ SConscript('sub1/SConscript', "env") SConscript('sub2/SConscript', "env") env.Alias('foo', ['f2.out', 'sub1']) env.Alias('bar', ['sub2', 'f3.out']) +env.Alias('blat', ['sub2', 'f3.out']) +env.Alias('blat', ['f2.out', 'sub1']) env.Depends('f1.out', 'bar') """ % python) @@ -107,4 +109,12 @@ test.fail_test(not os.path.exists(test.workpath('sub2', 'f9.out'))) test.up_to_date(arguments = 'f1.out') +os.unlink(test.workpath('f2.out')) +os.unlink(test.workpath('f3.out')) + +test.run(arguments = 'blat') + +test.fail_test(not os.path.exists(test.workpath('f2.out'))) +test.fail_test(not os.path.exists(test.workpath('f3.out'))) + test.pass_test() diff --git a/test/LIBPATH.py b/test/LIBPATH.py index afb87c6..871437c 100644 --- a/test/LIBPATH.py +++ b/test/LIBPATH.py @@ -44,13 +44,17 @@ prog2 = test.workpath('prog2') + _exe test.write('SConstruct', """ env1 = Environment(LIBS = [ 'foo1' ], LIBPATH = [ './lib1' ]) -env1.Program(target = 'prog', source = 'prog.c') -env1.Library(target = './lib1/foo1', source = 'f1.c') + +prog = env1.Object('prog', 'prog.c') +f1 = env1.Object('f1', 'f1.c') + +env1.Program(target = 'prog', source = prog) +env1.Library(target = './lib1/foo1', source = f1) env2 = Environment(LIBS = 'foo2', LIBPATH = '.') -env2.Program(target = 'prog2', source = 'prog.c') -env2.Library(target = 'foo2', source = 'f1.c') +env2.Program(target = 'prog2', source = prog) +env2.Library(target = 'foo2', source = f1) """) test.write('f1.c', r""" @@ -106,13 +110,17 @@ test.run(program = prog2, test.write('SConstruct', """ env1 = Environment(LIBS = [ 'foo1' ], LIBPATH = [ './lib1', './lib2' ]) -env1.Program(target = 'prog', source = 'prog.c') -env1.Library(target = './lib1/foo1', source = 'f1.c') + +prog = env1.Object('prog', 'prog.c') +f1 = env1.Object('f1', 'f1.c') + +env1.Program(target = 'prog', source = prog) +env1.Library(target = './lib1/foo1', source = f1) env2 = Environment(LIBS = 'foo2', LIBPATH = '. ./lib2') -env2.Program(target = 'prog2', source = 'prog.c') -env2.Library(target = 'foo2', source = 'f1.c') +env2.Program(target = 'prog2', source = prog) +env2.Library(target = 'foo2', source = f1) """) test.up_to_date(arguments = '.', stderr=None) diff --git a/test/RANLIB.py b/test/RANLIB.py index d255b7a..12ae212 100644 --- a/test/RANLIB.py +++ b/test/RANLIB.py @@ -64,8 +64,10 @@ bar = Environment(LIBS = ['bar'], LIBPATH = ['.'], foo.Library(target = 'foo', source = 'foo.c') bar.Library(target = 'bar', source = 'bar.c') -foo.Program(target = 'f', source = 'main.c') -bar.Program(target = 'b', source = 'main.c') +main = foo.Object('main', 'main.c') + +foo.Program(target = 'f', source = main) +bar.Program(target = 'b', source = main) """ % python) test.write('foo.c', r""" diff --git a/test/RANLIBFLAGS.py b/test/RANLIBFLAGS.py index 5549e94..752f685 100644 --- a/test/RANLIBFLAGS.py +++ b/test/RANLIBFLAGS.py @@ -64,8 +64,10 @@ bar = Environment(LIBS = ['bar'], LIBPATH = ['.'], RANLIB = '', foo.Library(target = 'foo', source = 'foo.c') bar.Library(target = 'bar', source = 'bar.c') -foo.Program(target = 'f', source = 'main.c') -bar.Program(target = 'b', source = 'main.c') +main = foo.Object('main', 'main.c') + +foo.Program(target = 'f', source = main) +bar.Program(target = 'b', source = main) """ % python) test.write('foo.c', r""" diff --git a/test/errors.py b/test/errors.py index 9f1a83c..fb042bb 100644 --- a/test/errors.py +++ b/test/errors.py @@ -28,7 +28,7 @@ import TestCmd import TestSCons import string -test = TestSCons.TestSCons(match = TestCmd.match_re) +test = TestSCons.TestSCons(match = TestCmd.match_re_dotall) test.write('foo.in', 'foo') test.write('exit.in', 'exit') @@ -52,11 +52,8 @@ env.exit('exit.out', 'exit.in') stderr = """scons: \*\*\* \[exit.out\] Exception Traceback \((most recent call|innermost) last\): File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ .+ .+ @@ -109,11 +106,8 @@ test.run(arguments='-f SConstruct3', stdout = "other errors\n", stderr = r"""Traceback \((most recent call|innermost) last\): File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ - .+ File "SConstruct3", line \d+, in \? raise InternalError, 'error inside' InternalError: error inside diff --git a/test/exceptions.py b/test/exceptions.py index acfe9dd..b3de487 100644 --- a/test/exceptions.py +++ b/test/exceptions.py @@ -29,7 +29,7 @@ import sys import TestSCons import TestCmd -test = TestSCons.TestSCons(match = TestCmd.match_re) +test = TestSCons.TestSCons(match = TestCmd.match_re_dotall) test.write('SConstruct', """ def func(source = None, target = None, env = None): @@ -44,11 +44,8 @@ test.write('foo.in', "foo.in\n") test.run(arguments = "foo.out", stderr = """scons: \*\*\* \[foo.out\] Exception Traceback \((most recent call|innermost) last\): File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ - .+ File ".+", line \d+, in .+ - .+ File "SConstruct", line 3, in func raise "func exception" func exception diff --git a/test/long-lines.py b/test/long-lines.py index a199a16..d42b570 100644 --- a/test/long-lines.py +++ b/test/long-lines.py @@ -48,7 +48,7 @@ while len(linkflags) <= 8100: env = Environment(LINKFLAGS = '$LINKXXX', LINKXXX = linkflags) env.Program(target = 'foo', source = 'foo.c') # Library(shared=1) uses $LINKFLAGS by default. -env.Library(target = 'bar', source = 'foo.c', shared=1, no_import_lib=1) +env.Library(target = 'bar', source = 'bar.c', shared=1, no_import_lib=1) """ % (linkflag, linkflag)) test.write('foo.c', r""" @@ -61,6 +61,17 @@ main(int argc, char *argv[]) } """) +test.write('bar.c', r""" +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + printf("foo.c\n"); + exit (0); +} +""") + + test.run(arguments = '.') test.up_to_date(arguments = '.') diff --git a/test/multi.py b/test/multi.py new file mode 100644 index 0000000..d955720 --- /dev/null +++ b/test/multi.py @@ -0,0 +1,236 @@ +#!/usr/bin/env python +# +# Copyright (c) 2001, 2002 Steven Knight +# +# 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__" + +import TestSCons +import os.path + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +def build(env, target, source): + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env.B(target = 'foo.out', source = 'foo.in') +env.B(target = 'foo.out', source = 'bar.in') +""") + +test.write('foo.in', 'foo.in\n') +test.write('bar.in', 'bar.in\n') + +test.run(arguments='foo.out') + +test.fail_test(not os.path.exists(test.workpath('foo.out'))) +test.fail_test(not test.read('foo.out') == 'foo.in\nbar.in\n') + +test.write('SConstruct', """ +def build(env, target, source): + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=0) +env = Environment(BUILDERS = [B]) +env.B(target = 'foo.out', source = 'foo.in') +env.B(target = 'foo.out', source = 'bar.in') +""") + +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Multiple ways to build the same target were specified for: foo.out +File "SConstruct", line 10, in ? +""") + +test.write('SConstruct', """ +def build(env, target, source): + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env.B(target = 'foo.out', source = 'foo.in', foo=1) +env.B(target = 'foo.out', source = 'bar.in', foo=2) +""") + +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Two different sets of build arguments were specified for the same target: foo.out +File "SConstruct", line 10, in ? +""") + +test.write('SConstruct', """ +def build(env, target, source): + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env2 = env.Copy(CCFLAGS='foo') +env.B(target = 'foo.out', source = 'foo.in') +env2.B(target = 'foo.out', source = 'bar.in') +""") + +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Two different environments were specified for the same target: foo.out +File "SConstruct", line 11, in ? +""") + +test.write('SConstruct', """ +def build(env, target, source): + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=0) +env = Environment(BUILDERS = [B]) +env.B(target = 'foo.out', source = 'foo.in') +env.B(target = 'foo.out', source = 'foo.in') +""") + +test.run(arguments='foo.out') +test.fail_test(not test.read('foo.out') == 'foo.in\n') + +test.write('SConstruct', """ +def build(env, target, source): + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +C = Builder(name='C', action=build, multi=1) +env = Environment(BUILDERS = [B,C]) +env.B(target = 'foo.out', source = 'foo.in') +env.C(target = 'foo.out', source = 'bar.in') +""") + +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Two different builders (B and C) were specified for the same target: foo.out +File "SConstruct", line 11, in ? +""") + +test.write('SConstruct', """ +def build(env, target, source): + for t in target: + file = open(str(t), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env.B(target = ['foo.out', 'bar.out'], source = 'foo.in') +env.B(target = ['foo.out', 'bar.out'], source = 'bar.in') +""") + +test.run(arguments='bar.out') +test.fail_test(not os.path.exists(test.workpath('bar.out'))) +test.fail_test(not test.read('bar.out') == 'foo.in\nbar.in\n') +test.fail_test(not os.path.exists(test.workpath('foo.out'))) +test.fail_test(not test.read('foo.out') == 'foo.in\nbar.in\n') + +test.write('SConstruct', """ +def build(env, target, source): + for t in target: + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env.B(target = ['foo.out', 'bar.out'], source = 'foo.in') +env.B(target = ['bar.out', 'foo.out'], source = 'bar.in') +""") + +# This is intentional. The order of the targets matter to the +# builder because the build command can contain things like ${TARGET[0]}: +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Two different target sets have a target in common: bar.out +File "SConstruct", line 11, in ? +""") + +# XXX It would be nice if the following two tests could be made to +# work by executing the action once for each unique set of +# targets. This would make it simple to deal with PDB files on Windows like so: +# +# env.Object(['foo.obj', 'vc60.pdb'], 'foo.c') +# env.Object(['bar.obj', 'vc60.pdb'], 'bar.c') + +test.write('SConstruct', """ +def build(env, target, source): + for t in target: + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env.B(target = ['foo.out', 'bar.out'], source = 'foo.in') +env.B(target = ['bar.out', 'blat.out'], source = 'bar.in') +""") + +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Two different target sets have a target in common: bar.out +File "SConstruct", line 11, in ? +""") + +test.write('SConstruct', """ +def build(env, target, source): + for t in target: + file = open(str(target[0]), "wt") + for s in source: + file.write(open(str(s), 'rt').read()) + +B = Builder(name='B', action=build, multi=1) +env = Environment(BUILDERS = [B]) +env.B(target = ['foo.out', 'bar.out'], source = 'foo.in') +env.B(target = 'foo.out', source = 'bar.in') +""") + +test.run(arguments='foo.out', + status=2, + stderr=""" +SCons error: Two different builders (ListBuilder(B) and B) were specified for the same target: foo.out +File "SConstruct", line 11, in ? +""") + + + + +test.pass_test() diff --git a/test/option--U.py b/test/option--U.py index 7f3e3f2..b984507 100644 --- a/test/option--U.py +++ b/test/option--U.py @@ -45,7 +45,7 @@ file.close() test.write('SConstruct', """ import SCons.Defaults -B = Builder(name='B', action='%s build.py $TARGET $SOURCES') +B = Builder(name='B', action='%s build.py $TARGET $SOURCES', multi=1) env = Environment(BUILDERS = [B, SCons.Defaults.Alias]) Default(env.B(target = 'sub1/foo.out', source = 'sub1/foo.in')) Export('env') -- cgit v0.12