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

Dirk Baechle tshortik at gmx.de
Fri Mar 10 02:26:14 EST 2017


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20170310/cefaf4a3/attachment.html>


More information about the Scons-users mailing list