pythonbuildwaf

Copying multiple files in waf using only a single target


The waf book shows that I can create a task generator which will copy a file:

def build(ctx):
    ctx(source='wscript', target='foo.txt', rule='cp ${SRC} ${TGT}')

This will result in a target, shown with waf configure list, called foo.txt. So that I can then do things like this:

waf configure build --targets=foo.txt

which is all well and good.

However, suppose I want to copy, say 200 files, all to populate a directory within the build directory, let's call that directory examples.

If I repeat this for each of the 200 files, I will have 200 targets and hence forth when I type waf configure list will get 200 targets and waf configure list will be rendered practically useless because of the explosion of output.

But I really want the copying of these 200 files to be a single target so that I can do something like waf configure build --targets=examples. How can I do this???


Solution

  • Use the buildcopy tool:

    import buildcopy
    ...
    def build(ctx):
        ctx(name = 'copystuff',
            features = 'buildcopy',
            buildcopy_source = ctx.path.ant_glob('examples/**'))
    

    This will recursively copy the examples directory tree to the build directory. Only one target copystuff is introduced.

    As an aside, if you want to copy one file:

    ctx(features = 'subst', 
        source = '...', target = '...',
        is_copy = True)
    

    is way better than calling the system's cp command.