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__"
28 Test various uses of the -c (clean) option.
35 _python_ = TestSCons._python_
37 test = TestSCons.TestSCons()
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', """
48 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
49 env = Environment(BUILDERS = { 'B' : B })
50 env.B(target = 'foo1.out', source = 'foo1.in')
51 env.B(target = 'foo2.out', source = 'foo2.xxx')
52 env.B(target = 'foo2.xxx', source = 'foo2.in')
53 env.B(target = 'foo3.out', source = 'foo3.in')
54 env.B(target = 'foo4.out', source = 'foo4.in')
55 env.NoClean('foo4.out')
57 if hasattr(os, 'symlink'):
58 def symlink1(env, target, source):
59 # symlink to a file that exists
60 os.symlink(str(source[0]), str(target[0]))
61 env.Command(target = 'symlink1', source = 'foo1.in', action = symlink1)
62 def symlink2(env, target, source):
63 # force symlink to a file that doesn't exist
64 os.symlink('does_not_exist', str(target[0]))
65 env.Command(target = 'symlink2', source = 'foo1.in', action = symlink2)
66 # Test handling of Builder calls that have multiple targets.
67 env.Command(['touch1.out', 'touch2.out'],
69 [Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}')])
72 test.write('foo1.in', "foo1.in\n")
74 test.write('foo2.in', "foo2.in\n")
76 test.write('foo3.in', "foo3.in\n")
78 test.write('foo4.in', "foo4.in\n")
80 test.run(arguments = 'foo1.out foo2.out foo3.out foo4.out')
82 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
83 test.must_match(test.workpath('foo2.xxx'), "foo2.in\n")
84 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
85 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
86 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
88 test.run(arguments = '-c foo1.out',
89 stdout = test.wrap_stdout("Removed foo1.out\n", cleaning=1))
91 test.must_not_exist(test.workpath('foo1.out'))
92 test.must_exist(test.workpath('foo2.xxx'))
93 test.must_exist(test.workpath('foo2.out'))
94 test.must_exist(test.workpath('foo3.out'))
95 test.must_exist(test.workpath('foo4.out'))
97 test.run(arguments = '--clean foo2.out foo2.xxx',
98 stdout = test.wrap_stdout("Removed foo2.xxx\nRemoved foo2.out\n",
101 test.must_not_exist(test.workpath('foo1.out'))
102 test.must_not_exist(test.workpath('foo2.xxx'))
103 test.must_not_exist(test.workpath('foo2.out'))
104 test.must_exist(test.workpath('foo3.out'))
105 test.must_exist(test.workpath('foo4.out'))
107 test.run(arguments = '--remove foo3.out',
108 stdout = test.wrap_stdout("Removed foo3.out\n", cleaning=1))
110 test.must_not_exist(test.workpath('foo1.out'))
111 test.must_not_exist(test.workpath('foo2.xxx'))
112 test.must_not_exist(test.workpath('foo2.out'))
113 test.must_not_exist(test.workpath('foo3.out'))
114 test.must_exist(test.workpath('foo4.out'))
116 test.run(arguments = '.')
118 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
119 test.must_match(test.workpath('foo2.xxx'), "foo2.in\n")
120 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
121 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
122 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
123 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
124 test.must_exist(test.workpath('touch1.out'))
125 test.must_exist(test.workpath('touch2.out'))
127 if hasattr(os, 'symlink'):
128 test.fail_test(not os.path.islink(test.workpath('symlink1')))
129 test.fail_test(not os.path.islink(test.workpath('symlink2')))
131 test.run(arguments = '-c foo2.xxx',
132 stdout = test.wrap_stdout("Removed foo2.xxx\n", cleaning=1))
134 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
135 test.must_not_exist(test.workpath('foo2.xxx'))
136 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
137 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
138 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
139 test.must_exist(test.workpath('touch1.out'))
140 test.must_exist(test.workpath('touch2.out'))
142 test.run(arguments = '-c .')
144 test.must_not_exist(test.workpath('foo1.out'))
145 test.must_not_exist(test.workpath('foo2.out'))
146 test.must_not_exist(test.workpath('foo3.out'))
147 test.must_exist(test.workpath('foo4.out'))
148 test.must_not_exist(test.workpath('touch1.out'))
149 test.must_not_exist(test.workpath('touch2.out'))
151 if hasattr(os, 'symlink'):
152 test.fail_test(os.path.islink(test.workpath('symlink1')))
153 test.fail_test(os.path.islink(test.workpath('symlink2')))
155 args = 'foo1.out foo2.out foo3.out touch1.out'
157 expect = test.wrap_stdout("""\
166 test.run(arguments = args)
168 test.run(arguments = '-c -n ' + args, stdout = expect)
170 test.run(arguments = '-n -c ' + args, stdout = expect)
172 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
173 test.must_match(test.workpath('foo2.xxx'), "foo2.in\n")
174 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
175 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
176 test.must_match(test.workpath('foo4.out'), "foo4.in\n")
177 test.must_exist(test.workpath('touch1.out'))
178 test.must_exist(test.workpath('touch2.out'))
181 expect1 = "scons: Could not remove 'foo1.out': Permission denied\n"
182 expect2 = "scons: Could not remove 'foo1.out': The process cannot access the file because it is being used by another process\n"
185 test.wrap_stdout(expect1, cleaning=1),
186 test.wrap_stdout(expect2, cleaning=1),
189 test.writable('.', 0)
190 f = open(test.workpath('foo1.out'))
191 test.run(arguments = '-c foo1.out')
192 stdout = test.stdout()
201 test.must_exist(test.workpath('foo1.out'))
203 test.writable('.', 1)
206 test.write(['subd', 'foon.in'], "foon.in\n")
207 test.write(['subd', 'foox.in'], "foox.in\n")
208 test.write('aux1.x', "aux1.x\n")
209 test.write('aux2.x', "aux2.x\n")
210 test.write('SConstruct', """
211 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
212 env = Environment(BUILDERS = { 'B' : B }, FOO = 'foo2')
213 env.B(target = 'foo1.out', source = 'foo1.in')
214 env.B(target = 'foo2.out', source = 'foo2.xxx')
215 foo2_xxx = env.B(target = 'foo2.xxx', source = 'foo2.in')
216 env.B(target = 'foo3.out', source = 'foo3.in')
217 SConscript('subd/SConscript')
218 Clean(foo2_xxx, ['aux1.x'])
219 env.Clean(['${FOO}.xxx'], ['aux2.x'])
223 test.write(['subd', 'SConscript'], """
224 Clean('.', 'foox.in')
227 expect = test.wrap_stdout("""Removed foo2.xxx
231 test.run(arguments = '-c foo2.xxx', stdout=expect)
232 test.must_match(test.workpath('foo1.out'), "foo1.in\n")
233 test.must_not_exist(test.workpath('foo2.xxx'))
234 test.must_match(test.workpath('foo2.out'), "foo2.in\n")
235 test.must_match(test.workpath('foo3.out'), "foo3.in\n")
237 expect = test.wrap_stdout("Removed %s\n" % os.path.join('subd', 'foox.in'),
239 test.run(arguments = '-c subd', stdout=expect)
240 test.must_not_exist(test.workpath('foox.in'))
242 expect = test.wrap_stdout("""Removed foo1.out
248 Removed directory subd
249 """ % (os.path.join('subd','SConscript'), os.path.join('subd', 'foon.in')),
251 test.run(arguments = '-c -n .', stdout=expect)
253 expect = test.wrap_stdout("""Removed foo1.out
258 Removed directory subd
259 """ % (os.path.join('subd','SConscript'), os.path.join('subd', 'foon.in')),
261 test.run(arguments = '-c .', stdout=expect)
262 test.must_not_exist(test.workpath('subdir', 'foon.in'))
263 test.must_not_exist(test.workpath('subdir'))
266 # Ensure that Set/GetOption('clean') works correctly:
267 test.write('SConstruct', """
268 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
269 env = Environment(BUILDERS = { 'B' : B })
270 env.B(target = 'foo.out', source = 'foo.in')
272 assert not GetOption('clean')
275 test.write('foo.in', '"Foo", I say!\n')
277 test.run(arguments='foo.out')
278 test.must_match(test.workpath('foo.out'), '"Foo", I say!\n')
280 test.write('SConstruct', """
281 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
282 env = Environment(BUILDERS = { 'B' : B })
283 env.B(target = 'foo.out', source = 'foo.in')
285 assert GetOption('clean')
286 SetOption('clean', 0)
287 assert GetOption('clean')
290 test.run(arguments='-c foo.out')
291 test.must_not_exist(test.workpath('foo.out'))
293 test.write('SConstruct', """
294 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
295 env = Environment(BUILDERS = { 'B' : B })
296 env.B(target = 'foo.out', source = 'foo.in')
299 test.run(arguments='foo.out')
300 test.must_match(test.workpath('foo.out'), '"Foo", I say!\n')
302 test.write('SConstruct', """
303 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
304 env = Environment(BUILDERS = { 'B' : B })
305 env.B(target = 'foo.out', source = 'foo.in')
307 assert not GetOption('clean')
308 SetOption('clean', 1)
309 assert GetOption('clean')
312 test.run(arguments='foo.out')
313 test.must_not_exist(test.workpath('foo.out'))