Add new Options flavors. (Hartmut Goebel)
[scons.git] / src / engine / SCons / Options / PathOption.py
1 """engine.SCons.Options.PathOption
2
3 This file defines an option type for SCons implementing 'package
4 activation'.
5
6 To be used whenever a 'package' may be enabled/disabled and the
7 package path may be specified.
8
9 Usage example:
10
11   Examples:
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)
15
16   To replace autoconf's --with-xxx=yyy 
17
18   opts = Options()
19
20   opts = Options()
21   opts.Add(PathOption('qtdir',
22                       'where the root of Qt is installed',
23                       qtdir))
24   opts.Add(PathOption('qt_includes',
25                       'where the Qt includes are installed',
26                       '$qtdir/includes'))
27   opts.Add(PathOption('qt_libraries',
28                       'where the Qt library is installed',
29                       '$qtdir/lib'))
30
31 """
32
33 #
34 # __COPYRIGHT__
35 #
36 # Permission is hereby granted, free of charge, to any person obtaining
37 # a copy of this software and associated documentation files (the
38 # "Software"), to deal in the Software without restriction, including
39 # without limitation the rights to use, copy, modify, merge, publish,
40 # distribute, sublicense, and/or sell copies of the Software, and to
41 # permit persons to whom the Software is furnished to do so, subject to
42 # the following conditions:
43 #
44 # The above copyright notice and this permission notice shall be included
45 # in all copies or substantial portions of the Software.
46 #
47 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
48 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
49 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54 #
55
56 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
57
58 __all__ = ('PathOption',)
59
60 import os
61
62 import SCons.Errors
63
64 def _validator(key, val, env):
65     """
66     """
67     # todo: write validator, check for path
68     if not os.path.exists(val):
69         raise SCons.Errors.UserError(
70             'Path does not exist for option %s: %s' % (key, val))
71
72
73 def PathOption(key, help, default):
74     # NB: searchfunc is currenty undocumented and unsupported
75     """
76     The input parameters describe a 'path list' option, thus they
77     are returned with the correct converter and validator appended. The
78     result is usable for input to opts.Add() .
79
80     A 'package list' option may either be 'all', 'none' or a list of
81     package names (seperated by space).
82     """
83     return (key, '%s ( /path/to/%s )' % (help, key), default,
84             _validator, None)
85