4
votes

I have a hierarchical build that use SConscript to declare build target recursively; so I don't know the targets beforehand. Each build will produce some extra files like *.err *.out that are not in targets. When I run scons -c, those files will be left uncleaned.

Is there a way to clean those file when I run scons -c?

1
Hi, thank you for your reply. I have looked into this before I ask, sorry I didn't made my question more clearer. I am wrapping scons as a general build system for other users. They will define what will be built use the SConscript under their folder. I do not wish to ask the users to manually add each of the output log files in their SConscript. What I know is the output file's folder in the same place as the target, the name will be the target's file name with the extension replaced to ".out" and ".err". Is there a way to set up the scons that let it automatically add those in? - Tianyu Yang

1 Answers

1
votes

One way to do this is to create you're own builder, then modify the emitter() function to include those possible extra targets.

In my own progject, I created my own builder around the SWIG tool because when it executes, I was saving the generated .py file in a different directory from the generate .cpp file. So the default scons -c wouldn't clean up the extra .py file.

So for your case you would do something like this:

def emitter(target, source, env):
    # based on the target, create File nodes for the files that will
    # get generated as a side effect.

    target.append('%s.err' % target[0])
    target.append('%s.out' % target[0])

    return target, source

Here a link to my builder tool for SWIG: SwigGen.py

This adds a new builder to the environment object so I can do:

env.SwigGen('module_wrapper.cpp', 'module.i')

And when I do a scons -c the extra 'module.py' that is created will get cleaned also.