- Fix handling when BuildDir() exists but is unwriteable. Add
"Stop." to those error messages for consistency.
+ - Catch incidents of bad builder creation (without an action) and
+ supply meaningful error messages.
+
From Christoph Wiedemann:
- Add an Environment.SetDefault() method that only sets values if
else:
executor.add_sources(slist)
if executor is None:
+ if not builder.action:
+ raise UserError, "Builder %s must have an action to build %s."%(builder.get_name(env or builder.env), map(str,tlist))
executor = SCons.Executor.Executor(builder.action,
env or builder.env,
[builder.overrides, overrides],
target = builder(env, source='n21')[0]
assert target.name == 'p-n21.s', target
+ builder = SCons.Builder.Builder(misspelled_action="foo",
+ suffix = '.s')
+ try:
+ builder(env, target = 'n22', source = 'n22')
+ except SCons.Errors.UserError, e:
+ pass
+ else:
+ raise "Did not catch expected UserError."
+
def test_mistaken_variables(self):
"""Test keyword arguments that are often mistakes
"""
env = Environment()
builder = SCons.Builder.Builder(prefix = 'lib.')
assert builder.get_prefix(env) == 'lib.'
- builder = SCons.Builder.Builder(prefix = 'lib')
+ builder = SCons.Builder.Builder(prefix = 'lib', action='')
assert builder.get_prefix(env) == 'lib'
tgt = builder(env, target = 'tgt1', source = 'src1')[0]
assert tgt.path == 'libtgt1', \
'.in' : 'out-',
'.x' : 'y-',
'$FOO' : 'foo-',
- '.zzz' : my_emit})
+ '.zzz' : my_emit},
+ action = '')
tgt = builder(my_env, source = 'f1')[0]
assert tgt.path == 'default-f1', tgt.path
tgt = builder(my_env, source = 'f2.c')[0]
"""
env = Environment(XSUFFIX = '.x', YSUFFIX = '.y')
- b1 = SCons.Builder.Builder(src_suffix = '.c')
+ b1 = SCons.Builder.Builder(src_suffix = '.c', action='')
assert b1.src_suffixes(env) == ['.c'], b1.src_suffixes(env)
tgt = b1(env, target = 'tgt2', source = 'src2')[0]
env = Environment()
builder = SCons.Builder.Builder(suffix = '.o')
assert builder.get_suffix(env) == '.o', builder.get_suffix(env)
- builder = SCons.Builder.Builder(suffix = 'o')
+ builder = SCons.Builder.Builder(suffix = 'o', action='')
assert builder.get_suffix(env) == '.o', builder.get_suffix(env)
tgt = builder(env, target = 'tgt3', source = 'src3')[0]
assert tgt.path == 'tgt3.o', \
'.in' : '.out',
'.x' : '.y',
'$BAR' : '.new',
- '.zzz' : my_emit})
+ '.zzz' : my_emit},
+ action='')
tgt = builder(my_env, source = 'f1')[0]
assert tgt.path == 'f1.default', tgt.path
tgt = builder(my_env, source = 'f2.c')[0]
sscan = TestScanner()
env = Environment()
builder = SCons.Builder.Builder(target_scanner=tscan,
- source_scanner=sscan)
+ source_scanner=sscan,
+ action='')
tgt = builder(env, target='foo2', source='bar')[0]
assert tgt.target_scanner == tscan, tgt.target_scanner
assert tgt.source_scanner == sscan, tgt.source_scanner
self.overridelist = overridelist
self.targets = targets
self.sources = sources[:]
+ if not action:
+ raise SCons.Errors.UserError, "Executor must have an action."
def get_build_env(self):
"""Fetch or create the appropriate build Environment
assert x.targets == 't', x.targets
source_list.append('s3')
assert x.sources == ['s1', 's2'], x.sources
+ try:
+ x = SCons.Executor.Executor(None, 'e', ['o'], 't', source_list)
+ except SCons.Errors.UserError:
+ pass
+ else:
+ raise "Did not catch expected UserError"
def test_get_build_env(self):
"""Test fetching and generating a build environment"""
--- /dev/null
+#!/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__"
+
+"""
+Test the ability to catch Builder creation with poorly specified Actions.
+"""
+
+import os.path
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+sconstruct = """
+def buildop(env, source, target):
+ outf = open(str(target[0]), 'wb')
+ inpf = open(str(source[0]), 'r')
+ for line in inpf.readlines():
+ if line.find(str(target[0])) == -1:
+ outf.write(line)
+ inpf.close()
+ outf.close()
+b1 = Builder(action=buildop, src_suffix='.a', suffix='.b')
+%s
+env=Environment(tools=[], BUILDERS={'b1':b1, 'b2':b2})
+foo_b = env.b1(source='foo.a')
+env.b2(source=foo_b)
+"""
+
+test.write('foo.a', """\
+foo.c
+foo.b
+built
+""")
+
+### Gross mistake in Builder spec
+
+test.write('SConstruct', sconstruct % '\
+b2 = Builder(act__ion=buildop, src_suffix=".b", suffix=".c")')
+
+test.run(arguments='.',
+ stderr="""\
+
+scons: *** Builder b2 must have an action to build ['foo.c'].
+File "SConstruct", line 14, in ?
+""",
+status = 2)
+
+### Subtle mistake in Builder spec
+
+test.write('SConstruct', sconstruct % '\
+b2 = Builder(actoin=buildop, src_suffix=".b", suffix=".c")')
+
+test.run(arguments='test2',
+ stderr="""\
+
+scons: *** Builder b2 must have an action to build ['foo.c'].
+File "SConstruct", line 14, in ?
+""",
+status = 2)
+
+### Missing action in Builder spec
+
+test.write('SConstruct', sconstruct % '\
+b2 = Builder(src_suffix=".b", suffix=".c")')
+
+test.run(arguments='test2',
+ stderr="""\
+
+scons: *** Builder b2 must have an action to build ['foo.c'].
+File "SConstruct", line 14, in ?
+""",
+status = 2)
+
+
+test.pass_test()