1 """engine.SCons.Variables.PackageVariable
3 This file defines the option type for SCons implementing 'package
6 To be used whenever a 'package' may be enabled/disabled and the
7 package path may be specified.
12 x11=no (disables X11 support)
13 x11=yes (will search for the package installation dir)
14 x11=/usr/local/X11 (will check this path for existance)
16 To replace autoconf's --with-xxx=yyy
19 opts.Add(PackageVariable('x11',
20 'use X11 installed here (yes = search some places',
23 if env['x11'] == True:
24 dir = ... search X11 in some standard places ...
27 ... build with x11 ...
33 # Permission is hereby granted, free of charge, to any person obtaining
34 # a copy of this software and associated documentation files (the
35 # "Software"), to deal in the Software without restriction, including
36 # without limitation the rights to use, copy, modify, merge, publish,
37 # distribute, sublicense, and/or sell copies of the Software, and to
38 # permit persons to whom the Software is furnished to do so, subject to
39 # the following conditions:
41 # The above copyright notice and this permission notice shall be included
42 # in all copies or substantial portions of the Software.
44 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
45 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
46 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
48 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
49 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
50 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
55 __all__ = ['PackageVariable',]
62 __enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search')
63 __disable_strings = ('0', 'no', 'false', 'off', 'disable')
68 lval = string.lower(val)
69 if lval in __enable_strings: return True
70 if lval in __disable_strings: return False
71 #raise ValueError("Invalid value for boolean option: %s" % val)
75 def _validator(key, val, env, searchfunc):
76 # NB: searchfunc is currenty undocumented and unsupported
79 # todo: write validator, check for path
83 env[key] = searchfunc(key, val)
84 elif env[key] and not os.path.exists(val):
85 raise SCons.Errors.UserError(
86 'Path does not exist for option %s: %s' % (key, val))
89 def PackageVariable(key, help, default, searchfunc=None):
90 # NB: searchfunc is currenty undocumented and unsupported
92 The input parameters describe a 'package list' option, thus they
93 are returned with the correct converter and validator appended. The
94 result is usable for input to opts.Add() .
96 A 'package list' option may either be 'all', 'none' or a list of
97 package names (seperated by space).
100 (help, '( yes | no | /path/to/%s )' % key),
102 return (key, help, default,
103 lambda k, v, e, f=searchfunc: _validator(k,v,e,f),