2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
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:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
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.
26 This file implements the warnings framework for SCons.
30 __revision__ = "src/engine/SCons/Warnings.py 3842 2008/12/20 22:59:52 scons"
37 class Warning(SCons.Errors.UserError):
41 # NOTE: If you add a new warning class, add it to the man page, too!
43 class CacheWriteErrorWarning(Warning):
46 class CorruptSConsignWarning(Warning):
49 class DependencyWarning(Warning):
52 class DeprecatedWarning(Warning):
55 class DeprecatedCopyWarning(DeprecatedWarning):
58 class DeprecatedOptionsWarning(DeprecatedWarning):
61 class DeprecatedSourceSignaturesWarning(DeprecatedWarning):
64 class DeprecatedTargetSignaturesWarning(DeprecatedWarning):
67 class DuplicateEnvironmentWarning(Warning):
70 class FutureReservedVariableWarning(Warning):
73 class LinkWarning(Warning):
76 class MisleadingKeywordsWarning(Warning):
79 class MissingSConscriptWarning(Warning):
82 class NoMD5ModuleWarning(Warning):
85 class NoMetaclassSupportWarning(Warning):
88 class NoObjectCountWarning(Warning):
91 class NoParallelSupportWarning(Warning):
94 class PythonVersionWarning(DeprecatedWarning):
97 class ReservedVariableWarning(Warning):
100 class StackSizeWarning(Warning):
103 class FortranCxxMixWarning(LinkWarning):
106 _warningAsException = 0
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.
114 def suppressWarningClass(clazz):
115 """Suppresses all warnings that are of type clazz or
116 derived from clazz."""
117 _enabled.insert(0, (clazz, 0))
119 def enableWarningClass(clazz):
120 """Suppresses all warnings that are of type clazz or
121 derived from clazz."""
122 _enabled.insert(0, (clazz, 1))
124 def warningAsException(flag=1):
125 """Turn warnings into exceptions. Returns the old value of the flag."""
126 global _warningAsException
127 old = _warningAsException
128 _warningAsException = flag
131 def warn(clazz, *args):
132 global _enabled, _warningAsException, _warningOut
134 warning = clazz(args)
135 for clazz, flag in _enabled:
136 if isinstance(warning, clazz):
138 if _warningAsException:
145 def process_warn_strings(arguments):
146 """Process string specifications of enabling/disabling warnings,
147 as passed to the --warn option or the SetOption('warn') function.
150 An argument to this option should be of the form <warning-class>
151 or no-<warning-class>. The warning class is munged in order
152 to get an actual class name from the classes above, which we
153 need to pass to the {enable,disable}WarningClass() functions.
154 The supplied <warning-class> is split on hyphens, each element
155 is capitalized, then smushed back together. Then the string
156 "Warning" is appended to get the class name.
158 For example, 'deprecated' will enable the DeprecatedWarning
159 class. 'no-dependency' will disable the .DependencyWarning
162 As a special case, --warn=all and --warn=no-all will enable or
163 disable (respectively) the base Warning class of all warnings.
169 return "SCons" + s[5:]
171 return string.capitalize(s)
173 for arg in arguments:
175 elems = string.split(string.lower(arg), '-')
181 if len(elems) == 1 and elems[0] == 'all':
182 class_name = "Warning"
184 class_name = string.join(map(_capitalize, elems), '') + "Warning"
186 clazz = globals()[class_name]
188 sys.stderr.write("No warning type: '%s'\n" % arg)
191 enableWarningClass(clazz)
193 suppressWarningClass(clazz)