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.
48 if os.name == 'posix':
49 os.environ['LD_LIBRARY_PATH'] = '.'
50 if string.find(sys.platform, 'irix') > -1:
51 os.environ['LD_LIBRARYN32_PATH'] = '.'
53 test = TestSCons.TestSCons()
55 test.subdir('bld', 'src', ['src', 'subsrcdir'])
58 foo = Environment(SHOBJPREFIX='', WINDOWS_INSERT_DEF=1)
59 foo.Append(SHCXXFLAGS = '-DFOO')
60 bar = Environment(SHOBJPREFIX='', WINDOWS_INSERT_DEF=1)
61 bar.Append(SHCXXFLAGS = '-DBAR')
63 VariantDir('bld', src, duplicate=1)
65 Nodes.extend(foo.SharedObject(target = 'foo%(_obj)s', source = 'prog.cpp'))
66 Nodes.extend(bar.SharedObject(target = 'bar%(_obj)s', source = 'prog.cpp'))
67 SConscript('bld/SConscript', ['Nodes'])
70 derived = map(lambda N: N.is_derived(), Nodes)
71 real1 = map(lambda N: os.path.exists(str(N)), Nodes)
72 exists = map(lambda N: N.exists(), Nodes)
73 real2 = map(lambda N: os.path.exists(str(N)), Nodes)
74 for N,D,R,E,F in map(None, Nodes, derived, real1, exists, real2):
75 print '%%s: %%s %%s %%s %%s'%%(N,D,R,E,F)
76 foo.SharedLibrary(target = 'foo', source = 'foo%(_obj)s')
77 bar.SharedLibrary(target = 'bar', source = 'bar%(_obj)s')
79 fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
80 foo_obj = fooMain.Object(target='foomain', source='main.c')
81 fooMain.Program(target='fooprog', source=foo_obj)
83 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
84 bar_obj = barMain.Object(target='barmain', source='main.c')
85 barMain.Program(target='barprog', source=bar_obj)
87 gooMain = foo.Clone(LIBS='goo', LIBPATH='bld')
88 goo_obj = gooMain.Object(target='goomain', source='main.c')
89 gooMain.Program(target='gooprog', source=goo_obj)
92 test.write('foo.def', r"""
99 test.write('bar.def', r"""
106 test.write('prog.cpp', r"""
113 printf("prog.cpp: FOO\n");
116 printf("prog.cpp: BAR\n");
128 except AttributeError:
130 __builtin__.False = 0
132 def mycopy(env, source, target):
133 open(str(target[0]),'w').write(open(str(source[0]),'r').read())
135 def exists_test(node):
136 before = os.path.exists(str(node)) # doesn't exist yet in VariantDir
137 via_node = node.exists() # side effect causes copy from src
138 after = os.path.exists(str(node))
141 if GetOption('no_exec'):
142 if (before,via_node,after) != (False,False,False):
144 sys.stderr.write('VariantDir exists() populated during dryrun!\n')
147 if (before,via_node,after) != (False,True,True):
149 sys.stderr.write('VariantDir exists() population did not occur! (%%s:%%s,%%s,%%s)\n'%%(str(node),before,via_node,after))
153 goo.Append(CFLAGS = '-DFOO')
154 goof_in = File('goof.in')
157 Nodes.append(goof_in)
158 Nodes.extend(goo.Command(target='goof.c', source='goof.in', action=mycopy))
159 boo_src = File('subsrcdir/boo.c')
162 boo_objs = goo.Object(target='subsrcdir/boo%(_obj)s', source = boo_src)
163 Nodes.extend(boo_objs)
164 Nodes.extend(goo.Object(target='goo%(_obj)s',source='goof.c'))
165 goo.Library(target = 'goo', source = ['goo%(_obj)s'] + boo_objs)
168 test.write(['src', 'goof.in'], r"""
171 extern char *boo_sub();
177 printf("prog.cpp: %s\n", boo_sub());
182 test.write(['src', 'subsrcdir', 'boo.c'], r"""
190 test.write('main.c', r"""
194 main(int argc, char* argv[])
201 builddir_srcnodes = [ os.path.join('bld', 'goof.in'),
202 os.path.join('bld', 'subsrcdir', 'boo.c'),
205 sub_build_nodes = [ os.path.join('bld', 'subsrcdir','boo' + _obj),
206 os.path.join('bld', 'goo' + _obj),
207 os.path.join('bld', 'goof.c'),
208 os.path.join('bld', lib_ + 'goo' + _lib),
211 build_nodes = ['fooprog' + _exe,
220 ] + builddir_srcnodes + sub_build_nodes
223 "cleanup after running a test"
224 for F in builddir_srcnodes:
225 test.unlink(F) # will be repopulated during clean operation
226 test.run(arguments = '-c')
227 for F in builddir_srcnodes:
229 for name in build_nodes:
230 test.must_not_exist(test.workpath(name))
233 ### First pass, make sure everything goes quietly
235 for name in build_nodes:
236 test.must_not_exist(test.workpath(name))
239 test.write('SConstruct', sconstruct % locals() )
240 test.write(['src', 'SConscript'], sconscript % locals() )
242 test.run(arguments = '.',
243 stderr=TestSCons.noisy_ar,
244 match=TestSCons.match_re_dotall)
246 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
247 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
248 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
250 for name in build_nodes:
251 test.must_exist(test.workpath(name))
255 ### Next pass: add internal Node ops that may have side effects to
256 ### ensure that those side-effects don't interfere with building
258 for name in build_nodes:
259 test.must_not_exist(test.workpath(name))
262 test.write('SConstruct', sconstruct % locals() )
263 test.write(['src', 'SConscript'], sconscript % locals() )
265 test.run(arguments = '.',
266 stderr=TestSCons.noisy_ar,
267 match=TestSCons.match_re_dotall)
269 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
270 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
271 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
273 for name in build_nodes:
274 test.must_exist(test.workpath(name))
278 ### Next pass: try a dry-run first and verify that it doesn't change
279 ### the buildability.
281 for name in build_nodes:
282 test.must_not_exist(test.workpath(name))
285 test.write('SConstruct', sconstruct % locals() )
286 test.write(['src', 'SConscript'], sconscript % locals() )
288 test.run(arguments = '-n .',
289 stderr=TestSCons.noisy_ar,
290 match=TestSCons.match_re_dotall)
292 for name in build_nodes:
293 test.must_not_exist(test.workpath(name))
295 test.run(arguments = '.',
296 stderr=TestSCons.noisy_ar,
297 match=TestSCons.match_re_dotall)
299 test.run(program = test.workpath('fooprog'), stdout = "prog.cpp: FOO\n")
300 test.run(program = test.workpath('barprog'), stdout = "prog.cpp: BAR\n")
301 test.run(program = test.workpath('gooprog'), stdout = "prog.cpp: GOO\n")
303 for name in build_nodes:
304 test.must_exist(test.workpath(name))
308 ### Next pass: do an up-build from a VariantDir src
311 for name in build_nodes:
312 test.must_not_exist(test.workpath(name))
315 test.write('SConstruct', sconstruct % locals() )
316 test.write(['src', 'SConscript'], sconscript % locals() )
318 test.run(chdir='src', arguments = '-u',
319 stderr=TestSCons.noisy_ar,
320 match=TestSCons.match_re_dotall)
322 for name in build_nodes:
323 if name in sub_build_nodes or name in builddir_srcnodes:
324 test.must_exist(test.workpath(name))
326 test.must_not_exist(test.workpath(name))
330 ### Next pass: do an up-build from a VariantDir src with Node Ops
333 for name in build_nodes:
334 test.must_not_exist(test.workpath(name))
337 test.write('SConstruct', sconstruct % locals() )
338 test.write(['src', 'SConscript'], sconscript % locals() )
340 test.run(chdir='src', arguments = '-u',
341 stderr=TestSCons.noisy_ar,
342 match=TestSCons.match_re_dotall)
344 for name in build_nodes:
345 if name in sub_build_nodes or name in builddir_srcnodes:
346 test.must_exist(test.workpath(name))
348 test.must_not_exist(test.workpath(name))