2

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.

1 Answer 1

2

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", ],
    )
2
  • Nice solution! And what can we do if we have more extensions? Files = ["hdr1.h", "src2.c", "i2.inc"..] Mar 20, 2014 at 17:19
  • 1
    You can add another decorator @extension('.h') or write a custom task generator which add a specific feature
    – neuro
    Mar 21, 2014 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.