3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """Variable type for list Variables.
26 A 'list' option may either be 'all', 'none' or a list of names
27 separated by comma. After the option has been processed, the option
28 value holds either the named list elements, all list elements or no
33 list_of_libs = Split('x11 gl qt ical')
39 help='libraries to build as shared libraries',
45 for lib in list_of_libs:
46 if lib in env['shared']:
52 # Known Bug: This should behave like a Set-Type, but does not really,
53 # since elements can occur twice.
56 from typing
import Tuple
, Callable
60 __all__
= ['ListVariable',]
63 class _ListVariable(collections
.UserList
):
64 def __init__(self
, initlist
=None, allowedElems
=None) -> None:
67 if allowedElems
is None:
69 super().__init
__([_f
for _f
in initlist
if _f
])
70 self
.allowedElems
= sorted(allowedElems
)
72 def __cmp__(self
, other
):
75 def __eq__(self
, other
):
78 def __ge__(self
, other
):
81 def __gt__(self
, other
):
84 def __le__(self
, other
):
87 def __lt__(self
, other
):
90 def __str__(self
) -> str:
94 if self
.data
== self
.allowedElems
:
99 def prepare_to_store(self
):
100 return self
.__str
__()
102 def _converter(val
, allowedElems
, mapdict
) -> _ListVariable
:
109 val
= [_f
for _f
in val
.split(',') if _f
]
110 val
= [mapdict
.get(v
, v
) for v
in val
]
111 notAllowed
= [v
for v
in val
if v
not in allowedElems
]
114 "Invalid value(s) for option: %s" % ','.join(notAllowed
)
116 return _ListVariable(val
, allowedElems
)
119 # def _validator(key, val, env) -> None:
121 # # TODO: write validator for pgk list
125 def ListVariable(key
, help, default
, names
, map={}) -> Tuple
[str, str, str, None, Callable
]:
126 """Return a tuple describing a list SCons Variable.
128 The input parameters describe a 'list' option. Returns
129 a tuple including the correct converter and validator.
130 The result is usable for input to :meth:`Add`.
132 *help* will have text appended indicating the legal values
133 (not including any extra names from *map*).
135 *map* can be used to map alternative names to the ones in *names* -
136 that is, a form of alias.
138 A 'list' option may either be 'all', 'none' or a list of
139 names (separated by commas).
141 names_str
= 'allowed names: %s' % ' '.join(names
)
142 if SCons
.Util
.is_List(default
):
143 default
= ','.join(default
)
145 (help, '(all|none|comma-separated list of names)', names_str
))
146 return (key
, help, default
, None, lambda val
: _converter(val
, names
, map))
150 # indent-tabs-mode:nil
152 # vim: set expandtab tabstop=4 shiftwidth=4: