Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.

This value node has a string argument which substitutes values from the environment. This is usefull for:

   1 import SCons.Node.Python
   3 class EnvValue(SCons.Node.Python.Value):
   4     """Node class which substitutes variables from the environment"""
   5     def __init__(self,env,value):
   6         """Initialiser takes an Environment and a string to be
   7 expanded."""
   8         SCons.Node.Python.Value.__init__(self,value)
   9         self.env=env
  10     def __str__(self):
  11         return env.subst(self.value)

Now you can do something like this:

   1 env.Command('target',EnvValue(env,'$MYVAR'),'echo $SOURCE > $TARGET')
   2 env['MYVAR']='SomeValue'

There is one scenario in which the results might not be as expected. This is when the builder creates an override environment. In this case the environment used for the value node is not the same as that used for the builder:

   1 env['MYVAR']='DefaultValue'
   2 env.Command('target',EnvValue(env,'$MYVAR'),'echo $SOURCE > $TARGET',MYVAR='SomeValue')

In this example the command becomes

echo DefaultValue

For a builder which is a python function which references environment values, you might want to have add an emitter function which adds a EnvValue as a dependency (I have not tried that yet).

EnvValue (last edited 2008-03-12 02:47:02 by localhost)