3 # Copyright (c) 2001, 2002 Steven Knight
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__"
30 test = TestSCons.TestSCons()
32 test.write('SConstruct', """
33 def build(env, target, source):
34 file = open(str(target[0]), 'wb')
36 file.write(open(str(s), 'rb').read())
38 B = Builder(name='B', action=build, multi=1)
39 env = Environment(BUILDERS = [B])
40 env.B(target = 'foo.out', source = 'foo.in')
41 env.B(target = 'foo.out', source = 'bar.in')
44 test.write('foo.in', 'foo.in\n')
45 test.write('bar.in', 'bar.in\n')
47 test.run(arguments='foo.out')
49 test.fail_test(not os.path.exists(test.workpath('foo.out')))
50 test.fail_test(not test.read('foo.out') == 'foo.in\nbar.in\n')
52 test.write('SConstruct', """
53 def build(env, target, source):
54 file = open(str(target[0]), 'wb')
56 file.write(open(str(s), 'rb').read())
58 B = Builder(name='B', action=build, multi=0)
59 env = Environment(BUILDERS = [B])
60 env.B(target = 'foo.out', source = 'foo.in')
61 env.B(target = 'foo.out', source = 'bar.in')
64 test.run(arguments='foo.out',
67 SCons error: Multiple ways to build the same target were specified for: foo.out
68 File "SConstruct", line 10, in ?
71 test.write('SConstruct', """
72 def build(env, target, source):
73 file = open(str(target[0]), 'wb')
75 file.write(open(str(s), 'rb').read())
77 B = Builder(name='B', action=build, multi=1)
78 env = Environment(BUILDERS = [B])
79 env.B(target = 'foo.out', source = 'foo.in', foo=1)
80 env.B(target = 'foo.out', source = 'bar.in', foo=2)
83 test.run(arguments='foo.out',
86 SCons error: Two different sets of build arguments were specified for the same target: foo.out
87 File "SConstruct", line 10, in ?
90 test.write('SConstruct', """
91 def build(env, target, source):
92 file = open(str(target[0]), 'wb')
94 file.write(open(str(s), 'rb').read())
96 B = Builder(name='B', action=build, multi=1)
97 env = Environment(BUILDERS = [B])
98 env2 = env.Copy(CCFLAGS='foo')
99 env.B(target = 'foo.out', source = 'foo.in')
100 env2.B(target = 'foo.out', source = 'bar.in')
103 test.run(arguments='foo.out',
106 SCons error: Two different environments were specified for the same target: foo.out
107 File "SConstruct", line 11, in ?
110 test.write('SConstruct', """
111 def build(env, target, source):
112 file = open(str(target[0]), 'wb')
114 file.write(open(str(s), 'rb').read())
116 B = Builder(name='B', action=build, multi=0)
117 env = Environment(BUILDERS = [B])
118 env.B(target = 'foo.out', source = 'foo.in')
119 env.B(target = 'foo.out', source = 'foo.in')
122 test.run(arguments='foo.out')
123 test.fail_test(not test.read('foo.out') == 'foo.in\n')
125 test.write('SConstruct', """
126 def build(env, target, source):
127 file = open(str(target[0]), 'wb')
129 file.write(open(str(s), 'rb').read())
131 B = Builder(name='B', action=build, multi=1)
132 C = Builder(name='C', action=build, multi=1)
133 env = Environment(BUILDERS = [B,C])
134 env.B(target = 'foo.out', source = 'foo.in')
135 env.C(target = 'foo.out', source = 'bar.in')
138 test.run(arguments='foo.out',
141 SCons error: Two different builders (B and C) were specified for the same target: foo.out
142 File "SConstruct", line 11, in ?
145 test.write('SConstruct', """
146 def build(env, target, source):
148 file = open(str(t), 'wb')
150 file.write(open(str(s), 'rb').read())
152 B = Builder(name='B', action=build, multi=1)
153 env = Environment(BUILDERS = [B])
154 env.B(target = ['foo.out', 'bar.out'], source = 'foo.in')
155 env.B(target = ['foo.out', 'bar.out'], source = 'bar.in')
158 test.run(arguments='bar.out')
159 test.fail_test(not os.path.exists(test.workpath('bar.out')))
160 test.fail_test(not test.read('bar.out') == 'foo.in\nbar.in\n')
161 test.fail_test(not os.path.exists(test.workpath('foo.out')))
162 test.fail_test(not test.read('foo.out') == 'foo.in\nbar.in\n')
164 test.write('SConstruct', """
165 def build(env, target, source):
167 file = open(str(target[0]), 'wb')
169 file.write(open(str(s), 'rb').read())
171 B = Builder(name='B', action=build, multi=1)
172 env = Environment(BUILDERS = [B])
173 env.B(target = ['foo.out', 'bar.out'], source = 'foo.in')
174 env.B(target = ['bar.out', 'foo.out'], source = 'bar.in')
177 # This is intentional. The order of the targets matter to the
178 # builder because the build command can contain things like ${TARGET[0]}:
179 test.run(arguments='foo.out',
182 SCons error: Two different target sets have a target in common: bar.out
183 File "SConstruct", line 11, in ?
186 # XXX It would be nice if the following two tests could be made to
187 # work by executing the action once for each unique set of
188 # targets. This would make it simple to deal with PDB files on Windows like so:
190 # env.Object(['foo.obj', 'vc60.pdb'], 'foo.c')
191 # env.Object(['bar.obj', 'vc60.pdb'], 'bar.c')
193 test.write('SConstruct', """
194 def build(env, target, source):
196 file = open(str(target[0]), 'wb')
198 file.write(open(str(s), 'rb').read())
200 B = Builder(name='B', action=build, multi=1)
201 env = Environment(BUILDERS = [B])
202 env.B(target = ['foo.out', 'bar.out'], source = 'foo.in')
203 env.B(target = ['bar.out', 'blat.out'], source = 'bar.in')
206 test.run(arguments='foo.out',
209 SCons error: Two different target sets have a target in common: bar.out
210 File "SConstruct", line 11, in ?
213 test.write('SConstruct', """
214 def build(env, target, source):
216 file = open(str(target[0]), 'wb')
218 file.write(open(str(s), 'rb').read())
220 B = Builder(name='B', action=build, multi=1)
221 env = Environment(BUILDERS = [B])
222 env.B(target = ['foo.out', 'bar.out'], source = 'foo.in')
223 env.B(target = 'foo.out', source = 'bar.in')
226 test.run(arguments='foo.out',
229 SCons error: Two different builders (ListBuilder(B) and B) were specified for the same target: foo.out
230 File "SConstruct", line 11, in ?