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 # This test is used to verify that the Buildability of a set of nodes
28 # is unaffected by various querying operations on those nodes:
30 # 1) Calling exists() on a Node (e.g. from find_file) in a VariantDir
31 # will cause that node to be duplicated into the builddir.
32 # However, this should *not* occur during a dryrun (-n). When not
33 # performed during a dryrun, this should not affect buildability.
34 # 2) Calling is_derived() should not affect buildability.
47 if os.name == 'posix':
48 os.environ['LD_LIBRARY_PATH'] = '.'
49 if sys.platform.find('irix') > -1:
50 os.environ['LD_LIBRARYN32_PATH'] = '.'
52 test = TestSCons.TestSCons()
54 test.subdir('bld', 'src', ['src', 'subsrcdir'])
57 foo = Environment(SHOBJPREFIX='', WINDOWS_INSERT_DEF=1)
58 foo.Append(SHCXXFLAGS = '-DFOO')
59 bar = Environment(SHOBJPREFIX='', WINDOWS_INSERT_DEF=1)
60 bar.Append(SHCXXFLAGS = '-DBAR')
62 VariantDir('bld', src, duplicate=1)
64 Nodes.extend(foo.SharedObject(target = 'foo%(_obj)s', source = 'prog.cpp'))
65 Nodes.extend(bar.SharedObject(target = 'bar%(_obj)s', source = 'prog.cpp'))
66 SConscript('bld/SConscript', ['Nodes'])
69 derived = [N.is_derived() for N in Nodes]
70 real1 = [os.path.exists(str(N)) for N in Nodes]
71 exists = [N.exists() for N in Nodes]
72 real2 = [os.path.exists(str(N)) for N in Nodes]
73 for N,D,R,E,F in zip(Nodes, derived, real1, exists, real2):
74 print '%%s: %%s %%s %%s %%s'%%(N,D,R,E,F)
75 foo.SharedLibrary(target = 'foo', source = 'foo%(_obj)s')
76 bar.SharedLibrary(target = 'bar', source = 'bar%(_obj)s')
78 fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
79 foo_obj = fooMain.Object(target='foomain', source='main.c')
80 fooMain.Program(target='fooprog', source=foo_obj)
82 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
83 bar_obj = barMain.Object(target='barmain', source='main.c')
84 barMain.Program(target='barprog', source=bar_obj)
86 gooMain = foo.Clone(LIBS='goo', LIBPATH='bld')
87 goo_obj = gooMain.Object(target='goomain', source='main.c')
88 gooMain.Program(target='gooprog', source=goo_obj)
91 test.write('foo.def', r"""
98 test.write('bar.def', r"""
105 test.write('prog.cpp', r"""
112 printf("prog.cpp: FOO\n");
115 printf("prog.cpp: BAR\n");
127 except AttributeError:
129 __builtin__.False = 0
131 def mycopy(env, source, target):
132 open(str(target[0]),'w').write(open(str(source[0]),'r').read())
134 def exists_test(node):
135 before = os.path.exists(str(node)) # doesn't exist yet in VariantDir
136 via_node = node.exists() # side effect causes copy from src
137 after = os.path.exists(str(node))
140 if GetOption('no_exec'):
141 if (before,via_node,after) != (False,False,False):
143 sys.stderr.write('VariantDir exists() populated during dryrun!\n')
146 if (before,via_node,after) != (False,True,True):
148 sys.stderr.write('VariantDir exists() population did not occur! (%%s:%%s,%%s,%%s)\n'%%(str(node),before,via_node,after))
152 goo.Append(CFLAGS = '-DFOO')
153 goof_in = File('goof.in')
156 Nodes.append(goof_in)
157 Nodes.extend(goo.Command(target='goof.c', source='goof.in', action=mycopy))
158 boo_src = File('subsrcdir/boo.c')
161 boo_objs = goo.Object(target='subsrcdir/boo%(_obj)s', source = boo_src)
162 Nodes.extend(boo_objs)
163 Nodes.extend(goo.Object(target='goo%(_obj)s',source='goof.c'))
164 goo.Library(target = 'goo', source = ['goo%(_obj)s'] + boo_objs)
167 test.write(['src', 'goof.in'], r"""
170 extern char *boo_sub();
176 printf("prog.cpp: %s\n", boo_sub());
181 test.write(['src', 'subsrcdir', 'boo.c'], r"""
189 test.write('main.c', r"""
193 main(int argc, char* argv[])
200 builddir_srcnodes = [ os.path.join('bld', 'goof.in'),
201 os.path.join('bld', 'subsrcdir', 'boo.c'),
204 sub_build_nodes = [ os.path.join('bld', 'subsrcdir','boo' + _obj),
205 os.path.join('bld', 'goo' + _obj),
206 os.path.join('bld', 'goof.c'),
207 os.path.join('bld', lib_ + 'goo' + _lib),
210 build_nodes = ['fooprog' + _exe,
219 ] + builddir_srcnodes + sub_build_nodes
222 "cleanup after running a test"
223 for F in builddir_srcnodes:
224 test.unlink(F) # will be repopulated during clean operation
225 test.run(arguments = '-c')
226 for F in builddir_srcnodes:
228 for name in build_nodes:
229 test.must_not_exist(test.workpath(name))
232 ### First pass, make sure everything goes quietly
234 for name in build_nodes:
235 test.must_not_exist(test.workpath(name))
238 test.write('SConstruct', sconstruct % locals() )
239 test.write(['src', 'SConscript'], sconscript % locals() )
241 test.run(arguments = '.',
242 stderr=TestSCons.noisy_ar,
243 match=TestSCons.match_re_dotall)
245 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
246 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
247 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
249 for name in build_nodes:
250 test.must_exist(test.workpath(name))
254 ### Next pass: add internal Node ops that may have side effects to
255 ### ensure that those side-effects don't interfere with building
257 for name in build_nodes:
258 test.must_not_exist(test.workpath(name))
261 test.write('SConstruct', sconstruct % locals() )
262 test.write(['src', 'SConscript'], sconscript % locals() )
264 test.run(arguments = '.',
265 stderr=TestSCons.noisy_ar,
266 match=TestSCons.match_re_dotall)
268 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
269 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
270 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
272 for name in build_nodes:
273 test.must_exist(test.workpath(name))
277 ### Next pass: try a dry-run first and verify that it doesn't change
278 ### the buildability.
280 for name in build_nodes:
281 test.must_not_exist(test.workpath(name))
284 test.write('SConstruct', sconstruct % locals() )
285 test.write(['src', 'SConscript'], sconscript % locals() )
287 test.run(arguments = '-n .',
288 stderr=TestSCons.noisy_ar,
289 match=TestSCons.match_re_dotall)
291 for name in build_nodes:
292 test.must_not_exist(test.workpath(name))
294 test.run(arguments = '.',
295 stderr=TestSCons.noisy_ar,
296 match=TestSCons.match_re_dotall)
298 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
299 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
300 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
302 for name in build_nodes:
303 test.must_exist(test.workpath(name))
307 ### Next pass: do an up-build from a VariantDir src
310 for name in build_nodes:
311 test.must_not_exist(test.workpath(name))
314 test.write('SConstruct', sconstruct % locals() )
315 test.write(['src', 'SConscript'], sconscript % locals() )
317 test.run(chdir='src', arguments = '-u',
318 stderr=TestSCons.noisy_ar,
319 match=TestSCons.match_re_dotall)
321 for name in build_nodes:
322 if name in sub_build_nodes or name in builddir_srcnodes:
323 test.must_exist(test.workpath(name))
325 test.must_not_exist(test.workpath(name))
329 ### Next pass: do an up-build from a VariantDir src with Node Ops
332 for name in build_nodes:
333 test.must_not_exist(test.workpath(name))
336 test.write('SConstruct', sconstruct % locals() )
337 test.write(['src', 'SConscript'], sconscript % locals() )
339 test.run(chdir='src', arguments = '-u',
340 stderr=TestSCons.noisy_ar,
341 match=TestSCons.match_re_dotall)
343 for name in build_nodes:
344 if name in sub_build_nodes or name in builddir_srcnodes:
345 test.must_exist(test.workpath(name))
347 test.must_not_exist(test.workpath(name))
355 # indent-tabs-mode:nil
357 # vim: set expandtab tabstop=4 shiftwidth=4: