waf跨项目依赖项

时间:2018-03-02 14:20:17

标签: waf build-system

我有一个简单的waf项目:

$ root
|-- a
|   `-- wscript
|-- b
|   `-- wscript
`-- wscript

Root wscript是

def configure(conf):
    pass

def build(bld):
    bld.recurse('a b')

a wscript是

def build(bld):
    bld (rule = 'touch ${TGT}', target = 'a.target' )

b wscript是

def build(bld):
    bld (rule = 'cp ${SRC} ${TGT}', source='a.target', target='b.target')

我想要实现的是拥有一个首先触及a.target的构建系统,然后将其复制到b.target。我希望a.targetb.target的规则保留在各自的wscript文件中。

当我尝试启动它时,我收到以下错误:

source not found: 'a.target' in bld(target=['b.target'], idx=1, tg_idx_count=2, meths=['process_rule', 'process_source'], rule='cp ${SRC} ${TGT}', _name='b.target', source='a.target', path=/<skip>/waf_playground/b, posted=True, features=[]) in /<skip>/waf_playground/b

如果我将这两个规则放在一个wscript文件中,那么一切都像魅力一样。

目标是否有办法依赖于其他wscript中定义的另一个目标?

1 个答案:

答案 0 :(得分:2)

指定源/目标时,相对于当前wscript文件表示。

$ waf configure build
...
source not found: 'a.target' in bld(source='a.target, ...)
...
$ tree build
build/
├── a
│   └── a.target
...

知道了,修复是在a.target中正确引用b/wscript源文件:

def build(bld):
    bld (rule = 'cp ${SRC} ${TGT}', source='../a/a.target', target='b.target')

现在任务正确找到源文件:

$ waf build
Waf: Entering directory `.../build'
[1/2] Creating build/a/a.target
[2/2] Compiling build/a/a.target
Waf: Leaving directory `.../build'
'build' finished successfully (0.055s)
$ tree build
build/
├── a
│   └── a.target
├── b
│   └── b.target
...