Add support for multi-command Builders and Actions.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 29 Sep 2001 10:52:18 +0000 (10:52 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 29 Sep 2001 10:52:18 +0000 (10:52 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@76 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
test/multiline.py [new file with mode: 0644]

index 2852b3a3e75368d2ea574300b4e5463e18662186..d354c5737c8150985d98b42933410e06a5c66485 100644 (file)
@@ -66,10 +66,16 @@ execute_actions = 1;
 
 def Action(act):
     """A factory for action objects."""
+    if type(act) == types.StringType:
+       l = string.split(act, "\n")
+       if len(l) > 1:
+           act = l
     if type(act) == types.FunctionType:
        return FunctionAction(act)
     elif type(act) == types.StringType:
        return CommandAction(act)
+    elif type(act) == types.ListType:
+       return ListAction(act)
     else:
        return None
 
@@ -119,3 +125,12 @@ class FunctionAction(ActionBase):
        # XXX:  WHAT SHOULD WE PRINT HERE?
        if execute_actions:
            self.function(kw)
+
+class ListAction(ActionBase):
+    """Class for lists of other actions."""
+    def __init__(self, list):
+       self.list = map(lambda x: Action(x), list)
+
+    def execute(self, **kw):
+       for l in self.list:
+           apply(l.execute, (), kw)
diff --git a/test/multiline.py b/test/multiline.py
new file mode 100644 (file)
index 0000000..5c51fac
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import os.path
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('build.py', r"""
+import sys
+contents = open(sys.argv[2], 'r').read()
+file = open(sys.argv[1], 'w')
+file.write(contents)
+file.close()
+""")
+
+test.write('SConstruct', """
+B1 = Builder(name = 'B1', action = ["python build.py .temp %(source)s",
+                                   "python build.py %(target)s .temp"])
+B2 = Builder(name = 'B2', action = "python build.py .temp %(source)s\\npython build.py %(target)s .temp")
+env = Environment(BUILDERS = [B1, B2])
+env.B1(target = 'foo1.out', source = 'foo1.in')
+env.B2(target = 'foo2.out', source = 'foo2.in')
+env.B1(target = 'foo3.out', source = 'foo3.in')
+""")
+
+test.write('foo1.in', "foo1.in\n")
+
+test.write('foo2.in', "foo2.in\n")
+
+test.write('foo3.in', "foo3.in\n")
+
+test.run(arguments = 'foo1.out foo2.out foo3.out')
+
+test.fail_test(test.read(test.workpath('foo1.out')) != "foo1.in\n")
+test.fail_test(test.read(test.workpath('foo2.out')) != "foo2.in\n")
+test.fail_test(test.read(test.workpath('foo3.out')) != "foo3.in\n")
+
+test.pass_test()