3 # Copyright (c) 2001, 2002, 2003 Steven Knight
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__"
33 test = TestSCons.TestSCons()
35 python = TestSCons.python
37 test.subdir('sub1', 'sub2', 'sub3')
39 test.write('build.py', r"""
41 contents = open(sys.argv[2], 'rb').read()
42 file = open(sys.argv[1], 'wb')
47 test.write('SConstruct', r"""
50 env['BUILDERS']['B'] = Builder(action=r'%s build.py $TARGET $SOURCES', multi=1)
51 Default(env.B(target = 'sub1/foo.out', source = 'sub1/foo.in'))
53 SConscript('sub2/SConscript')
54 Default(env.B(target = 'sub3/baz.out', source = 'sub3/baz.in'))
55 BuildDir('sub2b', 'sub2')
56 SConscript('sub2b/SConscript')
57 Default(env.B(target = 'sub2/xxx.out', source = 'xxx.in'))
58 SConscript('SConscript')
61 test.write(['sub2', 'SConscript'], """
63 bar = env.B(target = 'bar.out', source = 'bar.in')
66 Default(env.B(target = '../bar.out', source = 'bar.in'))
70 test.write(['sub1', 'foo.in'], "sub1/foo.in\n")
71 test.write(['sub2', 'bar.in'], "sub2/bar.in\n")
72 test.write(['sub3', 'baz.in'], "sub3/baz.in\n")
73 test.write('xxx.in', "xxx.in\n")
75 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub1'))
76 test.run(arguments = '-U foo.out', chdir = 'sub1')
78 test.fail_test(not os.path.exists(test.workpath('sub1', 'foo.out')))
79 test.fail_test(os.path.exists(test.workpath('sub2', 'bar.out')))
80 test.fail_test(os.path.exists(test.workpath('sub2b', 'bar.out')))
81 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
82 test.fail_test(os.path.exists(test.workpath('bar.out')))
83 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
85 test.unlink(['sub1', 'foo.out'])
87 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub1'))
88 test.run(arguments = '-U', chdir = 'sub1', stderr = None, status = 2)
89 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
90 test.fail_test(os.path.exists(test.workpath('sub2', 'bar.out')))
91 test.fail_test(os.path.exists(test.workpath('sub2b', 'bar.out')))
92 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
93 test.fail_test(os.path.exists(test.workpath('bar.out')))
94 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
97 if sys.platform == 'win32':
98 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('SUB2'))
99 test.run(chdir = 'SUB2', arguments = '-U')
101 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub2'))
102 test.run(chdir = 'sub2', arguments = '-U')
103 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
104 test.fail_test(not os.path.exists(test.workpath('sub2', 'bar.out')))
105 test.fail_test(not os.path.exists(test.workpath('sub2b', 'bar.out')))
106 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
107 test.fail_test(not os.path.exists(test.workpath('bar.out')))
108 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
110 test.unlink(['sub2', 'bar.out'])
111 test.unlink(['sub2b', 'bar.out'])
112 test.unlink('bar.out')
114 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath())
115 test.run(arguments='-U')
116 test.fail_test(not os.path.exists(test.workpath('sub1', 'foo.out')))
117 test.fail_test(os.path.exists(test.workpath('sub2', 'bar.out')))
118 test.fail_test(os.path.exists(test.workpath('sub2b', 'bar.out')))
119 test.fail_test(not os.path.exists(test.workpath('sub3', 'baz.out')))
120 test.fail_test(os.path.exists(test.workpath('bar.out')))
121 test.fail_test(not os.path.exists(test.workpath('sub2/xxx.out')))
123 test.unlink(['sub1', 'foo.out'])
124 test.unlink(['sub3', 'baz.out'])
125 test.unlink(['sub2', 'xxx.out'])
127 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub3'))
128 test.run(chdir = 'sub3', arguments='-U bar')
129 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
130 test.fail_test(not os.path.exists(test.workpath('sub2', 'bar.out')))
131 test.fail_test(not os.path.exists(test.workpath('sub2b', 'bar.out')))
132 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
133 test.fail_test(os.path.exists(test.workpath('bar.out')))
134 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
137 # Make sure that a Default() directory doesn't cause an exception.
140 test.write(['sub4', 'SConstruct'], """
144 test.run(chdir = 'sub4', arguments = '-U')
146 test.write('SConstruct', """
147 Default('not_a_target.in')
150 test.run(arguments = '-U', status=2, stderr="""\
151 scons: *** Do not know how to make target `not_a_target.in'. Stop.