[ci skip] update generated files
[scons.git] / test / Batch / callable.py
blob5c4d816d3c8ed8db348b42b707ed1ce6e0fa82a4
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 passing in a batch_key callable for more control over how
28 batch builders behave.
29 """
31 import os
33 import TestSCons
35 test = TestSCons.TestSCons()
37 test.subdir('sub1', 'sub2')
39 test.write('SConstruct', """
40 DefaultEnvironment(tools=[])
41 def batch_build(target, source, env):
42 for t, s in zip(target, source):
43 with open(str(t), 'wb') as f, open(str(s), 'rb') as infp:
44 f.write(infp.read())
45 if ARGUMENTS.get('BATCH_CALLABLE'):
46 def batch_key(action, env, target, source):
47 return (id(action), id(env), target[0].dir)
48 else:
49 batch_key=True
50 env = Environment(tools=[])
51 bb = Action(batch_build, batch_key=batch_key)
52 env['BUILDERS']['Batch'] = Builder(action=bb)
53 env1 = env.Clone()
54 env1.Batch('sub1/f1a.out', 'f1a.in')
55 env1.Batch('sub2/f1b.out', 'f1b.in')
56 env2 = env.Clone()
57 env2.Batch('sub1/f2a.out', 'f2a.in')
58 env2.Batch('sub2/f2b.out', 'f2b.in')
59 """)
61 test.write('f1a.in', "f1a.in\n")
62 test.write('f1b.in', "f1b.in\n")
63 test.write('f2a.in', "f2a.in\n")
64 test.write('f2b.in', "f2b.in\n")
66 sub1_f1a_out = os.path.join('sub1', 'f1a.out')
67 sub2_f1b_out = os.path.join('sub2', 'f1b.out')
68 sub1_f2a_out = os.path.join('sub1', 'f2a.out')
69 sub2_f2b_out = os.path.join('sub2', 'f2b.out')
71 expect = test.wrap_stdout("""\
72 batch_build(["%(sub1_f1a_out)s", "%(sub2_f1b_out)s"], ["f1a.in", "f1b.in"])
73 batch_build(["%(sub1_f2a_out)s", "%(sub2_f2b_out)s"], ["f2a.in", "f2b.in"])
74 """ % locals())
76 test.run(stdout = expect)
78 test.must_match(['sub1', 'f1a.out'], "f1a.in\n")
79 test.must_match(['sub2', 'f1b.out'], "f1b.in\n")
80 test.must_match(['sub1', 'f2a.out'], "f2a.in\n")
81 test.must_match(['sub2', 'f2b.out'], "f2b.in\n")
83 test.run(arguments = '-c')
85 test.must_not_exist(['sub1', 'f1a.out'])
86 test.must_not_exist(['sub2', 'f1b.out'])
87 test.must_not_exist(['sub1', 'f2a.out'])
88 test.must_not_exist(['sub2', 'f2b.out'])
90 expect = test.wrap_stdout("""\
91 batch_build(["%(sub1_f1a_out)s"], ["f1a.in"])
92 batch_build(["%(sub1_f2a_out)s"], ["f2a.in"])
93 batch_build(["%(sub2_f1b_out)s"], ["f1b.in"])
94 batch_build(["%(sub2_f2b_out)s"], ["f2b.in"])
95 """ % locals())
97 test.run(arguments = 'BATCH_CALLABLE=1', stdout = expect)
99 test.must_match(['sub1', 'f1a.out'], "f1a.in\n")
100 test.must_match(['sub2', 'f1b.out'], "f1b.in\n")
101 test.must_match(['sub1', 'f2a.out'], "f2a.in\n")
102 test.must_match(['sub2', 'f2b.out'], "f2b.in\n")
104 test.pass_test()
106 # Local Variables:
107 # tab-width:4
108 # indent-tabs-mode:nil
109 # End:
110 # vim: set expandtab tabstop=4 shiftwidth=4: