1 """engine.SCons.Options.BoolOption
3 This file defines the option type for SCons implementing true/false values.
8 opts.Add(BoolOption('embedded', 'build for an embedded system', 0))
10 if env['embedded'] == 1:
17 # Permission is hereby granted, free of charge, to any person obtaining
18 # a copy of this software and associated documentation files (the
19 # "Software"), to deal in the Software without restriction, including
20 # without limitation the rights to use, copy, modify, merge, publish,
21 # distribute, sublicense, and/or sell copies of the Software, and to
22 # permit persons to whom the Software is furnished to do so, subject to
23 # the following conditions:
25 # The above copyright notice and this permission notice shall be included
26 # in all copies or substantial portions of the Software.
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
29 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
30 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
39 __all__ = ('BoolOption', 'True', 'False')
45 __true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' )
46 __false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
48 # we need this since SCons should work version indepentant
54 Converts strings to True/False depending on the 'truth' expressed by
55 the string. If the string can't be converted, the original value
58 See '__true_strings' and '__false_strings' for values considered
59 'true' or 'false respectivly.
61 This is usable as 'converter' for SCons' Options.
63 lval = string.lower(val)
64 if lval in __true_strings: return True
65 if lval in __false_strings: return False
66 raise ValueError("Invalid value for boolean option: %s" % val)
69 def _validator(key, val, env):
71 Validates the given value to be either '0' or '1'.
73 This is usable as 'validator' for SCons' Options.
75 if not env[key] in (True, False):
76 raise SCons.Errors.UserError(
77 'Invalid value for boolean option %s: %s' % (key, env[key]))
80 def BoolOption(key, help, default):
82 The input parameters describe a boolen option, thus they are
83 returned with the correct converter and validator appended. The
84 'help' text will by appended by '(yes|no) to show the valid
85 valued. The result is usable for input to opts.Add().
87 return (key, '%s (yes|no)' % help, default,
88 _validator, _text2bool)