[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / emitter.py
blobd2a8b67b72353b77d84f4f70e266c0a37f4ded04
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 import TestSCons
29 test = TestSCons.TestSCons()
31 test.subdir('src')
33 test.write('SConstruct',"""
34 VariantDir('var1', 'src', duplicate=0)
35 VariantDir('var2', 'src', duplicate=1)
36 SConscript('src/SConscript')
37 SConscript('var1/SConscript')
38 SConscript('var2/SConscript')
39 """)
41 test.write('src/SConscript',"""
42 def build(target, source, env):
43 for t in target:
44 with open(str(t), "wt") as f:
45 f.write(str(t))
47 def emitter(target, source, env):
48 target.append(str(target[0])+".foo")
49 return target,source
51 def emit1(t, s, e): return (t + ['emit.1'], s)
52 def emit2(t, s, e): return (t + ['emit.2'], s)
54 foo = Builder(action=build, emitter=emitter)
55 bar = Builder(action=build, emitter='$EMITTERS')
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 """)
64 test.write(['src', 'f.in'], 'f.in')
65 test.write(['src', 'g.in'], 'g.in')
66 test.write(['src', 'h.in'], 'h.in')
68 # Do 'src' last so that creation of the emitter files in there doesn't
69 # interfere with searching for them in the VariantDirs.
71 test.run(arguments='var2')
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'))
81 test.run(arguments = 'var1')
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'))
91 test.run(arguments = 'src')
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'))
101 test.pass_test()
103 # Local Variables:
104 # tab-width:4
105 # indent-tabs-mode:nil
106 # End:
107 # vim: set expandtab tabstop=4 shiftwidth=4: