Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: scons-2.0.1/engine/SCons/Variables/BoolVariable.py

Issue 6711079: Added an unmodified copy of SCons to third_party. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/third_party/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scons-2.0.1/engine/SCons/Util.py ('k') | scons-2.0.1/engine/SCons/Variables/EnumVariable.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 """engine.SCons.Variables.BoolVariable
2
3 This file defines the option type for SCons implementing true/false values.
4
5 Usage example:
6
7 opts = Variables()
8 opts.Add(BoolVariable('embedded', 'build for an embedded system', 0))
9 ...
10 if env['embedded'] == 1:
11 ...
12 """
13
14 #
15 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S Cons Foundation
16 #
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:
24 #
25 # The above copyright notice and this permission notice shall be included
26 # in all copies or substantial portions of the Software.
27 #
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.
35 #
36
37 __revision__ = "src/engine/SCons/Variables/BoolVariable.py 5134 2010/08/16 23:02 :40 bdeegan"
38
39 __all__ = ['BoolVariable',]
40
41 import SCons.Errors
42
43 __true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' )
44 __false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
45
46
47 def _text2bool(val):
48 """
49 Converts strings to True/False depending on the 'truth' expressed by
50 the string. If the string can't be converted, the original value
51 will be returned.
52
53 See '__true_strings' and '__false_strings' for values considered
54 'true' or 'false respectivly.
55
56 This is usable as 'converter' for SCons' Variables.
57 """
58 lval = val.lower()
59 if lval in __true_strings: return True
60 if lval in __false_strings: return False
61 raise ValueError("Invalid value for boolean option: %s" % val)
62
63
64 def _validator(key, val, env):
65 """
66 Validates the given value to be either '0' or '1'.
67
68 This is usable as 'validator' for SCons' Variables.
69 """
70 if not env[key] in (True, False):
71 raise SCons.Errors.UserError(
72 'Invalid value for boolean option %s: %s' % (key, env[key]))
73
74
75 def BoolVariable(key, help, default):
76 """
77 The input parameters describe a boolen option, thus they are
78 returned with the correct converter and validator appended. The
79 'help' text will by appended by '(yes|no) to show the valid
80 valued. The result is usable for input to opts.Add().
81 """
82 return (key, '%s (yes|no)' % help, default,
83 _validator, _text2bool)
84
85 # Local Variables:
86 # tab-width:4
87 # indent-tabs-mode:nil
88 # End:
89 # vim: set expandtab tabstop=4 shiftwidth=4:
OLDNEW
« no previous file with comments | « scons-2.0.1/engine/SCons/Util.py ('k') | scons-2.0.1/engine/SCons/Variables/EnumVariable.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698