[Scons-users] Why is resetting user-defined options with SetOption forbidden?

Bill Deegan bill at baddogconsulting.com
Sun Mar 12 16:11:22 EDT 2017


Andrew,

Coincidentally I'm working on that code as part of the py2/3 port.
If I remember correctly, allowing users to specify options wasn't there
from the beginning of SCons and was added after many user requests.

Currently the code whitelists some options which are allowed to be set via
sconscripts.

I can't think of any good reason to dis-allow sconscripts to set the
locally added options.

-Bill



On Fri, Mar 10, 2017 at 2:26 AM, Dirk Baechle <tshortik at gmx.de> wrote:

> Hi Andrew,
>
> depending on how your additional conditions look like, couldn't this also
> be handled in a validator for the option in question?
>
> Best regards,
>
> Dirk
>
>
> Am 9. März 2017 20:06:45 MEZ schrieb "Andrew C. Morrow" <
> andrew.c.morrow at gmail.com>:
>>
>>
>> Hi -
>>
>> I'd like to be able to rewrite the value of an option I've defined with
>> AddOption, but SetOption appears to forbid this except for certain
>> intrinsic SCons options. This seems quite restrictive. I have many options
>> of this form:
>>
>>     AddOption('build-fast',
>>         choices=['on', 'off', 'auto'],
>>         const='on',
>>         default='auto',
>>         help='faster dependency checking',
>>         nargs='?',
>>         type='choice',
>>     )
>>
>> The 'auto' value is intended to allow the system to decide whether 'on'
>> or 'off' is appropriate, given the value of other options. However, the end
>> result is that it should hold the value 'on' or 'off'. So, ideally, I'd
>> later write:
>>
>> if GetOption('build-fast') == 'auto':
>>     if <conditions>:
>>         SetOption('build-fast') = 'on'
>>     else
>>         SetOption('build-fast') = 'off'
>>
>> That way, once I've done this normalization step, I can just ask anywhere
>> I need:
>>
>> if GetOption('build-fast') == 'on':
>>     do-stuff
>>
>> However, it seems that this is forbidden by SCons internally, even for
>> user-defined options, failing with a message like:
>>
>> scons: *** This option is not settable from a SConscript file: build-fast
>>
>> As a result, I need to hoist the option value into a variable, and
>> normalize that, then Export it for others to see and use instead of the
>> option value:
>>
>> build_fast = GetOption('build-fast')
>> if build_fast == 'auto':
>>     build_fast = 'on' if conditions else 'off'
>> Export('build_fast')
>>
>> This is unfortunate, since now the value of GetOption('build-fast')
>> isn't canonical, this exported state variable is instead, they vary in
>> their values, and it is easy to query the wrong one yielding different
>> results.
>>
>> I understand that some intrinsic SCons options may not make sense to be
>> reset, but is there an explicit reason that it cannot be done for user
>> defined options?
>>
>> Thanks,
>> Andrew
>>
>>
>>
> --
> Sent from my Android with K-9 Mail.
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20170312/86c9e5d4/attachment-0001.html>


More information about the Scons-users mailing list