5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
41 from TestSCons
import _exe
, lib_
, _lib
, _obj
, dll_
, _dll
43 if os
.name
== 'posix':
44 os
.environ
['LD_LIBRARY_PATH'] = '.'
45 if sys
.platform
.find('irix') > -1:
46 os
.environ
['LD_LIBRARYN32_PATH'] = '.'
48 test
= TestSCons
.TestSCons()
50 test
.subdir('bld', 'src', ['src', 'subsrcdir'])
53 DefaultEnvironment(tools=[]) # test speedup
54 foo = Environment(SHOBJPREFIX='', WINDOWS_INSERT_DEF=1)
55 foo.Append(SHCXXFLAGS = '-DFOO')
56 bar = Environment(SHOBJPREFIX='', WINDOWS_INSERT_DEF=1)
57 bar.Append(SHCXXFLAGS = '-DBAR')
59 VariantDir('bld', src, duplicate=1)
61 Nodes.extend(foo.SharedObject(target = 'foo%(_obj)s', source = 'prog.cpp'))
62 Nodes.extend(bar.SharedObject(target = 'bar%(_obj)s', source = 'prog.cpp'))
63 SConscript('bld/SConscript', ['Nodes'])
66 derived = [N.is_derived() for N in Nodes]
67 real1 = [os.path.exists(str(N)) for N in Nodes]
68 exists = [N.exists() for N in Nodes]
69 real2 = [os.path.exists(str(N)) for N in Nodes]
70 for N,D,R,E,F in zip(Nodes, derived, real1, exists, real2):
71 print('%%s: %%s %%s %%s %%s'%%(N,D,R,E,F))
72 foo.SharedLibrary(target = 'foo', source = 'foo%(_obj)s')
73 bar.SharedLibrary(target = 'bar', source = 'bar%(_obj)s')
75 fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
76 foo_obj = fooMain.Object(target='foomain', source='main.c')
77 fooMain.Program(target='fooprog', source=foo_obj)
79 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
80 bar_obj = barMain.Object(target='barmain', source='main.c')
81 barMain.Program(target='barprog', source=bar_obj)
83 gooMain = foo.Clone(LIBS='goo', LIBPATH='bld')
84 goo_obj = gooMain.Object(target='goomain', source='main.c')
85 gooMain.Program(target='gooprog', source=goo_obj)
88 test
.write('foo.def', r
"""
95 test
.write('bar.def', r
"""
102 test
.write('prog.cpp', r
"""
109 printf("prog.cpp: FOO\n");
112 printf("prog.cpp: BAR\n");
121 def mycopy(env, source, target):
122 with open(str(target[0]), 'wt') as fo, open(str(source[0]), 'rt') as fi:
125 def exists_test(node):
126 before = os.path.exists(str(node)) # doesn't exist yet in VariantDir
127 via_node = node.exists() # side effect causes copy from src
128 after = os.path.exists(str(node))
131 if GetOption('no_exec'):
132 if (before,via_node,after) != (False,False,False):
134 sys.stderr.write('VariantDir exists() populated during dryrun!\n')
137 if (before,via_node,after) != (False,True,True):
139 sys.stderr.write('VariantDir exists() population did not occur! (%%s:%%s,%%s,%%s)\n'%%(str(node),before,via_node,after))
143 goo.Append(CFLAGS = '-DFOO')
144 goof_in = File('goof.in')
147 Nodes.append(goof_in)
148 Nodes.extend(goo.Command(target='goof.c', source='goof.in', action=mycopy))
149 boo_src = File('subsrcdir/boo.c')
152 boo_objs = goo.Object(target='subsrcdir/boo%(_obj)s', source = boo_src)
153 Nodes.extend(boo_objs)
154 Nodes.extend(goo.Object(target='goo%(_obj)s',source='goof.c'))
155 goo.Library(target = 'goo', source = ['goo%(_obj)s'] + boo_objs)
158 test
.write(['src', 'goof.in'], r
"""
161 extern char *boo_sub();
167 printf("prog.cpp: %s\n", boo_sub());
172 test
.write(['src', 'subsrcdir', 'boo.c'], r
"""
180 test
.write('main.c', r
"""
184 main(int argc, char* argv[])
191 builddir_srcnodes
= [ os
.path
.join('bld', 'goof.in'),
192 os
.path
.join('bld', 'subsrcdir', 'boo.c'),
195 sub_build_nodes
= [ os
.path
.join('bld', 'subsrcdir','boo' + _obj
),
196 os
.path
.join('bld', 'goo' + _obj
),
197 os
.path
.join('bld', 'goof.c'),
198 os
.path
.join('bld', lib_
+ 'goo' + _lib
),
201 build_nodes
= ['fooprog' + _exe
,
210 ] + builddir_srcnodes
+ sub_build_nodes
213 """cleanup after running a test"""
214 for F
in builddir_srcnodes
:
215 test
.unlink(F
) # will be repopulated during clean operation
216 test
.run(arguments
= '-c')
217 for F
in builddir_srcnodes
:
219 for name
in build_nodes
:
220 test
.must_not_exist(test
.workpath(name
))
223 ### First pass, make sure everything goes quietly
225 for name
in build_nodes
:
226 test
.must_not_exist(test
.workpath(name
))
229 test
.write('SConstruct', sconstruct
% locals() )
230 test
.write(['src', 'SConscript'], sconscript
% locals() )
232 test
.run(arguments
= '.',
233 stderr
=TestSCons
.noisy_ar
,
234 match
=TestSCons
.match_re_dotall
)
236 test
.run(program
= test
.workpath('fooprog'), stdout
= "prog.cpp: FOO\n")
237 test
.run(program
= test
.workpath('barprog'), stdout
= "prog.cpp: BAR\n")
238 test
.run(program
= test
.workpath('gooprog'), stdout
= "prog.cpp: GOO\n")
240 for name
in build_nodes
:
241 test
.must_exist(test
.workpath(name
))
245 ### Next pass: add internal Node ops that may have side effects to
246 ### ensure that those side-effects don't interfere with building
248 for name
in build_nodes
:
249 test
.must_not_exist(test
.workpath(name
))
252 test
.write('SConstruct', sconstruct
% locals() )
253 test
.write(['src', 'SConscript'], sconscript
% locals() )
255 test
.run(arguments
= '.',
256 stderr
=TestSCons
.noisy_ar
,
257 match
=TestSCons
.match_re_dotall
)
259 test
.run(program
= test
.workpath('fooprog'), stdout
= "prog.cpp: FOO\n")
260 test
.run(program
= test
.workpath('barprog'), stdout
= "prog.cpp: BAR\n")
261 test
.run(program
= test
.workpath('gooprog'), stdout
= "prog.cpp: GOO\n")
263 for name
in build_nodes
:
264 test
.must_exist(test
.workpath(name
))
268 ### Next pass: try a dry-run first and verify that it doesn't change
269 ### the buildability.
271 for name
in build_nodes
:
272 test
.must_not_exist(test
.workpath(name
))
275 test
.write('SConstruct', sconstruct
% locals() )
276 test
.write(['src', 'SConscript'], sconscript
% locals() )
278 test
.run(arguments
= '-n .',
279 stderr
=TestSCons
.noisy_ar
,
280 match
=TestSCons
.match_re_dotall
)
282 for name
in build_nodes
:
283 test
.must_not_exist(test
.workpath(name
))
285 test
.run(arguments
= '.',
286 stderr
=TestSCons
.noisy_ar
,
287 match
=TestSCons
.match_re_dotall
)
289 test
.run(program
= test
.workpath('fooprog'), stdout
= "prog.cpp: FOO\n")
290 test
.run(program
= test
.workpath('barprog'), stdout
= "prog.cpp: BAR\n")
291 test
.run(program
= test
.workpath('gooprog'), stdout
= "prog.cpp: GOO\n")
293 for name
in build_nodes
:
294 test
.must_exist(test
.workpath(name
))
298 ### Next pass: do an up-build from a VariantDir src
301 for name
in build_nodes
:
302 test
.must_not_exist(test
.workpath(name
))
305 test
.write('SConstruct', sconstruct
% locals() )
306 test
.write(['src', 'SConscript'], sconscript
% locals() )
308 test
.run(chdir
='src', arguments
= '-u',
309 stderr
=TestSCons
.noisy_ar
,
310 match
=TestSCons
.match_re_dotall
)
312 for name
in build_nodes
:
313 if name
in sub_build_nodes
or name
in builddir_srcnodes
:
314 test
.must_exist(test
.workpath(name
))
316 test
.must_not_exist(test
.workpath(name
))
320 ### Next pass: do an up-build from a VariantDir src with Node Ops
323 for name
in build_nodes
:
324 test
.must_not_exist(test
.workpath(name
))
327 test
.write('SConstruct', sconstruct
% locals() )
328 test
.write(['src', 'SConscript'], sconscript
% locals() )
330 test
.run(chdir
='src', arguments
= '-u',
331 stderr
=TestSCons
.noisy_ar
,
332 match
=TestSCons
.match_re_dotall
)
334 for name
in build_nodes
:
335 if name
in sub_build_nodes
or name
in builddir_srcnodes
:
336 test
.must_exist(test
.workpath(name
))
338 test
.must_not_exist(test
.workpath(name
))
346 # indent-tabs-mode:nil
348 # vim: set expandtab tabstop=4 shiftwidth=4: