Question

How can I start a task from within another task calling a different task class.

@feature('unites')
@after_method('apply_link')
def make_test_unites(self):
    if getattr(self, 'link_task', None):
        tsk = self.create_task('unites', self.link_task.outputs)
        tsk.a = []

@feature('gtester')
@after_method('apply_link')
def make_test_gtester(self):
    if getattr(self, 'link_task', None):
         tsk = self.create_task('gtester', self.link_task.outputs)

class unites (Task.Task):
    def runnable_status(self):
        ### print("Never reached!")
        ...

    def run(self):
        ...
        ### print("Never reached!")
        ...


class gtester (Task.Task):
     def runnable_status(self):
         //works as expected

     def run(self):
         ...
         bld = self.generator.bld
         ...
         #utask = unites(env=bld.env)
         utask = self.generator.create_task ('unites')
         assert (utask)
         utask.set_inputs(self.generator.link_task.outputs)
         utask.a = ["some foo extra stuff"]
         #bld.add_to_group (utask)

         ### print ("this is definitily reached")

So the code does not crash but when I use ./waf --zones=task_gen,tasks all I get is the one task for gtester, but none for unites.

This is how it is used in practice:

test = bld.program(
    features = ['c', 'glib2', 'gtester'],
            ...,
            ...
            )

Have had a deep look into the waf book and the API docs, but neither did yield anything useful.

So how can I schedule a task (or any number of tasks) from an already running task?

Was it helpful?

Solution

The solution is to use

 tsk = self.generator.create_task('unites')
 bld.producer.outstanding.insert(0, tsk)
 bld.producer.total += 1

And ./waf --zones=tasks shows the additional tasks.


Inspired by in the waf svn repo under ./waf/playground/dynamic_headers/wscript


A thing to mention: The [M/N] task count infront of each line will suddenly jump up when gtester is processed, which is due to the fact that the total count gets updated at the end of a Task so waf can not know about the total number until then.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top