Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / Batch / callable.py
blob9fe14ee87eb0211079e6d0419df2ea1da7333ee1
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify passing in a batch_key callable for more control over how
29 batch builders behave.
30 """
32 import os
34 import TestSCons
36 test = TestSCons.TestSCons()
38 test.subdir('sub1', 'sub2')
40 test.write('SConstruct', """
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()
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: