Merge pull request #4553 from mwichmann/clone-variables
[scons.git] / test / Builder / wrapper.py
blob60f8b21baade64609749ed804dfd68641b0cb48d
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 Test the ability to use a direct Python function to wrap
28 calls to other Builder(s).
29 """
31 import TestSCons
33 test = TestSCons.TestSCons()
35 test.write('SConstruct', """
36 DefaultEnvironment(tools=[])
38 import os.path
39 import string
40 def cat(target, source, env):
41 with open(str(target[0]), 'wb') as fp:
42 for s in map(str, source):
43 with open(s, 'rb') as infp:
44 fp.write(infp.read())
45 Cat = Builder(action=cat)
46 def Wrapper(env, target, source):
47 if not target:
48 target = [str(source[0]).replace('.in', '.wout')]
49 t1 = 't1-'+str(target[0])
50 source = 's-'+str(source[0])
51 env.Cat(t1, source)
52 t2 = 't2-'+str(target[0])
53 env.Cat(t2, source)
54 env = Environment(tools=[],
55 BUILDERS = {'Cat' : Cat,
56 'Wrapper' : Wrapper})
57 env.Wrapper('f1.out', 'f1.in')
58 env.Wrapper('f2.in')
59 """)
61 test.write('s-f1.in', "s-f1.in\n")
62 test.write('s-f2.in', "s-f2.in\n")
64 test.run()
66 test.must_match('t1-f1.out', "s-f1.in\n")
67 test.must_match('t1-f2.wout', "s-f2.in\n")
68 test.must_match('t2-f1.out', "s-f1.in\n")
69 test.must_match('t2-f2.wout', "s-f2.in\n")
71 test.pass_test()
73 # Local Variables:
74 # tab-width:4
75 # indent-tabs-mode:nil
76 # End:
77 # vim: set expandtab tabstop=4 shiftwidth=4: