[Scons-users] ListVariables

Bill Deegan bill at baddogconsulting.com
Mon Jul 24 15:06:27 EDT 2017


It looks like SCons is doing the right thing, even thought the output is
confusing.
Here's the __str__ method for ListVariable()

def __str__(self):
    if len(self) == 0:
        return 'none'
    self.data.sort()
    if self.data == self.allowedElems:
        return 'all'
    else:
        return ','.join(self)

Note the "return all" when it detects that all allowed options are selected.

If I change your example to also print len(env['WITH_MQ']), I get the following:

MacBook-Pro:tmp bdbaddog$ python ../hg/scons/src/script/scons.py -f
SConstruct.ListVariables WITH_MQ=all
scons: Reading SConscript files ...
WITH_MQ = BROKER,PUB,SUB
WITH_MQ = 3
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.


-Bill


On Mon, Jul 24, 2017 at 7:24 AM, Mats Wichmann <mats at wichmann.us> wrote:

>
> 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'])
> ===
> _______________________________________________
> 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/20170724/11bcc398/attachment.html>


More information about the Scons-users mailing list