简体   繁体   中英

Dynamic task generators

I am evaluating waf build for an existing project that has tasks similar to that:

1. preprocessing phase: datafile => TransformationTask => library name list
2. for each library name: 
  2.1 import files from repository
  2.2 build library

The library list depends on the preprocessing task and is naturally not known in advance.

How can this be achieved with waf?

An easy way to do that is to generate a file with the library list with a first task. Another tasks will have the output of the first as an input and will process the corresponding file if needed to generate what you need. This task will generate another task dynamically to process each library. Look for Task.more_tasks in the waf book.

Something like that:

def parse(content):
    ...

def create_lib(task_gen, lib):
    ...

def process_libs_list(task):
    libs_list = ""
    # [...]
    task.outputs[0].write(libs_list)

def generate_libs(task):
    task.more_tasks = []
    for node in task.inputs:
        libs_list = parse(node.read())
        for lib in libs_list:
            new_task = create_lib(task.generator, lib)
            task.more_tasks.append(new_task)

def build(bld):
    bld(rule = process_libs_list, source = "datafile", target = "libs_list")
    bld(rule = generate_libs, source = "libs_list")

Note: You can set it in a "plugin" if needed in many wscripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM