自定义WAF任务既不运行也不查找源 [英] Custom waf task does neither run nor find sources

查看:107
本文介绍了自定义WAF任务既不运行也不查找源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的wscript中,我在apply_link方法之后运行了一些自定义任务(dummy),效果很好.

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

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

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:

  • 任务似乎根本没有生成.
  • bld.path.get_bld().ant_glob(...)找到的输出文件不会传递到任务.
  • 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.

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至少找到输出文件(当然,现在它们已经存在;)),但甚至没有运行我的其他自定义任务:

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)

所以我的问题总结为:

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

推荐答案

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

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.

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

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

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

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
)

这篇关于自定义WAF任务既不运行也不查找源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆