OLD | NEW |
1 """SCons.Script | 1 """SCons.Script |
2 | 2 |
3 This file implements the main() function used by the scons script. | 3 This file implements the main() function used by the scons script. |
4 | 4 |
5 Architecturally, this *is* the scons script, and will likely only be | 5 Architecturally, this *is* the scons script, and will likely only be |
6 called from the external "scons" wrapper. Consequently, anything here | 6 called from the external "scons" wrapper. Consequently, anything here |
7 should not be, or be considered, part of the build engine. If it's | 7 should not be, or be considered, part of the build engine. If it's |
8 something that we expect other software to want to use, it should go in | 8 something that we expect other software to want to use, it should go in |
9 some other module. If it's specific to the "scons" script invocation, | 9 some other module. If it's specific to the "scons" script invocation, |
10 it goes here. | 10 it goes here. |
11 | 11 |
12 """ | 12 """ |
13 | 13 |
14 # | 14 # |
15 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion | 15 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The SCons F
oundation |
16 # | 16 # |
17 # Permission is hereby granted, free of charge, to any person obtaining | 17 # Permission is hereby granted, free of charge, to any person obtaining |
18 # a copy of this software and associated documentation files (the | 18 # a copy of this software and associated documentation files (the |
19 # "Software"), to deal in the Software without restriction, including | 19 # "Software"), to deal in the Software without restriction, including |
20 # without limitation the rights to use, copy, modify, merge, publish, | 20 # without limitation the rights to use, copy, modify, merge, publish, |
21 # distribute, sublicense, and/or sell copies of the Software, and to | 21 # distribute, sublicense, and/or sell copies of the Software, and to |
22 # permit persons to whom the Software is furnished to do so, subject to | 22 # permit persons to whom the Software is furnished to do so, subject to |
23 # the following conditions: | 23 # the following conditions: |
24 # | 24 # |
25 # The above copyright notice and this permission notice shall be included | 25 # The above copyright notice and this permission notice shall be included |
26 # in all copies or substantial portions of the Software. | 26 # in all copies or substantial portions of the Software. |
27 # | 27 # |
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | 28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
29 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | 29 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
30 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 30 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | 31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
32 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | 32 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
33 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 33 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
34 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 34 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35 # | 35 # |
36 | 36 |
37 __revision__ = "src/engine/SCons/Script/Main.py 3842 2008/12/20 22:59:52 scons" | 37 __revision__ = "src/engine/SCons/Script/Main.py 3897 2009/01/13 06:45:54 scons" |
38 | 38 |
39 import os | 39 import os |
40 import os.path | 40 import os.path |
41 import string | 41 import string |
42 import sys | 42 import sys |
43 import time | 43 import time |
44 import traceback | 44 import traceback |
45 | 45 |
46 # Strip the script directory from sys.path() so on case-insensitive | 46 # Strip the script directory from sys.path() so on case-insensitive |
47 # (Windows) systems Python doesn't think that the "scons" script is the | 47 # (Windows) systems Python doesn't think that the "scons" script is the |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 ProgressObject = apply(Progressor, args, kw) | 148 ProgressObject = apply(Progressor, args, kw) |
149 | 149 |
150 # Task control. | 150 # Task control. |
151 # | 151 # |
152 | 152 |
153 _BuildFailures = [] | 153 _BuildFailures = [] |
154 | 154 |
155 def GetBuildFailures(): | 155 def GetBuildFailures(): |
156 return _BuildFailures | 156 return _BuildFailures |
157 | 157 |
158 class BuildTask(SCons.Taskmaster.Task): | 158 class BuildTask(SCons.Taskmaster.OutOfDateTask): |
159 """An SCons build task.""" | 159 """An SCons build task.""" |
160 progress = ProgressObject | 160 progress = ProgressObject |
161 | 161 |
162 def display(self, message): | 162 def display(self, message): |
163 display('scons: ' + message) | 163 display('scons: ' + message) |
164 | 164 |
165 def prepare(self): | 165 def prepare(self): |
166 self.progress(self.targets[0]) | 166 self.progress(self.targets[0]) |
167 return SCons.Taskmaster.Task.prepare(self) | 167 return SCons.Taskmaster.OutOfDateTask.prepare(self) |
168 | 168 |
169 def needs_execute(self): | 169 def needs_execute(self): |
170 target = self.targets[0] | 170 if SCons.Taskmaster.OutOfDateTask.needs_execute(self): |
171 if target.get_state() == SCons.Node.executing: | |
172 return True | 171 return True |
173 else: | 172 if self.top and self.targets[0].has_builder(): |
174 if self.top and target.has_builder(): | 173 display("scons: `%s' is up to date." % str(self.node)) |
175 display("scons: `%s' is up to date." % str(self.node)) | 174 return False |
176 return False | |
177 | 175 |
178 def execute(self): | 176 def execute(self): |
179 if print_time: | 177 if print_time: |
180 start_time = time.time() | 178 start_time = time.time() |
181 global first_command_start | 179 global first_command_start |
182 if first_command_start is None: | 180 if first_command_start is None: |
183 first_command_start = start_time | 181 first_command_start = start_time |
184 SCons.Taskmaster.Task.execute(self) | 182 SCons.Taskmaster.OutOfDateTask.execute(self) |
185 if print_time: | 183 if print_time: |
186 global cumulative_command_time | 184 global cumulative_command_time |
187 global last_command_end | 185 global last_command_end |
188 finish_time = time.time() | 186 finish_time = time.time() |
189 last_command_end = finish_time | 187 last_command_end = finish_time |
190 cumulative_command_time = cumulative_command_time+finish_time-start_
time | 188 cumulative_command_time = cumulative_command_time+finish_time-start_
time |
191 sys.stdout.write("Command execution time: %f seconds\n"%(finish_time
-start_time)) | 189 sys.stdout.write("Command execution time: %f seconds\n"%(finish_time
-start_time)) |
192 | 190 |
193 def do_failed(self, status=2): | 191 def do_failed(self, status=2): |
194 _BuildFailures.append(self.exception[1]) | 192 _BuildFailures.append(self.exception[1]) |
195 global exit_status | 193 global exit_status |
196 global this_build_status | 194 global this_build_status |
197 if self.options.ignore_errors: | 195 if self.options.ignore_errors: |
198 SCons.Taskmaster.Task.executed(self) | 196 SCons.Taskmaster.OutOfDateTask.executed(self) |
199 elif self.options.keep_going: | 197 elif self.options.keep_going: |
200 SCons.Taskmaster.Task.fail_continue(self) | 198 SCons.Taskmaster.OutOfDateTask.fail_continue(self) |
201 exit_status = status | 199 exit_status = status |
202 this_build_status = status | 200 this_build_status = status |
203 else: | 201 else: |
204 SCons.Taskmaster.Task.fail_stop(self) | 202 SCons.Taskmaster.OutOfDateTask.fail_stop(self) |
205 exit_status = status | 203 exit_status = status |
206 this_build_status = status | 204 this_build_status = status |
207 | 205 |
208 def executed(self): | 206 def executed(self): |
209 t = self.targets[0] | 207 t = self.targets[0] |
210 if self.top and not t.has_builder() and not t.side_effect: | 208 if self.top and not t.has_builder() and not t.side_effect: |
211 if not t.exists(): | 209 if not t.exists(): |
212 errstr="Do not know how to make target `%s'." % t | 210 errstr="Do not know how to make target `%s'." % t |
213 sys.stderr.write("scons: *** " + errstr) | 211 sys.stderr.write("scons: *** " + errstr) |
214 if not self.options.keep_going: | 212 if not self.options.keep_going: |
215 sys.stderr.write(" Stop.") | 213 sys.stderr.write(" Stop.") |
216 sys.stderr.write("\n") | 214 sys.stderr.write("\n") |
217 try: | 215 try: |
218 raise SCons.Errors.BuildError(t, errstr) | 216 raise SCons.Errors.BuildError(t, errstr) |
219 except KeyboardInterrupt: | 217 except KeyboardInterrupt: |
220 raise | 218 raise |
221 except: | 219 except: |
222 self.exception_set() | 220 self.exception_set() |
223 self.do_failed() | 221 self.do_failed() |
224 else: | 222 else: |
225 print "scons: Nothing to be done for `%s'." % t | 223 print "scons: Nothing to be done for `%s'." % t |
226 SCons.Taskmaster.Task.executed(self) | 224 SCons.Taskmaster.OutOfDateTask.executed(self) |
227 else: | 225 else: |
228 SCons.Taskmaster.Task.executed(self) | 226 SCons.Taskmaster.OutOfDateTask.executed(self) |
229 | 227 |
230 def failed(self): | 228 def failed(self): |
231 # Handle the failure of a build task. The primary purpose here | 229 # Handle the failure of a build task. The primary purpose here |
232 # is to display the various types of Errors and Exceptions | 230 # is to display the various types of Errors and Exceptions |
233 # appropriately. | 231 # appropriately. |
234 exc_info = self.exc_info() | 232 exc_info = self.exc_info() |
235 try: | 233 try: |
236 t, e, tb = exc_info | 234 t, e, tb = exc_info |
237 except ValueError: | 235 except ValueError: |
238 t, e = exc_info | 236 t, e = exc_info |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 def postprocess(self): | 284 def postprocess(self): |
287 if self.top: | 285 if self.top: |
288 t = self.targets[0] | 286 t = self.targets[0] |
289 for tp in self.options.tree_printers: | 287 for tp in self.options.tree_printers: |
290 tp.display(t) | 288 tp.display(t) |
291 if self.options.debug_includes: | 289 if self.options.debug_includes: |
292 tree = t.render_include_tree() | 290 tree = t.render_include_tree() |
293 if tree: | 291 if tree: |
294 print | 292 print |
295 print tree | 293 print tree |
296 SCons.Taskmaster.Task.postprocess(self) | 294 SCons.Taskmaster.OutOfDateTask.postprocess(self) |
297 | 295 |
298 def make_ready(self): | 296 def make_ready(self): |
299 """Make a task ready for execution""" | 297 """Make a task ready for execution""" |
300 SCons.Taskmaster.Task.make_ready(self) | 298 SCons.Taskmaster.OutOfDateTask.make_ready(self) |
301 if self.out_of_date and self.options.debug_explain: | 299 if self.out_of_date and self.options.debug_explain: |
302 explanation = self.out_of_date[0].explain() | 300 explanation = self.out_of_date[0].explain() |
303 if explanation: | 301 if explanation: |
304 sys.stdout.write("scons: " + explanation) | 302 sys.stdout.write("scons: " + explanation) |
305 | 303 |
306 class CleanTask(SCons.Taskmaster.Task): | 304 class CleanTask(SCons.Taskmaster.AlwaysTask): |
307 """An SCons clean task.""" | 305 """An SCons clean task.""" |
308 def fs_delete(self, path, pathstr, remove=1): | 306 def fs_delete(self, path, pathstr, remove=1): |
309 try: | 307 try: |
310 if os.path.exists(path): | 308 if os.path.exists(path): |
311 if os.path.isfile(path): | 309 if os.path.isfile(path): |
312 if remove: os.unlink(path) | 310 if remove: os.unlink(path) |
313 display("Removed " + pathstr) | 311 display("Removed " + pathstr) |
314 elif os.path.isdir(path) and not os.path.islink(path): | 312 elif os.path.isdir(path) and not os.path.islink(path): |
315 # delete everything in the dir | 313 # delete everything in the dir |
316 entries = os.listdir(path) | 314 entries = os.listdir(path) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 executed = SCons.Taskmaster.Task.executed_without_callbacks | 370 executed = SCons.Taskmaster.Task.executed_without_callbacks |
373 | 371 |
374 # Have the taskmaster arrange to "execute" all of the targets, because | 372 # Have the taskmaster arrange to "execute" all of the targets, because |
375 # we'll figure out ourselves (in remove() or show() above) whether | 373 # we'll figure out ourselves (in remove() or show() above) whether |
376 # anything really needs to be done. | 374 # anything really needs to be done. |
377 make_ready = SCons.Taskmaster.Task.make_ready_all | 375 make_ready = SCons.Taskmaster.Task.make_ready_all |
378 | 376 |
379 def prepare(self): | 377 def prepare(self): |
380 pass | 378 pass |
381 | 379 |
382 class QuestionTask(SCons.Taskmaster.Task): | 380 class QuestionTask(SCons.Taskmaster.AlwaysTask): |
383 """An SCons task for the -q (question) option.""" | 381 """An SCons task for the -q (question) option.""" |
384 def prepare(self): | 382 def prepare(self): |
385 pass | 383 pass |
386 | 384 |
387 def execute(self): | 385 def execute(self): |
388 if self.targets[0].get_state() != SCons.Node.up_to_date or \ | 386 if self.targets[0].get_state() != SCons.Node.up_to_date or \ |
389 (self.top and not self.targets[0].exists()): | 387 (self.top and not self.targets[0].exists()): |
390 global exit_status | 388 global exit_status |
391 global this_build_status | 389 global this_build_status |
392 exit_status = 1 | 390 exit_status = 1 |
393 this_build_status = 1 | 391 this_build_status = 1 |
394 self.tm.stop() | 392 self.tm.stop() |
395 | 393 |
396 def executed(self): | 394 def executed(self): |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 memory_stats.append('before building targets:') | 1157 memory_stats.append('before building targets:') |
1160 count_stats.append(('pre-', 'build')) | 1158 count_stats.append(('pre-', 'build')) |
1161 | 1159 |
1162 def jobs_postfunc( | 1160 def jobs_postfunc( |
1163 jobs=jobs, | 1161 jobs=jobs, |
1164 options=options, | 1162 options=options, |
1165 closing_message=closing_message, | 1163 closing_message=closing_message, |
1166 failure_message=failure_message | 1164 failure_message=failure_message |
1167 ): | 1165 ): |
1168 if jobs.were_interrupted(): | 1166 if jobs.were_interrupted(): |
1169 progress_display("scons: Build interrupted.") | 1167 if not options.no_progress and not options.silent: |
| 1168 sys.stderr.write("scons: Build interrupted.\n") |
1170 global exit_status | 1169 global exit_status |
1171 global this_build_status | 1170 global this_build_status |
1172 exit_status = 2 | 1171 exit_status = 2 |
1173 this_build_status = 2 | 1172 this_build_status = 2 |
1174 | 1173 |
1175 if this_build_status: | 1174 if this_build_status: |
1176 progress_display("scons: " + failure_message) | 1175 progress_display("scons: " + failure_message) |
1177 else: | 1176 else: |
1178 progress_display("scons: " + closing_message) | 1177 progress_display("scons: " + closing_message) |
1179 if not options.no_exec: | 1178 if not options.no_exec: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 | 1243 |
1245 parts = ["SCons by Steven Knight et al.:\n"] | 1244 parts = ["SCons by Steven Knight et al.:\n"] |
1246 try: | 1245 try: |
1247 import __main__ | 1246 import __main__ |
1248 parts.append(version_string("script", __main__)) | 1247 parts.append(version_string("script", __main__)) |
1249 except (ImportError, AttributeError): | 1248 except (ImportError, AttributeError): |
1250 # On Windows there is no scons.py, so there is no | 1249 # On Windows there is no scons.py, so there is no |
1251 # __main__.__version__, hence there is no script version. | 1250 # __main__.__version__, hence there is no script version. |
1252 pass | 1251 pass |
1253 parts.append(version_string("engine", SCons)) | 1252 parts.append(version_string("engine", SCons)) |
1254 parts.append("Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 T
he SCons Foundation") | 1253 parts.append("Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
2009 The SCons Foundation") |
1255 version = string.join(parts, '') | 1254 version = string.join(parts, '') |
1256 | 1255 |
1257 import SConsOptions | 1256 import SConsOptions |
1258 parser = SConsOptions.Parser(version) | 1257 parser = SConsOptions.Parser(version) |
1259 values = SConsOptions.SConsValues(parser.get_default_values()) | 1258 values = SConsOptions.SConsValues(parser.get_default_values()) |
1260 | 1259 |
1261 OptionsParser = parser | 1260 OptionsParser = parser |
1262 | 1261 |
1263 try: | 1262 try: |
1264 _exec_main(parser, values) | 1263 _exec_main(parser, values) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 ct = 0.0 | 1311 ct = 0.0 |
1313 else: | 1312 else: |
1314 ct = last_command_end - first_command_start | 1313 ct = last_command_end - first_command_start |
1315 scons_time = total_time - sconscript_time - ct | 1314 scons_time = total_time - sconscript_time - ct |
1316 print "Total build time: %f seconds"%total_time | 1315 print "Total build time: %f seconds"%total_time |
1317 print "Total SConscript file execution time: %f seconds"%sconscript_time | 1316 print "Total SConscript file execution time: %f seconds"%sconscript_time |
1318 print "Total SCons execution time: %f seconds"%scons_time | 1317 print "Total SCons execution time: %f seconds"%scons_time |
1319 print "Total command execution time: %f seconds"%ct | 1318 print "Total command execution time: %f seconds"%ct |
1320 | 1319 |
1321 sys.exit(exit_status) | 1320 sys.exit(exit_status) |
OLD | NEW |