自定义waf任务既不会运行,也不会找到源

时间:2018-12-07 08:24:06

标签: waf

wscript方法之后,我在dummy中运行了一些自定义任务(apply_link),

完成此dummy任务之后,我想收集所有输出文件(将其设为*.dll*.exe*.o*.a*.elf),然后在这些输出文件上运行另一个任务,但出现两个错误:

  • 任务似乎根本没有生成。
  • bld.path.get_bld().ant_glob(...)找到的输出文件不会传递给任务。

wscript看起来像这样:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-

top = '.'
out = 'build'

VERSION = '0.0.0'
APPNAME = 'app'

from waflib import Task, TaskGen

def options(opt):
    opt.load('compiler_c')

def configure(conf):
    conf.load('compiler_c')

def build(bld):
    bld.program(target='app', features='dummy', source='main.c')
    bld.path.get_bld().ant_glob('**/*.elf **/*.a **/*.o', quiet=True)
    bld(bld.path.get_bld().ant_glob('**/*.elf **/*.a **/*.o', quiet=True))


class tsk_1(Task.Task):
    run_str = 'echo Hello from dummy and ${SRC} > ${TGT}'
    color = 'GREEN'


@TaskGen.feature('dummy')
@TaskGen.after_method('apply_link')
def add_dummy_task(self):
    # create one more *.o file
    self.dummy_task = self.create_task(
        'tsk_1',
        src=self.link_task.outputs[0],
        tgt=self.link_task.outputs[0].change_ext('hello.o'))

@TaskGen.extension('.elf')
@TaskGen.extension('.a')
@TaskGen.extension('.o')
@TaskGen.after('add_dummy_task')
def process(self, node):
    self.sk = self.create_task('size', node)

class size(Task.Task):
    color = 'PINK'
    def run(self):
        print('Another hello from ${self.inputs[0]}')

Shell输出:

$ python waf clean configure build -v
'clean' finished successfully (0.036s)
Setting top to                           : /cygdrive/c/Users/user/Documents/waf-tests/test1
Setting out to                           : /cygdrive/c/Users/user/Documents/waf-tests/test1/build
Checking for 'gcc' (C compiler)          : 09:11:43 runner ['/usr/bin/gcc', '-dM', '-E', '-']
/usr/bin/gcc
'configure' finished successfully (0.123s)
Waf: Entering directory `/cygdrive/c/Users/user/Documents/waf-tests/test1/build'
[1/3] Compiling main.c
09:11:43 runner ['/usr/bin/gcc', '../main.c', '-c', '-o/cygdrive/c/Users/user/Documents/waf-tests/test1/build/main.c.1.o']
[2/3] Linking build/app.exe
09:11:43 runner ['/usr/bin/gcc', '-Wl,--enable-auto-import', 'main.c.1.o', '-o/cygdrive/c/Users/user/Documents/waf-tests/test1/build/app.exe', '-Wl,-Bstatic', '-Wl,-Bdynamic']
[3/3] Compiling build/app.exe
09:11:43 runner ' echo Hello from dummy and app.exe > apphello.o '
Waf: Leaving directory `/cygdrive/c/Users/user/Documents/waf-tests/test1/build'
'build' finished successfully (0.356s)

如果我重新运行build命令waf至少找到输出文件(当然,现在它们已经存在了;)),但是即使这样,它也不能运行我的其他自定义任务:

$ python waf build
Waf: Entering directory `/cygdrive/c/Users/user/Documents/waf-tests/test1/build'
[/cygdrive/c/Users/user/Documents/waf-tests/test1/build/apphello.o, /cygdrive/c/Users/user/Documents/waf-tests/test1/build/main.c.1.o]
Waf: Leaving directory `/cygdrive/c/Users/user/Documents/waf-tests/test1/build'
'build' finished successfully (0.040s)

所以我的问题总结为:

  • 为什么waf不遵守@TaskGen.after('add_dummy_task')完成后搜索输出文件的约束
  • 即使自从以前的版本可用以来,即使文件存在,任务也为什么不运行。

1 个答案:

答案 0 :(得分:2)

Taskgen.after添加的约束仅在任务生成器方法的顺序上。它并不意味着对任务有任何约束。您可以使用--zone task_gen选项看到这一点。

您描述的唯一来源是main.c,它不会触发您的process方法。

可能是拼写错误,但是您的第二个任务生成器没有source所需的Taskgen.extension属性,也没有features属性。试试:

bld(
    source = bld.path.get_bld().ant_glob('**/*.elf **/*.a **/*.o'),
    features = 'dummy',
    quiet = True
)