SCons自定义构建器 - 使用多个文件构建并输出一个文件

时间:2012-02-08 23:45:38

标签: builder scons

如果我有一个可执行文件,一次生成多个文件的输出 -

generate_output -o a.out -f input1.txt input2.txt input3.txt

有没有办法为此编写这样的自定义构建器? 我现在所拥有的是 -

builder = Builder(
        action='generate_output -o $TARGET -f $SOURCE',
        suffix='.out', src_suffix='.txt')

然后它只生成序列中的文件,这不是我真正想要的 -

generate_output -o input1.out -f input1.txt
generate_output -o input2.out -f input2.txt
# etc...

1 个答案:

答案 0 :(得分:10)

尝试使用$SOURCES,请参阅Variable Substitution

builder = Builder(
        action='generate_output -o $TARGET -f $SOURCES',
        suffix='.out', src_suffix='.txt')

这个简单的例子对我有用:

env = Environment()

builder = Builder(action='cat $SOURCES > $TARGET',
        suffix='.out', src_suffix='.txt')

env = Environment(BUILDERS = {'MyBld' : builder})

env.MyBld('all', ['a.txt', 'b.txt', 'c.txt'])

只要generate_output不需要-f在每个输入文件之前,这将有效。

相关问题