Search code examples
scons

In scons call a custom function using builder


I have a custom function which I want to call using builder object

def generate_action(target, source, env):
    print "TRIDIP:::::::I am in"
    return None

Now I created a builder

env['BUILDERS']['generateAction'] = Builder(action = generate_action)
action = env.generateAction() 

As you see, I have not pass any arugument and I don't want to pass any argument for which my custom function generate_action() is not called. I want to call the function without any argument.


Solution

  • You have to call the Builder, specifying the result file you depend on as source. You can't leave the "target=" and "source=" parameters out at the same time, because SCons has to know where in the total build graph this step fits in. Your SConscript should look something like (untested, and from the top of my head):

    # env = Environment()
    env['BUILDERS']['generateAction'] = Builder(action = generate_action)
    # creates your other result file
    myResult = env.someOtherBuilder('out.foo', 'in.txt')
    # calls your generate_action method
    action = env.generateAction('dummy.txt', myResult)
    

    Note, how this will always call your "generateAction" Builder, because the "dummy.txt" is never created, so the target is never up-to-date.

    Finally, my guess is that this answer won't really help and lead you into more trouble. When people try to call custom methods at build time they're usually using SCons in a wrong way...most of the time because they don't have the correct mental model to understand how SCons works. You might want to read up on some basics in the UserGuide ( http://scons.org/doc/production/HTML/scons-user.html ) or ask your further questions on our User mailing list at scons-users@scons.org (see also http://scons.org/lists.php ).