Task generatorsTasks are not manipulated directly, but generated using instances of the class task_gen. The roles of the class task_gen are the following: - hold parameters that can be shared by many tasks
- perform parameter verification
- map file extensions to task types
- generate the tasks
- provide extensions
ExtensionsTask generators do not use inheritance: - to avoid code duplication
- to avoid huge class hierarchies
- to separate the code cleanly in different modules
To replace this, methods are attached to the task_gen class itself, at runtime. The following constraints are added when attaching a new method: - inclusion: run this method if this task generator requires that feature (program -> use the method link_cpp_files)
- precedence/order: run method1 before method2
- optionally a file extension (additional function parameter required)
@taskgen
@feature('cprogram', 'cshlib', 'cstaticlib')
@after('apply_core')
def apply_link(self):
print 'some code to execute'After task generators are declared, the method post is called to execute the relevant task_gen methods: - task_gen methods matching an entry in obj.features are added for execution
- task_gen methods are then sorted using the precedence rules (@after('othermethod'))
- task_gen methods are then executed
File or suffix associationsSince the most common scenario is the execution of methods when a filename matching a particular pattern is found, a central method "apply_core" is executed by default: - the method apply_core is called
- if a name in the list obj.source is mapped to a method, that method is called, or
- the name is converted to a node, and if the name suffix is mapped to a method, that method is called
@extension(['.c', '.cc'])
def c_hook(self, node):
print "create a c task here"
|