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 Test various basic uses of the -c (clean) option.
34 _python_
= TestSCons
._python
_
36 test
= TestSCons
.TestSCons()
38 test
.write('build.py', r
"""
40 with open(sys.argv[1], 'wb') as ofp, open(sys.argv[2], 'rb') as ifp:
44 test
.write('SConstruct', """
45 DefaultEnvironment(tools=[])
46 B = Builder(action = r'%(_python_)s build.py $TARGETS $SOURCES')
47 env = Environment(tools=[], BUILDERS = { 'B' : B })
48 env.B(target = 'foo1.out', source = 'foo1.in')
49 env.B(target = 'foo2.out', source = 'foo2.xxx')
50 env.B(target = 'foo2.xxx', source = 'foo2.in')
51 env.B(target = 'foo3.out', source = 'foo3.in')
52 env.B(target = 'foo4.out', source = 'foo4.in')
53 env.NoClean('foo4.out')
56 if hasattr(os, 'symlink') and sys.platform !='win32':
57 def symlink1(env, target, source):
58 # symlink to a file that exists
59 os.symlink(str(source[0]), str(target[0]))
60 env.Command(target = 'symlink1', source = 'foo1.in', action = symlink1)
61 def symlink2(env, target, source):
62 # force symlink to a file that doesn't exist
63 os.symlink('does_not_exist', str(target[0]))
64 env.Command(target = 'symlink2', source = 'foo1.in', action = symlink2)
65 # Test handling of Builder calls that have multiple targets.
66 env.Command(['touch1.out', 'touch2.out'],
68 [Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}')])
71 test
.write('foo1.in', "foo1.in\n")
73 test
.write('foo2.in', "foo2.in\n")
75 test
.write('foo3.in', "foo3.in\n")
77 test
.write('foo4.in', "foo4.in\n")
79 test
.run(arguments
= 'foo1.out foo2.out foo3.out foo4.out')
81 test
.must_match(test
.workpath('foo1.out'), "foo1.in\n")
82 test
.must_match(test
.workpath('foo2.xxx'), "foo2.in\n")
83 test
.must_match(test
.workpath('foo2.out'), "foo2.in\n")
84 test
.must_match(test
.workpath('foo3.out'), "foo3.in\n")
85 test
.must_match(test
.workpath('foo4.out'), "foo4.in\n")
87 test
.run(arguments
= '-c foo1.out',
88 stdout
= test
.wrap_stdout("Removed foo1.out\n", cleaning
=1))
90 test
.must_not_exist(test
.workpath('foo1.out'))
91 test
.must_exist(test
.workpath('foo2.xxx'))
92 test
.must_exist(test
.workpath('foo2.out'))
93 test
.must_exist(test
.workpath('foo3.out'))
94 test
.must_exist(test
.workpath('foo4.out'))
96 test
.run(arguments
= '--clean foo2.out foo2.xxx',
97 stdout
= test
.wrap_stdout("Removed foo2.xxx\nRemoved foo2.out\n",
100 test
.must_not_exist(test
.workpath('foo1.out'))
101 test
.must_not_exist(test
.workpath('foo2.xxx'))
102 test
.must_not_exist(test
.workpath('foo2.out'))
103 test
.must_exist(test
.workpath('foo3.out'))
104 test
.must_exist(test
.workpath('foo4.out'))
106 test
.run(arguments
= '--remove foo3.out',
107 stdout
= test
.wrap_stdout("Removed foo3.out\n", cleaning
=1))
109 test
.must_not_exist(test
.workpath('foo1.out'))
110 test
.must_not_exist(test
.workpath('foo2.xxx'))
111 test
.must_not_exist(test
.workpath('foo2.out'))
112 test
.must_not_exist(test
.workpath('foo3.out'))
113 test
.must_exist(test
.workpath('foo4.out'))
115 test
.run(arguments
= '.')
117 test
.must_match(test
.workpath('foo1.out'), "foo1.in\n")
118 test
.must_match(test
.workpath('foo2.xxx'), "foo2.in\n")
119 test
.must_match(test
.workpath('foo2.out'), "foo2.in\n")
120 test
.must_match(test
.workpath('foo3.out'), "foo3.in\n")
121 test
.must_match(test
.workpath('foo3.out'), "foo3.in\n")
122 test
.must_match(test
.workpath('foo4.out'), "foo4.in\n")
123 test
.must_exist(test
.workpath('touch1.out'))
124 test
.must_exist(test
.workpath('touch2.out'))
126 if test
.platform_has_symlink():
127 test
.fail_test(not os
.path
.islink(test
.workpath('symlink1')))
128 test
.fail_test(not os
.path
.islink(test
.workpath('symlink2')))
130 test
.run(arguments
= '-c foo2.xxx',
131 stdout
= test
.wrap_stdout("Removed foo2.xxx\n", cleaning
=1))
133 test
.must_match(test
.workpath('foo1.out'), "foo1.in\n")
134 test
.must_not_exist(test
.workpath('foo2.xxx'))
135 test
.must_match(test
.workpath('foo2.out'), "foo2.in\n")
136 test
.must_match(test
.workpath('foo3.out'), "foo3.in\n")
137 test
.must_match(test
.workpath('foo4.out'), "foo4.in\n")
138 test
.must_exist(test
.workpath('touch1.out'))
139 test
.must_exist(test
.workpath('touch2.out'))
141 test
.run(arguments
= '-c .')
143 test
.must_not_exist(test
.workpath('foo1.out'))
144 test
.must_not_exist(test
.workpath('foo2.out'))
145 test
.must_not_exist(test
.workpath('foo3.out'))
146 test
.must_exist(test
.workpath('foo4.out'))
147 test
.must_not_exist(test
.workpath('touch1.out'))
148 test
.must_not_exist(test
.workpath('touch2.out'))
150 if test
.platform_has_symlink():
151 test
.fail_test(os
.path
.islink(test
.workpath('symlink1')))
152 test
.fail_test(os
.path
.islink(test
.workpath('symlink2')))
154 args
= 'foo1.out foo2.out foo3.out touch1.out'
156 expect
= test
.wrap_stdout("""\
165 test
.run(arguments
= args
)
167 test
.run(arguments
= '-c -n ' + args
, stdout
= expect
)
169 test
.run(arguments
= '-n -c ' + args
, stdout
= expect
)
171 test
.must_match(test
.workpath('foo1.out'), "foo1.in\n")
172 test
.must_match(test
.workpath('foo2.xxx'), "foo2.in\n")
173 test
.must_match(test
.workpath('foo2.out'), "foo2.in\n")
174 test
.must_match(test
.workpath('foo3.out'), "foo3.in\n")
175 test
.must_match(test
.workpath('foo4.out'), "foo4.in\n")
176 test
.must_exist(test
.workpath('touch1.out'))
177 test
.must_exist(test
.workpath('touch2.out'))
183 # indent-tabs-mode:nil
185 # vim: set expandtab tabstop=4 shiftwidth=4: