Encapsulate task skipping in a method to help with the shrinking sets feature

This commit is contained in:
Thomas Nagy 2014-01-02 20:21:45 +01:00
parent 44720924b6
commit 5fc835639e
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
2 changed files with 16 additions and 89 deletions

View File

@ -279,6 +279,9 @@ class Parallel(object):
put_pool(x)
self.pool = []
def skip(self, tsk):
tsk.hasrun = Task.SKIPPED
def start(self):
"""
Give tasks to :py:class:`waflib.Runner.TaskConsumer` instances until the build finishes or the ``stop`` flag is set.
@ -316,7 +319,7 @@ class Parallel(object):
# TODO waf 1.7 this piece of code should go in the error_handler
tsk.err_msg = Utils.ex_stack()
if not self.stop and self.bld.keep:
tsk.hasrun = Task.SKIPPED
self.skip(tsk)
if self.bld.keep == 1:
# if -k stop at the first exception, if -kk try to go as far as possible
if Logs.verbose > 1 or not self.error:
@ -334,7 +337,7 @@ class Parallel(object):
self.postpone(tsk)
elif st == Task.SKIP_ME:
self.processed += 1
tsk.hasrun = Task.SKIPPED
self.skip(tsk)
self.add_more_tasks(tsk)
else:
# run me: put the task in ready queue

View File

@ -90,92 +90,16 @@ def get_out(self):
return tsk
Runner.Parallel.get_out = get_out
if 1:
def start(self):
self.total = self.bld.total()
while not self.stop:
self.refill_task_list()
# consider the next task
tsk = self.get_next_task()
if not tsk:
if self.count:
# tasks may add new ones after they are run
continue
else:
# no tasks to run, no tasks running, time to exit
break
if tsk.hasrun:
# if the task is marked as "run", just skip it
self.processed += 1
continue
if self.stop: # stop immediately after a failure was detected
break
try:
st = tsk.runnable_status()
except Exception:
self.processed += 1
# TODO waf 1.7 this piece of code should go in the error_handler
tsk.err_msg = Utils.ex_stack()
if not self.stop and self.bld.keep:
tsk.hasrun = Task.SKIPPED
if self.bld.keep == 1:
# if -k stop at the first exception, if -kk try to go as far as possible
if Logs.verbose > 1 or not self.error:
self.error.append(tsk)
self.stop = True
else:
if Logs.verbose > 1:
self.error.append(tsk)
continue
tsk.hasrun = Task.EXCEPTION
self.error_handler(tsk)
continue
if st == Task.ASK_LATER:
self.postpone(tsk)
elif st == Task.SKIP_ME:
self.processed += 1
tsk.hasrun = Task.SKIPPED
self.add_more_tasks(tsk)
# shrinking sets
try:
ws = tsk.waiting_sets
except AttributeError:
pass
else:
for k in ws:
k.remove(tsk)
else:
# run me: put the task in ready queue
tsk.position = (self.processed, self.total)
self.count += 1
tsk.master = self
self.processed += 1
if self.numjobs == 1:
tsk.process()
else:
self.add_task(tsk)
# self.count represents the tasks that have been made available to the consumer threads
# collect all the tasks after an error else the message may be incomplete
while self.error and self.count:
self.get_out()
#print loop
assert (self.count == 0 or self.stop)
# free the task pool, if any
self.free_task_pool()
Runner.Parallel.start = start
def skip(self, tsk):
tsk.hasrun = Task.SKIPPED
# shrinking sets
try:
ws = tsk.waiting_sets
except AttributeError:
pass
else:
for k in ws:
k.remove(tsk)
Runner.Parallel.skip = skip