Search code examples
buildscons

How to add a new command line variable to an existing construction Environment?


Suppose I have a SConstruct which exports a construction environment to a subsidiary SConscript:

Export('SConscript', 'env')

I'd like for SConscript to insert a command line variable foo into env so that I can invoke builds with the command

scons foo=bar

Is this possible, or must support for such command line variables be supplied to the environment's constructor?


Solution

  • Create a new Variables object containing the new variable and then update the environmentin the subsidiarySConscript`:

    Import('env')
    vars = Variables()
    vars.Add('foo', help='a command line variable named foo')
    vars.Update(env)