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

Andrew C. Morrow andrew.c.morrow at gmail.com
Wed Jul 9 14:07:00 EDT 2014


On Wed, Jul 9, 2014 at 1:29 PM, Dirk Bächle <tshortik at gmx.de> wrote:
> Hi Andrew,
>
> On 09.07.2014 18:43, Andrew C. Morrow wrote:
>>
>> [...]
>>
>> 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:
>
>
> if you need to provide a default value for your option, you can do this with
> the "default=" keyword. AddOption() uses the same syntax as
> optparse.add_option, as mentioned in the UserGuide, sect. "10.1.5: the
> AddOption function".
>

Of course, but that doesn't really help here. The issue is more that
for some variables, especially those that are set to some default by
tools (lets call it TOOL_OPT to avoid confusion), stating the option
in the Environment constructor overrides the autoselected value, even
if the option is not passed by the user:

Environment(
    tools=['tool'],
    TOOL_OPT=None,
)

may not be equivalent to

Environment(
    tools=['tool'],
)

Which means you can't write:

Environment(
    tools=['tool'],
    TOOL_OPT=GetOption('tool-opt'),
)

On the other hand, using Variables does work correctly here, in that
if TOOL_OPT is declared with AddVariables but is not passed on the
command line, then the autoselected value is still respected when the
Environment is initialized with 'variables='. But see my other recent
post for some issues with Variables when the target variable in the
Environment has semantics for a Python None value. It seems there is
no way to select the None value from the command line.

>
>>
>> The documentation states that HOST_ARCH must be set at construction
>> time, so I can't optionally do it later.
>
>
> Note, that you can always start with an empty environment:
>
>   env = Environment(tools=[])
>
> and then add Tools later with:
>
>   env.Tool('qt4')
>
> , once its required environment variables are setup properly.

OK, so the solution would be to build up iteratively, more or less.
But I don't think it would actually work for HOST_ARCH, since I
believe the default for that is set by the win32 Platform setup,
rather than the tools?

Do you see a problem with my approach of building up an environment
dict and then using **kwargs to set up in one go? It seems more
reliable than assuming certain variables are
generated/managed/consumed by particular tools.

envdict = {
    tools : [list, of, tools],
}

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

env = Environment(**envdict)

Thanks,
Andrew


More information about the Scons-users mailing list