Task generator method execution

Methods may be added to task generators, and those methods are bound to features. At the beginning of the build, the task generator instances are executed one by one, and in turn their methods are executed to generate the tasks or to modify additional data. We will now describe what make task generator methods with an example:

Here is an example of a task generator method from the Waf source code:

from TaskGen import before, after, taskgen

@taskgen
@after('apply_obj_vars_cc')
@after('apply_obj_vars_cxx')
@before('apply_link')
def asm_incflags(self):
	if self.env['ASINCFLAGS']: self.env['_ASINCFLAGS'] = self.env['ASINCFLAGS']
			

In general, the methods cannot be called several times or in random order. For example, in c++ programming contexts, the compilation tasks must be created before link tasks because link task will reference the compilation tasks. This leads to a particular workflow, reproduced in the following illustration:

The list of methods to execute is kept in the attribute meths of the task generator instance. The list of methods to execute may be given directly.

It is however more convenient to use the attribute feature to add the methods automatically. For example, for creating a c application, the methods to execute depend on the operating system, so the feature system actually simplifies the code reuse.

The order constraints on the methods (after/before), are used to sort the list of methods in the attribute meths. The sorting is performed once, and the list is consumed as methods are executed. Though no new feature may be added once the first method is executed, new methods may be added dynamically in self.meths. Here is how to make an infinite loop:

from TaskGen import before, after, taskgen

@taskgen
@feature('*')
def infinite_loop(self):
	self.meths.append('infinite_loop')