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

koo*_*koo 6 builder scons

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

generate_output -o a.out -f input1.txt input2.txt input3.txt
Run Code Online (Sandbox Code Playgroud)

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

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

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

generate_output -o input1.out -f input1.txt
generate_output -o input2.out -f input2.txt
# etc...
Run Code Online (Sandbox Code Playgroud)

Dav*_*her 10

尝试使用$SOURCES,请参阅变量替换:

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

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

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'])
Run Code Online (Sandbox Code Playgroud)

只要generate_output不需要-f在每个输入文件之前,这将起作用.