1

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} ...'
1
  • Which version of waf do you use ? And, please add a minimal wscript that should but does not work ...
    – neuro
    Mar 18, 2014 at 15:48

1 Answer 1

2

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 ...

4
  • Thank you! I will try it out. Mar 19, 2014 at 10:35
  • @Vincent: you are welcome. Click on the upper little arrow if the answer is useful :) and accept it if it answers your problem ;)
    – neuro
    Mar 20, 2014 at 16:16
  • I have founded that Waf is way better than make, just it's a bit hard to get started with cross-compiler, but it's definitely worth the effort. Mar 20, 2014 at 23:00
  • 1
    Yes I stop using make on a big project when it takes more than a minute to say there is nothing to do ^^
    – neuro
    Mar 21, 2014 at 8:16

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.