l = string.split(act, "\n")
if len(l) > 1:
act = l
- if type(act) == types.FunctionType:
+ if callable(act):
return FunctionAction(act)
elif type(act) == types.StringType:
return CommandAction(act)
one is an internal Python function, one is a list
containing one of each.
"""
+
cmd1 = "python %s %s xyzzy" % (act_py, outfile)
+
builder = SCons.Builder.Builder(action = cmd1)
r = builder.execute()
assert r == 0
assert test.read(outfile, 'r') == "act.py: xyzzy\n"
def function1(kw):
- f = open(kw['out'], 'w')
- f.write("function1\n")
- f.close()
+ open(kw['out'], 'w').write("function1\n")
return 1
builder = SCons.Builder.Builder(action = function1)
assert r == 1
assert test.read(outfile, 'r') == "function1\n"
+ class class1a:
+ def __init__(self, kw):
+ open(kw['out'], 'w').write("class1a\n")
+
+ builder = SCons.Builder.Builder(action = class1a)
+ r = builder.execute(out = outfile)
+ assert r.__class__ == class1a
+ assert test.read(outfile, 'r') == "class1a\n"
+
+ class class1b:
+ def __call__(self, kw):
+ open(kw['out'], 'w').write("class1b\n")
+ return 2
+
+ builder = SCons.Builder.Builder(action = class1b())
+ r = builder.execute(out = outfile)
+ assert r == 2
+ assert test.read(outfile, 'r') == "class1b\n"
+
cmd2 = "python %s %s syzygy" % (act_py, outfile)
+
def function2(kw):
open(kw['out'], 'a').write("function2\n")
- return 2
- builder = SCons.Builder.Builder(action = [cmd2, function2])
+ return 0
+
+ class class2a:
+ def __call__(self, kw):
+ open(kw['out'], 'a').write("class2a\n")
+ return 0
+
+ class class2b:
+ def __init__(self, kw):
+ open(kw['out'], 'a').write("class2b\n")
+
+ builder = SCons.Builder.Builder(action = [cmd2, function2, class2a(), class2b])
r = builder.execute(out = outfile)
- assert r == 2
- assert test.read(outfile, 'r') == "act.py: syzygy\nfunction2\n"
+ assert r.__class__ == class2b
+ assert test.read(outfile, 'r') == "act.py: syzygy\nfunction2\nclass2a\nclass2b\n"
def test_insuffix(self):
"""Test Builder creation with a specified input suffix
import re
import types
import SCons.Util
-
+import SCons.Builder
def Command():
dlist = dlist[0]
return dlist
+ def Command(self, target, source, action):
+ """Builds the supplied target files from the supplied
+ source files using the supplied action. Action may
+ be any type that the Builder constructor will accept
+ for an action."""
+ bld = SCons.Builder.Builder(name="Command", action=action)
+ return bld(self, target, source)
+
def subst(self, string):
"""Recursively interpolates construction variables from the
Environment into the specified string, returning the expanded
assert d.__class__.__name__ == 'File'
assert d.path == 'Environment.py'
+ def test_Command(self):
+ """Test the Command() method."""
+ env = Environment()
+ t = env.Command(target='foo.out', source=['foo1.in', 'foo2.in'],
+ action='buildfoo %(target)s %(source)s')
+ assert t.derived
+ assert t.builder.action.__class__.__name__ == 'CommandAction'
+ assert t.builder.action.command == 'buildfoo %(target)s %(source)s'
+ assert 'foo1.in' in map(lambda x: x.path, t.sources)
+ assert 'foo2.in' in map(lambda x: x.path, t.sources)
+
+ def testFunc(ENV, target, source):
+ assert target == 'foo.out'
+ assert source == 'foo1.in foo2.in' or source == 'foo2.in foo1.in'
+ env.Command(target='foo.out', source=['foo1.in','foo2.in'],
+ action=testFunc)
+
def test_subst(self):
"""Test substituting construction variables within strings
from SCons.Errors import BuildError
import string
-
+import types
class Node:
test = TestSCons.TestSCons()
-test.pass_test() #XXX Short-circuit until this is implemented.
-
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'r').read() + open(sys.argv[3], 'r').read()
+contents = open(sys.argv[2], 'r').read()
file = open(sys.argv[1], 'w')
file.write(contents)
file.close()
env.Command(target = 'f1.out', source = 'f1.in',
action = "python build.py %(target)s %(source)s")
env.Command(target = 'f2.out', source = 'f2.in',
- action = "python build.py temp2 %(source)s\npython build.py %(target)s temp2")
+ action = "python build.py temp2 %(source)s\\npython build.py %(target)s temp2")
env.Command(target = 'f3.out', source = 'f3.in',
action = ["python build.py temp3 %(source)s",
"python build.py %(target)s temp3"])
test.write('f3.in', "f3.in\n")
-test.run(arguments = '.')
+#XXXtest.run(arguments = '.')
+test.run(arguments = 'f1.out f2.out f3.out')
test.fail_test(test.read('f1.out') != "f1.in\n")
test.fail_test(test.read('f2.out') != "f2.in\n")