SCons custom builder - build with multiple files and output one file

痞子三分冷 提交于 2020-01-03 11:29:09

问题


If I have an executable that generates an output from multiple files at a time -

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

Is there a way to write such a custom builder for this? What I have at the moment is -

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

Then it only generates files in a sequence, which is not what I really wanted -

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

回答1:


Try using $SOURCES, see Variable Substitution:

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

It works for me in this simple example:

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'])

This will work as long as generate_output doesn't require -f to precede each input file.



来源:https://stackoverflow.com/questions/9203367/scons-custom-builder-build-with-multiple-files-and-output-one-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!