Question

Is there a better/shorter way to create these 2 tasks, which work on multiple files? I would prefer new_task_generator instead of cryptic classes.

Files = ["src1.c", "src2.c"]

    for File in Files:
        bld.new_task_gen(
            name = "Proc1_task",
            source = File,
            target= File + ".p1",
            rule ="Proc1.exe ${SRC} > ${TGT}")

    for File in Files:
        bld.new_task_gen(
            name = "Proc2_task",
            after = "Proc1_task", # not parallel with Proc1_task
            source = File,
            target= File + ".p2",
            rule ="Proc2.exe ${SRC} > ${TGT}")

Proc1.exe and Proc2.exe only accept one file per call.

Was it helpful?

Solution

If your sources files have a specific extension like .c, the most simple way is to add a hook to this extension:

@extension('.c')
def process_my_extension(self, node):

    task1 = self.create_task("task1", node, node.change_ext(".p1"))
    task2 = self.create_task("task2", node, node.change_ext(".p2"))

    task2.set_run_after(task1)

class task1_task(Task.Task):

    run_str = "Proc1.exe ${SRC} > ${TGT}"
    ext_in  = ['.c']
    ext_out = ['.p1'] 

class task2_task(Task.Task):

    run_str = "Proc2.exe ${SRC} > ${TGT}"
    ext_in  = ['.c']
    ext_out = ['.p2']

The best is to do it in a specific file (mytool.py) which you load in your main wscript:

def configure(conf):

    conf.load("mytool", tooldir = ".") # load your mytool.py

def build(bld):

    bld(
        source = ["src1.c", "src2.c", ],
    )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top