You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.5 KiB

6 years ago
  1. """engine.SCons.Variables.PackageVariable
  2. This file defines the option type for SCons implementing 'package
  3. activation'.
  4. To be used whenever a 'package' may be enabled/disabled and the
  5. package path may be specified.
  6. Usage example:
  7. Examples:
  8. x11=no (disables X11 support)
  9. x11=yes (will search for the package installation dir)
  10. x11=/usr/local/X11 (will check this path for existence)
  11. To replace autoconf's --with-xxx=yyy ::
  12. opts = Variables()
  13. opts.Add(PackageVariable('x11',
  14. 'use X11 installed here (yes = search some places',
  15. 'yes'))
  16. ...
  17. if env['x11'] == True:
  18. dir = ... search X11 in some standard places ...
  19. env['x11'] = dir
  20. if env['x11']:
  21. ... build with x11 ...
  22. """
  23. #
  24. # Copyright (c) 2001 - 2017 The SCons Foundation
  25. #
  26. # Permission is hereby granted, free of charge, to any person obtaining
  27. # a copy of this software and associated documentation files (the
  28. # "Software"), to deal in the Software without restriction, including
  29. # without limitation the rights to use, copy, modify, merge, publish,
  30. # distribute, sublicense, and/or sell copies of the Software, and to
  31. # permit persons to whom the Software is furnished to do so, subject to
  32. # the following conditions:
  33. #
  34. # The above copyright notice and this permission notice shall be included
  35. # in all copies or substantial portions of the Software.
  36. #
  37. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  38. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  39. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  40. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  41. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  42. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  43. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  44. #
  45. __revision__ = "src/engine/SCons/Variables/PackageVariable.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  46. __all__ = ['PackageVariable',]
  47. import SCons.Errors
  48. __enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search')
  49. __disable_strings = ('0', 'no', 'false', 'off', 'disable')
  50. def _converter(val):
  51. """
  52. """
  53. lval = val.lower()
  54. if lval in __enable_strings: return True
  55. if lval in __disable_strings: return False
  56. #raise ValueError("Invalid value for boolean option: %s" % val)
  57. return val
  58. def _validator(key, val, env, searchfunc):
  59. # NB: searchfunc is currently undocumented and unsupported
  60. """
  61. """
  62. # TODO write validator, check for path
  63. import os
  64. if env[key] is True:
  65. if searchfunc:
  66. env[key] = searchfunc(key, val)
  67. elif env[key] and not os.path.exists(val):
  68. raise SCons.Errors.UserError(
  69. 'Path does not exist for option %s: %s' % (key, val))
  70. def PackageVariable(key, help, default, searchfunc=None):
  71. # NB: searchfunc is currently undocumented and unsupported
  72. """
  73. The input parameters describe a 'package list' option, thus they
  74. are returned with the correct converter and validator appended. The
  75. result is usable for input to opts.Add() .
  76. A 'package list' option may either be 'all', 'none' or a list of
  77. package names (separated by space).
  78. """
  79. help = '\n '.join(
  80. (help, '( yes | no | /path/to/%s )' % key))
  81. return (key, help, default,
  82. lambda k, v, e: _validator(k,v,e,searchfunc),
  83. _converter)
  84. # Local Variables:
  85. # tab-width:4
  86. # indent-tabs-mode:nil
  87. # End:
  88. # vim: set expandtab tabstop=4 shiftwidth=4: