[Scons-users] Question about Variables

driscoll at cs.wisc.edu driscoll at cs.wisc.edu
Mon Sep 17 19:22:04 EDT 2012


I have a problem with the use of Variables.

If, in my SConstruct, I create a Variables object, add a FLAG to it,
create an environment, and print out the value of FLAG, everything
works as expected:

$ cat SConstruct
v = Variables()
v.AddVariables(
BoolVariable("FLAG", "A flag", False)
)
env = Environment(tools=[], variables=v)
print "FLAG is", env["FLAG"]

$ scons --quiet FLAG=False
FLAG is False

$ scons --quiet FLAG=true
FLAG is True

However, if I take the creation of the Variables() object and
Environment() and put it into its own module (inside site_scons),
importing things as appropriate, then things don't work and it ignores
the arguments:

$ cat SConstruct
import test

$ cat site_scons/test.py
import SCons.Environment
import SCons.Variables
import SCons.Script
Environment=SCons.Script.Environment
Variables=SCons.Variables.Variables
BoolVariable=SCons.Variables.BoolVariable

v = Variables()
v.AddVariables(
BoolVariable("FLAG", "A flag", False)
)
env = Environment(tools=[], variables=v)
print "FLAG is", env["FLAG"]

$ scons --quiet FLAG=False
FLAG is False

$ scons --quiet FLAG=true
FLAG is False


Obviously I'm doing weird things here, but why isn't it doing what I
expect, and what should I do to fix it?


(Some context: I'm creating a module that will need to look at command
line arguments to set up library paths, compiler paths, etc.; I really
don't think it fits into the notion of a "tool" though. If you go
through the Variables objects, there's no way to get the value of a
flag besides creating a temporary environment, which is the point of
creating the environments in the module. But alternative suggestions are
also welcome.)



More information about the Scons-users mailing list