Issue 1086: add support for generic batch build actions, and
[scons.git] / test / Batch / CHANGED_SOURCES.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Verify use of $CHANGED_SOURCES with batch builders correctly decides
29 to rebuild if any sources of changed, and specifies only the sources
30 on the rebuild.
31 """
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 _python_ = TestSCons._python_
38
39 test.write('batch_build.py', """\
40 import os
41 import sys
42 dir = sys.argv[1]
43 for infile in sys.argv[2:]:
44     inbase = os.path.splitext(os.path.split(infile)[1])[0]
45     outfile = os.path.join(dir, inbase+'.out')
46     open(outfile, 'wb').write(open(infile, 'rb').read())
47 sys.exit(0)
48 """)
49
50 test.write('SConstruct', """
51 env = Environment()
52 env['BATCH_BUILD'] = 'batch_build.py'
53 env['BATCHCOM'] = r'%(_python_)s $BATCH_BUILD ${TARGET.dir} $CHANGED_SOURCES'
54 bb = Action('$BATCHCOM', batch_key=True, targets='CHANGED_TARGETS')
55 env['BUILDERS']['Batch'] = Builder(action=bb)
56 env1 = env.Clone()
57 env1.Batch('out1/f1a.out', 'f1a.in')
58 env1.Batch('out1/f1b.out', 'f1b.in')
59 env2 = env.Clone()
60 env2.Batch('out2/f2a.out', 'f2a.in')
61 env3 = env.Clone()
62 env3.Batch('out3/f3a.out', 'f3a.in')
63 env3.Batch('out3/f3b.out', 'f3b.in')
64 """ % locals())
65
66 test.write('f1a.in', "f1a.in\n")
67 test.write('f1b.in', "f1b.in\n")
68 test.write('f2a.in', "f2a.in\n")
69 test.write('f3a.in', "f3a.in\n")
70 test.write('f3b.in', "f3b.in\n")
71
72 expect = test.wrap_stdout("""\
73 %(_python_)s batch_build.py out1 f1a.in f1b.in
74 %(_python_)s batch_build.py out2 f2a.in
75 %(_python_)s batch_build.py out3 f3a.in f3b.in
76 """ % locals())
77
78 test.run(stdout = expect)
79
80 test.must_match(['out1', 'f1a.out'], "f1a.in\n")
81 test.must_match(['out1', 'f1b.out'], "f1b.in\n")
82 test.must_match(['out2', 'f2a.out'], "f2a.in\n")
83 test.must_match(['out3', 'f3a.out'], "f3a.in\n")
84 test.must_match(['out3', 'f3b.out'], "f3b.in\n")
85
86
87
88 test.write('f1b.in', "f1b.in 2\n")
89
90 expect = test.wrap_stdout("""\
91 %(_python_)s batch_build.py out1 f1b.in
92 """ % locals())
93
94 test.run(stdout = expect)
95
96 test.must_match(['out1', 'f1a.out'], "f1a.in\n")
97 test.must_match(['out1', 'f1b.out'], "f1b.in 2\n")
98 test.must_match(['out2', 'f2a.out'], "f2a.in\n")
99 test.must_match(['out3', 'f3a.out'], "f3a.in\n")
100 test.must_match(['out3', 'f3b.out'], "f3b.in\n")
101
102
103
104 test.write('f3a.in', "f3a.in 2\n")
105
106 expect = test.wrap_stdout("""\
107 %(_python_)s batch_build.py out3 f3a.in
108 """ % locals())
109
110 test.run(stdout = expect)
111
112 test.must_match(['out1', 'f1a.out'], "f1a.in\n")
113 test.must_match(['out1', 'f1b.out'], "f1b.in 2\n")
114 test.must_match(['out2', 'f2a.out'], "f2a.in\n")
115 test.must_match(['out3', 'f3a.out'], "f3a.in 2\n")
116 test.must_match(['out3', 'f3b.out'], "f3b.in\n")
117
118 test.pass_test()