嵌套的SCons Builder

时间:2014-09-19 20:06:00

标签: scons

我想对SCons Builder输出进行一些后期处理:

env = Environment()
bld = Builder(action = 'postproc $SOURCE $TARGET')
env.Append(BUILDERS = {'PostProc': bld})
prog = env.Program('foo.c')
env.PostProc('foo.pp',prog)

这可以按预期工作。但是,我更喜欢使用一个Builder调用,所以我想我可以像这样嵌套它:

env = Environment()
bld = Builder(action = 'postproc $SOURCE $TARGET')
env.Append(BUILDERS = {'PostProc': bld})

def build_pp(env, target, source):
    prog = env.Program(source)
    return env.PostProc(target,prog)

bld2 = Builder(action = build_pp)
env.Append(BUILDERS = {'BuildPP': bld2})

env.BuildPP('foo.pp','foo.c')

但可理解的结果是:

scons: *** [foo.pp] Multiple ways to build the same target were specified for: foo.pp (from ['foo.c'] and from ['foo'])

知道如何实现这一目标吗?

1 个答案:

答案 0 :(得分:4)

将几个构建器包装成一个构建器(可能与扩展参数解析等相结合)通常使用伪构建器完成。查看第20章" Pseudo-Builders:User Guide的AddMethod函数" 以及http://www.scons.org/wiki/ToolsForFools上的工具编写指南。