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 BuildDir
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.
35 # 3) Calling is_pseudo_derived() may cause the sbuilder to be set, and
36 # it may caues the builder to be set as well, but it should not
37 # adversely affect buildability.
51 if sys.platform == 'win32':
52 fooflags = '/nologo -DFOO'
53 barflags = '/nologo -DBAR'
58 if os.name == 'posix':
59 os.environ['LD_LIBRARY_PATH'] = '.'
60 if string.find(sys.platform, 'irix') > -1:
61 os.environ['LD_LIBRARYN32_PATH'] = '.'
63 test = TestSCons.TestSCons()
65 test.subdir('bld', 'src', ['src', 'subsrcdir'])
68 foo = Environment(SHCXXFLAGS = '%(fooflags)s', WINDOWS_INSERT_DEF=1)
69 bar = Environment(SHCXXFLAGS = '%(barflags)s', WINDOWS_INSERT_DEF=1)
71 BuildDir('bld', src, duplicate=1)
73 Nodes.extend(foo.SharedObject(target = 'foo%(_obj)s', source = 'prog.cpp'))
74 Nodes.extend(bar.SharedObject(target = 'bar%(_obj)s', source = 'prog.cpp'))
75 SConscript('bld/SConscript', ['Nodes'])
78 derived = map(lambda N: N.is_derived(), Nodes)
79 p_derived = map(lambda N: N.is_pseudo_derived(), Nodes)
80 real1 = map(lambda N: os.path.exists(str(N)), Nodes)
81 exists = map(lambda N: N.exists(), Nodes)
82 real2 = map(lambda N: os.path.exists(str(N)), Nodes)
83 for N,D,P,R,E,F in map(None, Nodes, derived, p_derived,
84 real1, exists, real2):
85 print '%%s: %%s %%s %%s %%s %%s'%%(N,D,P,R,E,F)
86 foo.SharedLibrary(target = 'foo', source = 'foo%(_obj)s')
87 bar.SharedLibrary(target = 'bar', source = 'bar%(_obj)s')
89 fooMain = foo.Copy(LIBS='foo', LIBPATH='.')
90 foo_obj = fooMain.Object(target='foomain', source='main.c')
91 fooMain.Program(target='fooprog', source=foo_obj)
93 barMain = bar.Copy(LIBS='bar', LIBPATH='.')
94 bar_obj = barMain.Object(target='barmain', source='main.c')
95 barMain.Program(target='barprog', source=bar_obj)
97 gooMain = foo.Copy(LIBS='goo', LIBPATH='bld')
98 goo_obj = gooMain.Object(target='goomain', source='main.c')
99 gooMain.Program(target='gooprog', source=goo_obj)
103 test.write('foo.def', r"""
105 DESCRIPTION "Foo Shared Library"
111 test.write('bar.def', r"""
113 DESCRIPTION "Bar Shared Library"
119 test.write('prog.cpp', r"""
126 printf("prog.cpp: FOO\n");
129 printf("prog.cpp: BAR\n");
141 except AttributeError:
143 __builtin__.False = 0
145 def mycopy(env, source, target):
146 open(str(target[0]),'w').write(open(str(source[0]),'r').read())
148 def exists_test(node):
149 before = os.path.exists(str(node)) # doesn't exist yet in BuildDir
150 via_node = node.exists() # side effect causes copy from src
151 after = os.path.exists(str(node))
153 node.is_pseudo_derived()
155 if SCons.Script.Main.options.noexec:
156 if (before,via_node,after) != (False,False,False):
158 sys.stderr.write('BuildDir exits() populated during dryrun!\n')
161 if (before,via_node,after) != (False,True,True):
163 sys.stderr.write('BuildDir exists() population did not occur! (%%s:%%s,%%s,%%s)\n'%%(str(node),before,via_node,after))
166 goo = Environment(CPPFLAGS = '%(fooflags)s')
167 goof_in = File('goof.in')
170 Nodes.append(goof_in)
171 Nodes.extend(goo.Command(target='goof.c', source='goof.in', action=mycopy))
172 boo_src = File('subsrcdir/boo.c')
175 boo_objs = goo.Object(target='subsrcdir/boo%(_obj)s', source = boo_src)
176 Nodes.extend(boo_objs)
177 Nodes.extend(goo.Object(target='goo%(_obj)s',source='goof.c'))
178 goo.Library(target = 'goo', source = ['goo%(_obj)s'] + boo_objs)
181 test.write(['src', 'goof.in'], r"""
184 extern char *boo_sub();
190 printf("prog.cpp: %s\n", boo_sub());
195 test.write(['src', 'subsrcdir', 'boo.c'], r"""
203 test.write('main.c', r"""
208 main(int argc, char* argv[])
215 builddir_srcnodes = [ os.path.join('bld', 'goof.in'),
216 os.path.join('bld', 'subsrcdir', 'boo.c'),
219 sub_build_nodes = [ os.path.join('bld', 'subsrcdir','boo' + _obj),
220 os.path.join('bld', 'goo' + _obj),
221 os.path.join('bld', 'goof.c'),
222 os.path.join('bld', lib_ + 'goo' + _lib),
225 build_nodes = ['fooprog' + _exe,
234 ] + builddir_srcnodes + sub_build_nodes
237 "cleanup after running a test"
238 for F in builddir_srcnodes:
239 test.unlink(F) # will be repopulated during clean operation
240 test.run(arguments = '-c')
241 for F in builddir_srcnodes:
243 for name in build_nodes:
244 test.must_not_exist(test.workpath(name))
247 ### First pass, make sure everything goes quietly
249 for name in build_nodes:
250 test.must_not_exist(test.workpath(name))
253 test.write('SConstruct', sconstruct % locals() )
254 test.write(['src', 'SConscript'], sconscript % locals() )
256 test.run(arguments = '.',
257 stderr=TestSCons.noisy_ar,
258 match=TestSCons.match_re_dotall)
260 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
261 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
262 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
264 for name in build_nodes:
265 test.must_exist(test.workpath(name))
269 ### Next pass: add internal Node ops that may have side effects to
270 ### ensure that those side-effects don't interfere with building
272 for name in build_nodes:
273 test.must_not_exist(test.workpath(name))
276 test.write('SConstruct', sconstruct % locals() )
277 test.write(['src', 'SConscript'], sconscript % locals() )
279 test.run(arguments = '.',
280 stderr=TestSCons.noisy_ar,
281 match=TestSCons.match_re_dotall)
283 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
284 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
285 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
287 for name in build_nodes:
288 test.must_exist(test.workpath(name))
292 ### Next pass: try a dry-run first and verify that it doesn't change
293 ### the buildability.
295 for name in build_nodes:
296 test.must_not_exist(test.workpath(name))
299 test.write('SConstruct', sconstruct % locals() )
300 test.write(['src', 'SConscript'], sconscript % locals() )
302 test.run(arguments = '-n .',
303 stderr=TestSCons.noisy_ar,
304 match=TestSCons.match_re_dotall)
306 for name in build_nodes:
307 test.must_not_exist(test.workpath(name))
309 test.run(arguments = '.',
310 stderr=TestSCons.noisy_ar,
311 match=TestSCons.match_re_dotall)
313 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
314 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
315 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
317 for name in build_nodes:
318 test.must_exist(test.workpath(name))
322 ### Next pass: do an up-build from a BuildDir src
325 for name in build_nodes:
326 test.must_not_exist(test.workpath(name))
329 test.write('SConstruct', sconstruct % locals() )
330 test.write(['src', 'SConscript'], sconscript % locals() )
332 test.run(chdir='src', arguments = '-u',
333 stderr=TestSCons.noisy_ar,
334 match=TestSCons.match_re_dotall)
336 for name in build_nodes:
337 if name in sub_build_nodes or name in builddir_srcnodes:
338 test.must_exist(test.workpath(name))
340 test.must_not_exist(test.workpath(name))
344 ### Next pass: do an up-build from a BuildDir src with Node Ops
347 for name in build_nodes:
348 test.must_not_exist(test.workpath(name))
351 test.write('SConstruct', sconstruct % locals() )
352 test.write(['src', 'SConscript'], sconscript % locals() )
354 test.run(chdir='src', arguments = '-u',
355 stderr=TestSCons.noisy_ar,
356 match=TestSCons.match_re_dotall)
358 for name in build_nodes:
359 if name in sub_build_nodes or name in builddir_srcnodes:
360 test.must_exist(test.workpath(name))
362 test.must_not_exist(test.workpath(name))