In some cases the information to process is very specific and does not really fit in the list of sources. The data may be attached to various attribute of the task generator, and a distinct task generator method may process the attributes dynamically.
In the following example, a new attribute 'tst' is added to task generators instances, and is used to call a method to print the contents of that attribute at the start of the build:
def build(bld): foo = bld.new_task_gen() foo.tst = 'hello, world' # alternate syntax: bld.new_task_gen(tst = 'hello, world')
To attach a new method to the task_gen class (the type of foo), the decorator @taskgen is used in the following manner:
from TaskGen import taskgen @taskgen def print_tst(self): print('processing the tst attribute: %r' % self.tst)
At this point, the function print_tst is attached to the class as a new method, but to process the attribute foo.tst, the method has to be called explicitly:
def build(bld): foo = bld.new_task_gen() foo.tst = 'hello, world' foo.print_tst()
To schedule that method for automatic execution, it is necessary to bind it somehow. The aliases are given in the task generator attribute features:
from TaskGen import taskgen, feature @taskgen @feature('TEST') def print_tst(self): print('processing the tst attribute: %r' % self.tst) def build(bld): foo = bld.new_task_gen() foo.features = ['TEST'] foo.tst = 'hello, world'
For mapping the method to all features, the wildcard * may be used, a complete example is reproduced below:
srcdir='.' blddir='build' from TaskGen import taskgen, feature @taskgen @feature('*') def print_tst(self): print('processing the tst attribute: %r' % self.tst) def build(bld): foo = bld.new_task_gen() foo.tst = 'hello, world' def configure(conf): pass def set_options(opt): pass
Upon execution, this produces the following output:
$ waf processing the tst attribute: hello, world