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__"
28 Verify that specifying a build_dir argument to SConscript still works.
30 Note that the build_dir argument does not yet print a deprecation warning.
35 test = TestSCons.TestSCons()
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')
49 test.write(['test', 'SConstruct'], """
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')
62 def cat(env, source, target):
63 target = str(target[0])
64 source = map(str, source)
65 f = open(target, "wb")
67 f.write(open(src, "rb").read())
70 env = Environment(BUILDERS={'Cat':Builder(action=cat)},
75 SConscript('src/SConscript', build_dir=var1)
76 SConscript('src/SConscript', build_dir='build/var2', src_dir=src)
78 SConscript('src/SConscript', build_dir='build/var3', duplicate=0)
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)
86 #XXX SConscript('src/SConscript', build_dir='../build/var5', src_dir='alt')
87 SConscript('src/SConscript', build_dir=var6)
89 SConscript('src/SConscript', build_dir=var7, src_dir=src, duplicate=0)
90 env.SConscript('src/SConscript', build_dir='../$BUILD/var8', duplicate=0)
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:
97 # VariantDir('build/var9', '.')
98 # SConscript('build/var9/src/SConscript')
99 SConscript('src/SConscript', build_dir='build/var9', src_dir='.')
102 test.subdir(['test', 'src'], ['test', 'alt'])
104 test.write(['test', 'src', 'SConscript'], """
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'])
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")
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")
120 test.run(chdir='test', arguments = '. ../build')
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"
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)
141 def equal_stats(x,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])
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)))
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)))
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'))
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'))
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)))
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)))
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'))
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'))
206 test.write(['test2', 'SConstruct'], """\
207 SConscript('SConscript', build_dir='Build', src_dir='.', duplicate=0)
210 test.write(['test2', 'SConscript'], """\
212 foo_obj = env.Object('foo.c')
213 env.Program('foo', [foo_obj, 'bar.c'])
216 test.write(['test2', 'bar.c'], r"""
226 test.write(['test2', 'foo.c'], r"""
234 main(int argc, char *argv[]) {
240 test.run(chdir="test2")
242 _obj = TestSCons._obj
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))
250 # Make sure that directories for subsidiary SConscript() calls
251 # in a build_dir get created if they don't already exist.
254 test.subdir(['test3', 'src'], ['test3', 'src', '_glscry'])
256 test.write(['test3', 'SConstruct'], """\
257 SConscript(dirs=['src'], build_dir='build', duplicate=0)
260 test.write(['test3', 'src', 'SConscript'], """\
261 SConscript(dirs=['_glscry'])
264 test.write(['test3', 'src', '_glscry', 'SConscript'], """\
267 test.write(['test3', 'src', 'file.in'], "file.in\n")
269 test.write(['test3', 'src', '_glscry', 'file.in'], "file.in\n")
271 test.run(chdir='test3')
278 # indent-tabs-mode:nil
280 # vim: set expandtab tabstop=4 shiftwidth=4: