[Scons-users] Dependencie with Sconscripts and builder's environment
Dirk Bächle
tshortik at gmx.de
Wed Oct 12 03:12:58 EDT 2016
Hi Albert,
On 12.10.2016 01:27, Albert Arquer wrote:
> Hi Dirk,
>
> sorry for all the questions but I am not that experienced in python.
>
> I have been looking around the scons sources and I have found the get_presig function implemented in FunctionAction.
>
> However my question is, how can I overrinde this class from my sconscripts? Modifying the scons libraries is not an option...
>
okay...what you basically need is the knowledge that functions are first-class objects in Python. So you can assign them and treat
them in the same way as normal variables. So, in your SConscript you do
import SCons.Action
import SCons.Builder
def myBuildMethod():
...
# Create Action
myFuncAct = SCons.Action.Action(myBuildMethod)
# Get at the original presig function
origPresig = myFuncAct.get_presig
# Define our own version of it, where we append the variable of interest
def wrappedPresig():
return origPresig + env.subst("$COMMAND")
# Set this as our new presig method
myFuncAct.get_presig = wrappedPresig
# Now create a proper Builder with our monkey-patched presig function
myBuilder = SCons.Builder.Builder(myFuncAct)
, all from the top of my head and untested. ;)
I hope this helps you further already, but other Python experts might chime in on this as well.
Best regards,
Dirk
More information about the Scons-users
mailing list