break
try:
+ task.prepare()
task.execute()
except KeyboardInterrupt:
raise
if task == None:
break
- cv.release()
try:
+ task.prepare()
+ cv.release()
try:
task.execute()
finally:
self.i = i
self.taskmaster = taskmaster
self.was_executed = 0
+ self.was_prepared = 0
+
+ def prepare(self):
+ self.was_prepared = 1
def execute(self):
+ self.taskmaster.test_case.failUnless(self.was_prepared,
+ "the task wasn't prepared")
+
self.taskmaster.guard.acquire()
self.taskmaster.begin_list.append(self.i)
self.taskmaster.guard.release()
def executed(self):
self.taskmaster.num_executed = self.taskmaster.num_executed + 1
+ self.taskmaster.test_case.failUnless(self.was_prepared,
+ "the task wasn't prepared")
self.taskmaster.test_case.failUnless(self.was_executed,
"the task wasn't really executed")
self.taskmaster.test_case.failUnless(self.__class__ is Task,
def failed(self):
self.taskmaster.num_failed = self.taskmaster.num_failed + 1
self.taskmaster.stop = 1
+ self.taskmaster.test_case.failUnless(self.was_prepared,
+ "the task wasn't prepared")
+
class ExceptionTask:
"""A dummy task class for testing purposes."""
def __init__(self, i, taskmaster):
self.taskmaster = taskmaster
+ self.was_prepared = 0
+
+ def prepare(self):
+ self.was_prepared = 1
def execute(self):
raise "exception"
def executed(self):
self.taskmaster.num_executed = self.taskmaster.num_executed + 1
+ self.taskmaster.test_case.failUnless(self.was_prepared,
+ "the task wasn't prepared")
self.taskmaster.test_case.failUnless(self.was_executed,
"the task wasn't really executed")
self.taskmaster.test_case.failUnless(self.__class__ is Task,
def failed(self):
self.taskmaster.num_failed = self.taskmaster.num_failed + 1
self.taskmaster.stop = 1
+ self.taskmaster.test_case.failUnless(self.was_prepared,
+ "the task wasn't prepared")
class Taskmaster:
"""A dummy taskmaster class for testing the job classes."""
def all_tasks_are_iterated(self):
return self.num_iterated == self.num_tasks
-
+
def is_blocked(self):
# simulate blocking tasks
return self.num_iterated - self.num_executed >= max(num_jobs/2, 2)
if self.top:
display('scons: "%s" is up to date.' % str(self.targets[0]))
else:
- try:
- self.targets[0].prepare()
- if print_time:
- start_time = time.time()
- self.targets[0].build()
- if print_time:
- finish_time = time.time()
- global command_time
- command_time = command_time+finish_time-start_time
- print "Command execution time: %f seconds"%(finish_time-start_time)
-
- except BuildError, e:
- sys.stderr.write("scons: *** [%s] %s\n" % (e.node, e.errstr))
- if e.errstr == 'Exception':
- traceback.print_exception(e.args[0], e.args[1],
- e.args[2])
- raise
- except UserError, e:
- # We aren't being called out of a user frame, so
- # don't try to walk the stack, just print the error.
- sys.stderr.write("\nSCons error: %s\n" % e)
- raise
- except StopError, e:
- s = str(e)
- if not keep_going_on_error:
- s = s + ' Stop.'
- sys.stderr.write("scons: *** %s\n" % s)
- raise
- except:
- sys.stderr.write("scons: *** %s\n" % sys.exc_value)
- raise
+ if print_time:
+ start_time = time.time()
+ self.targets[0].build()
+ if print_time:
+ finish_time = time.time()
+ global command_time
+ command_time = command_time+finish_time-start_time
+ print "Command execution time: %f seconds"%(finish_time-start_time)
def executed(self):
SCons.Taskmaster.Task.executed(self)
def failed(self):
global exit_status
+
+ e = sys.exc_value
+ if sys.exc_type == BuildError:
+ sys.stderr.write("scons: *** [%s] %s\n" % (e.node, e.errstr))
+ if e.errstr == 'Exception':
+ traceback.print_exception(e.args[0], e.args[1],
+ e.args[2])
+ elif sys.exc_type == UserError:
+ # We aren't being called out of a user frame, so
+ # don't try to walk the stack, just print the error.
+ sys.stderr.write("\nSCons error: %s\n" % e)
+ elif sys.exc_type == StopError:
+ s = str(e)
+ if not keep_going_on_error:
+ s = s + ' Stop.'
+ sys.stderr.write("scons: *** %s\n" % s)
+ else:
+ sys.stderr.write("scons: *** %s\n" % e)
+
if ignore_errors:
SCons.Taskmaster.Task.executed(self)
elif keep_going_on_error:
execute = remove
+ def prepare(self):
+ pass
+
class QuestionTask(SCons.Taskmaster.Task):
"""An SCons task for the -q (question) option."""
+ def prepare(self):
+ pass
+
def execute(self):
if self.targets[0].get_state() != SCons.Node.up_to_date:
global exit_status
self.top = top
self.node = node
- def execute(self):
- # This methods is called from multiple threads in
- # a parallel build, so only do thread safe stuff here.
- # Do thread unsafe stuff in executed() or failed().
+
+ def prepare(self):
+ """Called just before the task is executed."""
if self.targets[0].get_state() != SCons.Node.up_to_date:
self.targets[0].prepare()
+
+ def execute(self):
+ """Called to execute the task.
+
+ This methods is called from multiple threads in
+ a parallel build, so only do thread safe stuff here.
+ Do thread unsafe stuff in prepare(), executed() or failed()."""
+ if self.targets[0].get_state() != SCons.Node.up_to_date:
self.targets[0].build()
def get_target(self):
n1 = Node("n1")
tm = SCons.Taskmaster.Taskmaster([n1, n1])
t = tm.next_task()
+ t.prepare()
t.execute()
t = tm.next_task()
assert t == None
tm = SCons.Taskmaster.Taskmaster([n3])
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n1 built", built_text
t.executed()
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n2 built", built_text
t.executed()
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n3 built", built_text
t.executed()
tasker = MyTask, calc = MyCalc())
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n1 up-to-date", built_text
t.executed()
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n2 up-to-date", built_text
t.executed()
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n3 up-to-date top", built_text
t.executed()
tm = SCons.Taskmaster.Taskmaster([n3])
t = tm.next_task()
+ t.prepare()
t.execute()
assert built_text == "n1 built", built_text
t.executed()