如何在 Waf 中标记规则,以使构建不会因该规则失败而停止?
前任。
bld(rule="magicalcommand {SRC} {TGT}", source="somefile", target="othersuchfile")
wheremagicalcommand
可能会以某种方式失败(但该命令失败也没关系)。
如何在 Waf 中标记规则,以使构建不会因该规则失败而停止?
前任。
bld(rule="magicalcommand {SRC} {TGT}", source="somefile", target="othersuchfile")
wheremagicalcommand
可能会以某种方式失败(但该命令失败也没关系)。
通过将规则从字符串转换为函数并将实际执行调用包装到 try/except 块中来解决它:
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')
请注意,我使用的是bld.cmd_and_log
,而不是bld.exec_command
。stdout
前者实际上会引发错误(并且据说stderr
通过失败提供对命令的访问e
),后者只是为我杀死了整个构建过程。