Question

In Waf how can I create multiple custom tasks, that can run parallel (with --jobs=JOBS)?

Sources = ["C:\\src1.c", "C:\\Mod1\src2.c", ... 30pcs] # one per call
Incl_Paths = ["Mod1". "Mod1"]  # list all of them in all call
INCL_ST = "-I%s" # how to format an include path in an argument
Ext_out = "_loc" # output file extension

The goal:

C:\\LOC.exe -IMod1 -IMod2 C:\\src1.c > build\\src1.c_loc        //or better src1_loc
C:\\LOC.exe -IMod1 -IMod2 C:\\Mod1\src2.c > build\\src2.c_loc   //or better src2_loc
...

I couldn't get it work

def build(bld):
    for i in Sources:
        bld.new_task_gen(
            source = i,
            rule='C:\\LOC.exe ${INCL_ST:Incl_Paths} ${SRC} > ' + i + Ext_out,
        )

Also I couldn't extract the exe

# find_program(self, filename, path_list=[], var=None, environ=None, exts=''):

cfg.find_program("C:\\LOC.exe",  var='LOC')

To change from:

rule='C:\\LOC.exe ...'

To:

  rule='${LOC} ...'
Was it helpful?

Solution

Something like this should work with waf 1.7:

from waflib.Task import Task
from waflib.TaskGen import extension

Ext_out = "_loc" # output file extension

def configure(conf):
    # loc.exe must be in the system path for this to work
    conf.find_program(
        'loc',
        var = "LOC",
    )
    conf.env.Incl_Paths = ["Mod1", "Mod1"]
    conf.env.INCL_ST = "-I%s"

@extension('.c')
def process_loc(self, node):
    out_node = node.change_ext(Ext_out)
    tsk = self.create_task('loc')
    tsk.set_inputs(node)
    tsk.set_outputs(out_node)

class loc_task(Task):
    ext_in = ['.c']
    ext_out = ['_loc']
    run_str = "${LOC} ${INCL_ST:Incl_Paths} ${SRC} > ${TGT}"


def build(bld):
    bld(source = ["src1.c", "src2.c"])

Well it works for me on linux faking loc ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top