0

How do I mark a rule in Waf such that the build doesn't stop on that rule's failure?

ex.

bld(rule="magicalcommand {SRC} {TGT}", source="somefile", target="othersuchfile")

where magicalcommand may somehow fail (but it's okay for that command to fail).

user
  • 4,920
  • 3
  • 25
  • 38
  • Not related to waf specifically, but to all build systems in general - you could create a wrapper script that will return 0 regardless of it's content commands results (or even `magicalcommand || true` for nix systems). Sadly it isn't too portable way. – keltar Oct 03 '13 at 08:43

1 Answers1

0

Solved it by turning the rule from a string into a function with the actual execution call wrapped into a try/except block:

def somefunc(task):
    # set up the command string using task.inputs, task.outputs [, and task.env]
    cmd = 'magicalcommand ' + task.inputs[0].abspath() + ' ' + task.outputs[0].abspath()
    try:
        return bld.cmd_and_log(cmd)
    except Exception as e:
        from waflib import Logs
        Logs.info('cmd failed!')
        return 0

bld(rule=somefunc, source='somefile', target='othersuchfile')

Note that I'm using bld.cmd_and_log, not bld.exec_command. The former actually throws on error (and supposedly supplies access to the stdout and stderr of the command through e on failure), the latter just kills the entire build process for me.

user
  • 4,920
  • 3
  • 25
  • 38