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