[Scons-users] ListVariables

Mats Wichmann mats at wichmann.us
Mon Jul 24 10:24:28 EDT 2017


I've ended up a little mystified about the operation of ListVariable,
after I dug a bit to figure out if a certain change from the default
behavior was possible to code up.

scons-man reports this:

===
Return a tuple of arguments to set up an option whose value may be one
or more of a specified list of legal enumerated values. The option will
use the specified name key, have a default value of default, and display
the specified help text. The option will only support the values all,
none, or the values in the names list.
===

So is it intended that if you supply 'all' or 'none' to the option that
you will be passed those strings, or that they will be expanded to
values from the supplied list?

The ListVariable implementation includes a converter, helpfully named
_converter, which includes this code:

    if val == 'none':
        val = []
    elif val == 'all':
        val = allowedElems
    else:

yet when I code up a simple test and pass 'all' or 'none' they are not
expanded as the inclusion of this converter would suggest, they seem to
be passed through as is.  Is that the actual expectation? (the docs
don't say one way or the other)

(the mini use-case that sent me down this path was that we have places
where we really want the behavior "one or more" from the documentation
statement, that is a selection of 'none', whether passed as is or
expanded to an empty list, should be disallowed. obviously it's easy
enough to check for 'none' in the code afterwards so that isn't a huge
issue, but I was still looking for how to do)


Simple-minded example:
=== SConstruct
opts = Variables()
opts.Add(
    ListVariable(
        'WITH_MQ',
        'Build with MQ subscriber/publisher/broker',
        default='all',
        names=['PUB', 'SUB', 'BROKER'],
))
env = Environment(variables=opts)
Help(opts.GenerateHelpText(env))

print("WITH_MQ =", env['WITH_MQ'])
===


More information about the Scons-users mailing list