d54f3afd940de0022546a2e9b3f4264de47a1f2d
[scons.git] / test / Deprecated / SConscript-build_dir.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 """
28 Verify that specifying a build_dir argument to SConscript still works.
29
30 Note that the build_dir argument does not yet print a deprecation warning.
31 """
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 all1 = test.workpath('test', 'build', 'var1', 'all')
38 all2 = test.workpath('test', 'build', 'var2', 'all')
39 all3 = test.workpath('test', 'build', 'var3', 'all')
40 all4 = test.workpath('test', 'build', 'var4', 'all')
41 all5 = test.workpath('build', 'var5', 'all')
42 all6 = test.workpath('build', 'var6', 'all')
43 all7 = test.workpath('build', 'var7', 'all')
44 all8 = test.workpath('build', 'var8', 'all')
45 all9 = test.workpath('test', 'build', 'var9', 'src', 'all')
46
47 test.subdir('test')
48
49 test.write(['test', 'SConstruct'], """
50 src = Dir('src')
51 alt = Dir('alt')
52 var1 = Dir('build/var1')
53 var2 = Dir('build/var2')
54 var3 = Dir('build/var3')
55 var4 = Dir('build/var4')
56 var5 = Dir('../build/var5')
57 var6 = Dir('../build/var6')
58 var7 = Dir('../build/var7')
59 var8 = Dir('../build/var8')
60 var9 = Dir('../build/var9')
61
62 def cat(env, source, target):
63     target = str(target[0])
64     source = map(str, source)
65     f = open(target, "wb")
66     for src in source:
67         f.write(open(src, "rb").read())
68     f.close()
69
70 env = Environment(BUILDERS={'Cat':Builder(action=cat)},
71                   BUILD='build')
72
73 Export("env")
74
75 SConscript('src/SConscript', build_dir=var1)
76 SConscript('src/SConscript', build_dir='build/var2', src_dir=src)
77
78 SConscript('src/SConscript', build_dir='build/var3', duplicate=0)
79
80 #XXX We can't support var4 and var5 yet, because our VariantDir linkage
81 #XXX is to an entire source directory.  We haven't yet generalized our
82 #XXX infrastructure to be able to take the SConscript file from one source
83 #XXX directory, but the rest of the files from a different one.
84 #XXX SConscript('src/SConscript', build_dir=var4, src_dir=alt, duplicate=0)
85
86 #XXX SConscript('src/SConscript', build_dir='../build/var5', src_dir='alt')
87 SConscript('src/SConscript', build_dir=var6)
88
89 SConscript('src/SConscript', build_dir=var7, src_dir=src, duplicate=0)
90 env.SConscript('src/SConscript', build_dir='../$BUILD/var8', duplicate=0)
91
92 # This tests the fact that if you specify a src_dir that is above
93 # the dir a SConscript is in, that we do the intuitive thing, i.e.,
94 # we set the path of the SConscript accordingly.  The below is
95 # equivalent to saying:
96 #
97 # VariantDir('build/var9', '.')
98 # SConscript('build/var9/src/SConscript')
99 SConscript('src/SConscript', build_dir='build/var9', src_dir='.')
100 """) 
101
102 test.subdir(['test', 'src'], ['test', 'alt'])
103
104 test.write(['test', 'src', 'SConscript'], """
105 Import("env")
106 env.Cat('aaa.out', 'aaa.in')
107 env.Cat('bbb.out', 'bbb.in')
108 env.Cat('ccc.out', 'ccc.in')
109 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
110 """)
111
112 test.write('test/src/aaa.in', "test/src/aaa.in\n")
113 test.write('test/src/bbb.in', "test/src/bbb.in\n")
114 test.write('test/src/ccc.in', "test/src/ccc.in\n")
115
116 test.write('test/alt/aaa.in', "test/alt/aaa.in\n")
117 test.write('test/alt/bbb.in', "test/alt/bbb.in\n")
118 test.write('test/alt/ccc.in', "test/alt/ccc.in\n")
119
120 test.run(chdir='test', arguments = '. ../build')
121
122 all_src = "test/src/aaa.in\ntest/src/bbb.in\ntest/src/ccc.in\n"
123 all_alt = "test/alt/aaa.in\ntest/alt/bbb.in\ntest/alt/ccc.in\n"
124
125 test.must_match(all1, all_src)
126 test.must_match(all2, all_src)
127 test.must_match(all3, all_src)
128 #XXX We can't support var4 and var5 yet, because our VariantDir linkage
129 #XXX is to an entire source directory.  We haven't yet generalized our
130 #XXX infrastructure to be able to take the SConscript file from one source
131 #XXX directory, but the rest of the files from a different one.
132 #XXX test.must_match(all4, all_alt)
133 #XXX test.must_match(all5, all_alt)
134 test.must_match(all6, all_src)
135 test.must_match(all7, all_src)
136 test.must_match(all8, all_src)
137 test.must_match(all9, all_src)
138
139 import os
140 import stat
141 def equal_stats(x,y):
142     x = os.stat(x)
143     y = os.stat(y)
144     return (stat.S_IMODE(x[stat.ST_MODE]) == stat.S_IMODE(y[stat.ST_MODE]) and
145             x[stat.ST_MTIME] ==  y[stat.ST_MTIME])
146
147 # Make sure we did duplicate the source files in build/var1,
148 # and that their stats are the same:
149 for file in ['aaa.in', 'bbb.in', 'ccc.in']:
150     test.must_exist(test.workpath('test', 'build', 'var1', file))
151     test.fail_test(not equal_stats(test.workpath('test', 'build', 'var1', file),
152                                    test.workpath('test', 'src', file)))
153
154 # Make sure we did duplicate the source files in build/var2,
155 # and that their stats are the same:
156 for file in ['aaa.in', 'bbb.in', 'ccc.in']:
157     test.must_exist(test.workpath('test', 'build', 'var2', file))
158     test.fail_test(not equal_stats(test.workpath('test', 'build', 'var2', file),
159                                    test.workpath('test', 'src', file)))
160  
161 # Make sure we didn't duplicate the source files in build/var3.
162 test.must_not_exist(test.workpath('test', 'build', 'var3', 'aaa.in'))
163 test.must_not_exist(test.workpath('test', 'build', 'var3', 'bbb.in'))
164 test.must_not_exist(test.workpath('test', 'build', 'var3', 'ccc.in'))
165  
166 #XXX We can't support var4 and var5 yet, because our VariantDir linkage
167 #XXX is to an entire source directory.  We haven't yet generalized our
168 #XXX infrastructure to be able to take the SConscript file from one source
169 #XXX directory, but the rest of the files from a different one.
170 #XXX Make sure we didn't duplicate the source files in build/var4.
171 #XXXtest.must_not_exist(test.workpath('test', 'build', 'var4', 'aaa.in'))
172 #XXXtest.must_not_exist(test.workpath('test', 'build', 'var4', 'bbb.in'))
173 #XXXtest.must_not_exist(test.workpath('test', 'build', 'var4', 'ccc.in'))
174
175 #XXX We can't support var4 and var5 yet, because our VariantDir linkage
176 #XXX is to an entire source directory.  We haven't yet generalized our
177 #XXX infrastructure to be able to take the SConscript file from one source
178 #XXX directory, but the rest of the files from a different one.
179 #XXX Make sure we did duplicate the source files in build/var5,
180 #XXX and that their stats are the same:
181 #XXXfor file in ['aaa.in', 'bbb.in', 'ccc.in']:
182 #XXX    test.must_exist(test.workpath('build', 'var5', file))
183 #XXX    test.fail_test(not equal_stats(test.workpath('build', 'var5', file),
184 #XXX                                   test.workpath('test', 'src', file)))
185
186 # Make sure we did duplicate the source files in build/var6,
187 # and that their stats are the same:
188 for file in ['aaa.in', 'bbb.in', 'ccc.in']:
189     test.must_exist(test.workpath('build', 'var6', file))
190     test.fail_test(not equal_stats(test.workpath('build', 'var6', file),
191                                    test.workpath('test', 'src', file)))
192  
193 # Make sure we didn't duplicate the source files in build/var7.
194 test.must_not_exist(test.workpath('build', 'var7', 'aaa.in'))
195 test.must_not_exist(test.workpath('build', 'var7', 'bbb.in'))
196 test.must_not_exist(test.workpath('build', 'var7', 'ccc.in'))
197  
198 # Make sure we didn't duplicate the source files in build/var8.
199 test.must_not_exist(test.workpath('build', 'var8', 'aaa.in'))
200 test.must_not_exist(test.workpath('build', 'var8', 'bbb.in'))
201 test.must_not_exist(test.workpath('build', 'var8', 'ccc.in'))
202
203 ###################
204 test.subdir('test2')
205
206 test.write(['test2', 'SConstruct'], """\
207 SConscript('SConscript', build_dir='Build', src_dir='.', duplicate=0)
208 """)
209
210 test.write(['test2', 'SConscript'], """\
211 env = Environment()
212 foo_obj = env.Object('foo.c')
213 env.Program('foo', [foo_obj, 'bar.c'])
214 """)
215
216 test.write(['test2', 'bar.c'], r"""
217 #include <stdio.h>
218 #include <stdlib.h>
219
220 void
221 bar(void) {
222         printf("bar.c\n");
223 }
224 """)
225
226 test.write(['test2', 'foo.c'], r"""
227 #include <stdio.h>
228 #include <stdlib.h>
229
230 extern void
231 bar(void);
232
233 int
234 main(int argc, char *argv[]) {
235         bar();
236         printf("foo.c\n");
237 }
238 """)
239
240 test.run(chdir="test2")
241
242 _obj = TestSCons._obj
243
244 test.must_not_exist(test.workpath('test2', 'foo' + _obj))
245 test.must_not_exist(test.workpath('test2', 'bar' + _obj))
246 test.must_exist(test.workpath('test2', 'Build', 'foo' + _obj))
247 test.must_exist(test.workpath('test2', 'Build', 'bar' + _obj))
248
249 ###################
250 # Make sure that directories for subsidiary SConscript() calls
251 # in a build_dir get created if they don't already exist.
252 test.subdir('test3')
253
254 test.subdir(['test3', 'src'], ['test3', 'src', '_glscry'])
255
256 test.write(['test3', 'SConstruct'], """\
257 SConscript(dirs=['src'], build_dir='build', duplicate=0)
258 """)
259
260 test.write(['test3', 'src', 'SConscript'], """\
261 SConscript(dirs=['_glscry'])
262 """)
263
264 test.write(['test3', 'src', '_glscry', 'SConscript'], """\
265 """)
266
267 test.write(['test3', 'src', 'file.in'], "file.in\n")
268
269 test.write(['test3', 'src', '_glscry', 'file.in'], "file.in\n")
270
271 test.run(chdir='test3')
272
273
274 test.pass_test()
275
276 # Local Variables:
277 # tab-width:4
278 # indent-tabs-mode:nil
279 # End:
280 # vim: set expandtab tabstop=4 shiftwidth=4: