[Scons-users] Dependencie with Sconscripts and builder's environment

Dirk Bächle tshortik at gmx.de
Tue Oct 11 15:58:49 EDT 2016


Albert,

On 11.10.2016 21:22, Albert Arquer wrote:
> Python value node? Please could you elaborate on how that would work?
>

sure...here's a simple example


   import time
   e = Command('wibble', 'a', 'echo foo >> $TARGET')
   Depends(e, Value(time.strftime("%H:%M", time.localtime())))


where I store the formatted current time in a Value node, and let the target file depend on it too. As a result, the build command 
is rerun whenever the input file "a" changes, but also after every full minute.
You should be able to init your Value node with something like "env.subst('$COMMENT')", which should then get substituted to the 
actual string each time the SConscript is parsed.

You can find some more info about Value nodes in the MAN pages.

> Isn't there any other way this can be done? Could I redefine the get_presig method for the builder? Or maybe use different kinds of
> builers? (As you mentioned mine is a python Action, maybe there are others?)
>

This is Python, so monkey-patching is always an option. ;) Create the FunctionAction, then wrap the original get_presig method and 
reassign...

Dirk


> We thought we could dump the whole env into a file when registering a target and then pass that file as a builder source, but we are
> doing this for code redability and evaluation speed, and I am not sure if that would accomplish neither...
>

Before you go down this road, the Value approach above seems far more lightweight to me. You can wrap the "Create this kind of 
target, and add an explicit dependency to $COMMENT"-part into a Python function if you like... (see also pseudo-Builders in 
https://bitbucket.org/scons/scons/wiki/ToolsForFools ).




More information about the Scons-users mailing list