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.

254 lines
6.8 KiB

6 years ago
  1. #
  2. # Copyright (c) 2001 - 2017 The SCons Foundation
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  16. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #
  23. """SCons.Warnings
  24. This file implements the warnings framework for SCons.
  25. """
  26. __revision__ = "src/engine/SCons/Warnings.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  27. import sys
  28. import SCons.Errors
  29. class Warning(SCons.Errors.UserError):
  30. pass
  31. class WarningOnByDefault(Warning):
  32. pass
  33. # NOTE: If you add a new warning class, add it to the man page, too!
  34. class TargetNotBuiltWarning(Warning): # Should go to OnByDefault
  35. pass
  36. class CacheVersionWarning(WarningOnByDefault):
  37. pass
  38. class CacheWriteErrorWarning(Warning):
  39. pass
  40. class CorruptSConsignWarning(WarningOnByDefault):
  41. pass
  42. class DependencyWarning(Warning):
  43. pass
  44. class DevelopmentVersionWarning(WarningOnByDefault):
  45. pass
  46. class DuplicateEnvironmentWarning(WarningOnByDefault):
  47. pass
  48. class FutureReservedVariableWarning(WarningOnByDefault):
  49. pass
  50. class LinkWarning(WarningOnByDefault):
  51. pass
  52. class MisleadingKeywordsWarning(WarningOnByDefault):
  53. pass
  54. class MissingSConscriptWarning(WarningOnByDefault):
  55. pass
  56. class NoMD5ModuleWarning(WarningOnByDefault):
  57. pass
  58. class NoMetaclassSupportWarning(WarningOnByDefault):
  59. pass
  60. class NoObjectCountWarning(WarningOnByDefault):
  61. pass
  62. class NoParallelSupportWarning(WarningOnByDefault):
  63. pass
  64. class ReservedVariableWarning(WarningOnByDefault):
  65. pass
  66. class StackSizeWarning(WarningOnByDefault):
  67. pass
  68. class VisualCMissingWarning(WarningOnByDefault):
  69. pass
  70. # Used when MSVC_VERSION and MSVS_VERSION do not point to the
  71. # same version (MSVS_VERSION is deprecated)
  72. class VisualVersionMismatch(WarningOnByDefault):
  73. pass
  74. class VisualStudioMissingWarning(Warning):
  75. pass
  76. class FortranCxxMixWarning(LinkWarning):
  77. pass
  78. # Deprecation warnings
  79. class FutureDeprecatedWarning(Warning):
  80. pass
  81. class DeprecatedWarning(Warning):
  82. pass
  83. class MandatoryDeprecatedWarning(DeprecatedWarning):
  84. pass
  85. # Special case; base always stays DeprecatedWarning
  86. class PythonVersionWarning(DeprecatedWarning):
  87. pass
  88. class DeprecatedSourceCodeWarning(FutureDeprecatedWarning):
  89. pass
  90. class DeprecatedBuildDirWarning(DeprecatedWarning):
  91. pass
  92. class TaskmasterNeedsExecuteWarning(DeprecatedWarning):
  93. pass
  94. class DeprecatedCopyWarning(MandatoryDeprecatedWarning):
  95. pass
  96. class DeprecatedOptionsWarning(MandatoryDeprecatedWarning):
  97. pass
  98. class DeprecatedSourceSignaturesWarning(MandatoryDeprecatedWarning):
  99. pass
  100. class DeprecatedTargetSignaturesWarning(MandatoryDeprecatedWarning):
  101. pass
  102. class DeprecatedDebugOptionsWarning(MandatoryDeprecatedWarning):
  103. pass
  104. class DeprecatedSigModuleWarning(MandatoryDeprecatedWarning):
  105. pass
  106. class DeprecatedBuilderKeywordsWarning(MandatoryDeprecatedWarning):
  107. pass
  108. # The below is a list of 2-tuples. The first element is a class object.
  109. # The second element is true if that class is enabled, false if it is disabled.
  110. _enabled = []
  111. # If set, raise the warning as an exception
  112. _warningAsException = 0
  113. # If not None, a function to call with the warning
  114. _warningOut = None
  115. def suppressWarningClass(clazz):
  116. """Suppresses all warnings that are of type clazz or
  117. derived from clazz."""
  118. _enabled.insert(0, (clazz, 0))
  119. def enableWarningClass(clazz):
  120. """Enables all warnings that are of type clazz or
  121. derived from clazz."""
  122. _enabled.insert(0, (clazz, 1))
  123. def warningAsException(flag=1):
  124. """Turn warnings into exceptions. Returns the old value of the flag."""
  125. global _warningAsException
  126. old = _warningAsException
  127. _warningAsException = flag
  128. return old
  129. def warn(clazz, *args):
  130. global _enabled, _warningAsException, _warningOut
  131. warning = clazz(args)
  132. for clazz, flag in _enabled:
  133. if isinstance(warning, clazz):
  134. if flag:
  135. if _warningAsException:
  136. raise warning
  137. if _warningOut:
  138. _warningOut(warning)
  139. break
  140. def process_warn_strings(arguments):
  141. """Process string specifications of enabling/disabling warnings,
  142. as passed to the --warn option or the SetOption('warn') function.
  143. An argument to this option should be of the form <warning-class>
  144. or no-<warning-class>. The warning class is munged in order
  145. to get an actual class name from the classes above, which we
  146. need to pass to the {enable,disable}WarningClass() functions.
  147. The supplied <warning-class> is split on hyphens, each element
  148. is capitalized, then smushed back together. Then the string
  149. "Warning" is appended to get the class name.
  150. For example, 'deprecated' will enable the DeprecatedWarning
  151. class. 'no-dependency' will disable the DependencyWarning class.
  152. As a special case, --warn=all and --warn=no-all will enable or
  153. disable (respectively) the base Warning class of all warnings.
  154. """
  155. def _capitalize(s):
  156. if s[:5] == "scons":
  157. return "SCons" + s[5:]
  158. else:
  159. return s.capitalize()
  160. for arg in arguments:
  161. elems = arg.lower().split('-')
  162. enable = 1
  163. if elems[0] == 'no':
  164. enable = 0
  165. del elems[0]
  166. if len(elems) == 1 and elems[0] == 'all':
  167. class_name = "Warning"
  168. else:
  169. class_name = ''.join(map(_capitalize, elems)) + "Warning"
  170. try:
  171. clazz = globals()[class_name]
  172. except KeyError:
  173. sys.stderr.write("No warning type: '%s'\n" % arg)
  174. else:
  175. if enable:
  176. enableWarningClass(clazz)
  177. elif issubclass(clazz, MandatoryDeprecatedWarning):
  178. fmt = "Can not disable mandataory warning: '%s'\n"
  179. sys.stderr.write(fmt % arg)
  180. else:
  181. suppressWarningClass(clazz)
  182. # Local Variables:
  183. # tab-width:4
  184. # indent-tabs-mode:nil
  185. # End:
  186. # vim: set expandtab tabstop=4 shiftwidth=4: