Custom waf task does neither run nor find sources

主宰稳场 提交于 2019-12-10 18:27:42

问题


In my wscript I run some custom Task (dummy) after the apply_link method, and this works fine.

After this dummy-task has finished I want to collect all of my output files (let it be *.dll, *.exe, *.o, *.a or *.elf) and run another task on these output file, but I get two errors:

  • The task seems not to be generated at all.
  • The output files found by bld.path.get_bld().ant_glob(...) are not passed to the task.

Thewscript looks like this:

#!/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 output:

$ 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)

If I re-run the build command waf at least finds the the output files (of course, now they are alredy present ;) ), but not even then it runs my other custom task:

$ 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)

So my questions summarize to:

  • Why does waf not respect the constraint to search for the output files after @TaskGen.after('add_dummy_task') has finished
  • Why does the task not run, even if the files are present since a previous build is available.

回答1:


The constraint added by Taskgen.after is only on the order of task generator methods. It does not imply ANY constraint on tasks. You can see that by using the --zone task_gen option.

The only source you described is main.c which does not trigger your process method.

Probably a typo, but your second task generator has no source attribute needed by Taskgen.extension, nor features attribute. Try:

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


来源:https://stackoverflow.com/questions/53665743/custom-waf-task-does-neither-run-nor-find-sources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!