[Scons-users] Not clobbering autodetected HOST_ARCH when configured via Options

Andrew C. Morrow andrew.c.morrow at gmail.com
Wed Jul 9 12:43:58 EDT 2014


The following question uses HOST_ARCH because it is the construction
variable that was giving me trouble, but I think the question applies
to any construction variable that, if it is to be customized, must be
set at Environment construction time.

I can set up HOST_ARCH reasonably using Variables:

variables = AddVariables(
    (HOST_ARCH, "The host architecture for Windows builds"),
)

env = Environment(variables=variables).

The above does the right thing whether or not HOST_ARCH is passed to scons:

# OK, HOST_ARCH will be autoselected by SCons internals
> scons

# OK, HOST_ARCH will be set to x86
> scons HOST_ARCH=x86


If, instead, I want to manage HOST_ARCH via Options for consistency
with a project that currently uses Options for everything:

AddOption('--host-arch', ...)

env = Environment(
    HOST_ARCH=GetOption('host-arch'))
)

Then all is well if I pass --host-arch:

# OK, HOST_ARCH gets the value of --host-arch
> scons --host-arch=x86

But if I don't set the option, things are not OK:

# NOT OK, HOST_ARCH becomes 'None' in Environment, instead of taking
autoselected value:
> scons

The documentation states that HOST_ARCH must be set at construction
time, so I can't optionally do it later. One thought was to build the
argument dictionary to the Environment constructor incrementally, and
then pass it as the kwargs:

envdict = dict()

if GetOption('host-arch'):
    envdict['HOST_ARCH'] = GetOption('host-arch')

env = Environment(**envdict);

What is the preferred mechanism for optionally setting Environment
variables without disturbing defaults?

Thanks,
Andrew


More information about the Scons-users mailing list