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