Added fix for TeX includes with same name as subdirs.
[scons.git] / test / emitter.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 import TestSCons
28 import os
29
30 test = TestSCons.TestSCons()
31
32 test.subdir('src')
33
34 test.write('SConstruct',"""
35 VariantDir('var1', 'src', duplicate=0)
36 VariantDir('var2', 'src', duplicate=1)
37 SConscript('src/SConscript')
38 SConscript('var1/SConscript')
39 SConscript('var2/SConscript')
40 """)
41
42 test.write('src/SConscript',"""
43 def build(target, source, env):
44     for t in target:
45         open(str(t), "wt").write(str(t))
46
47 def emitter(target, source, env):
48     target.append(str(target[0])+".foo")
49     return target,source
50
51 def emit1(t, s, e): return (t + ['emit.1'], s)
52 def emit2(t, s, e): return (t + ['emit.2'], s)
53
54 foo = Builder(action=build, emitter=emitter)
55 bar = Builder(action=build, emitter='$EMITTERS')
56
57 env=Environment(BUILDERS={ 'foo': foo, 'bar': bar },
58                 EMITTERS=[emit1, emit2])
59 env.foo('f.out', 'f.in')
60 env.foo(File('g.out'), 'g.in')
61 env.bar('h.out', 'h.in')
62 """)
63
64 test.write(['src', 'f.in'], 'f.in')
65 test.write(['src', 'g.in'], 'g.in')
66 test.write(['src', 'h.in'], 'h.in')
67
68 # Do 'src' last so that creation of the emitter files in there doesn't
69 # interfere with searching for them in the VariantDirs.
70
71 test.run(arguments='var2')
72
73 test.must_exist(test.workpath('var2', 'f.out'))
74 test.must_exist(test.workpath('var2', 'f.out.foo'))
75 test.must_exist(test.workpath('var2', 'g.out'))
76 test.must_exist(test.workpath('var2', 'g.out.foo'))
77 test.must_exist(test.workpath('var2', 'h.out'))
78 test.must_exist(test.workpath('var2', 'emit.1'))
79 test.must_exist(test.workpath('var2', 'emit.2'))
80
81 test.run(arguments = 'var1')
82
83 test.must_exist(test.workpath('var1', 'f.out'))
84 test.must_exist(test.workpath('var1', 'f.out.foo'))
85 test.must_exist(test.workpath('var1', 'g.out'))
86 test.must_exist(test.workpath('var1', 'g.out.foo'))
87 test.must_exist(test.workpath('var1', 'h.out'))
88 test.must_exist(test.workpath('var1', 'emit.1'))
89 test.must_exist(test.workpath('var1', 'emit.2'))
90
91 test.run(arguments = 'src')
92
93 test.must_exist(test.workpath('src', 'f.out'))
94 test.must_exist(test.workpath('src', 'f.out.foo'))
95 test.must_exist(test.workpath('src', 'g.out'))
96 test.must_exist(test.workpath('src', 'g.out.foo'))
97 test.must_exist(test.workpath('src', 'h.out'))
98 test.must_exist(test.workpath('src', 'emit.1'))
99 test.must_exist(test.workpath('src', 'emit.2'))
100
101 test.pass_test()
102
103 # Local Variables:
104 # tab-width:4
105 # indent-tabs-mode:nil
106 # End:
107 # vim: set expandtab tabstop=4 shiftwidth=4: