我希望在另一个waf任务中使用waf任务的目标作为源,但这不像预期的那样工作。
一个简单但完整的例子:我添加了两个任务(t_1
,t_2
)作为一个特性,并通过before
和after
添加了它们的约束。
t_1
中,我使用src=link_task.outputs[0]
作为任务的src
,使用link_task.outputs[0].change_ext('.txt')
作为任务的tgt
。t_2
中,我想使用t_1
的输出/目标作为输入。我以为我可以通过引用self.t_1.ouputs
来获得它,但这似乎是错误的。为什么这在t_1
中适用于apply_link
任务,而不适用于t_1
python waf configure build
将导致:
user@膝上型计算机/cygdrive/c/work $pythonWAF-1.9.13将干净生成设置设置顶部配置为: /cygdrive/c/work : /cygdrive/c/work/build检查“gcc”(C编译器):/usr/bin/gcc成功完成(0.150秒)“清洁”成功完成(0.010 s) Waf:输入目录/cygdrive/c/work/build' 'task\_gen' object has no attribute 't\_1' <===================== How to get this working [1/3] Compiling main.c [2/3] Linking build/abc.exe [3/3] Compiling build/abc.exe abc.exe Waf: Leaving directory
/cygdrive/c/work/build‘build’已成功完成(0.270)发布于 2018-01-08 18:06:35
before
和after
装饰器应用于任务生成器方法,而不是任务。你应该:
@TaskGen.feature('t_1')
@TaskGen.after('apply_link')
# correction: no need to use @TaskGen.before('add_t_2_task')
def add_t_1_task(self):
# correction: you have to define self.t_1
self.t_1 = self.create_task(
't_1',
self.link_task.outputs[0],
self.link_task.outputs[0].change_ext('.txt')
)
@TaskGen.feature('t_2')
@TaskGen.after('apply_link', 'add_t_1_task') # correction: use method name
def add_t_2_task(self):
# add_t-2_task is executed after add_t_1_task, so using self.t_1 is ok
print "t_1", self.t_1
顺便说一句,不要使用always_run=True
,因为它击败了waf的一个主要特性,即只构建您需要构建的内容:)
https://stackoverflow.com/questions/47630926
复制相似问题