2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 5023 2010/06/14 22:05:46 scons"
36 class Warning(SCons.Errors.UserError):
39 class WarningOnByDefault(Warning):
43 # NOTE: If you add a new warning class, add it to the man page, too!
45 class CacheWriteErrorWarning(Warning):
48 class CorruptSConsignWarning(WarningOnByDefault):
51 class DependencyWarning(Warning):
54 class DuplicateEnvironmentWarning(WarningOnByDefault):
57 class FutureReservedVariableWarning(WarningOnByDefault):
60 class LinkWarning(WarningOnByDefault):
63 class MisleadingKeywordsWarning(WarningOnByDefault):
66 class MissingSConscriptWarning(WarningOnByDefault):
69 class NoMD5ModuleWarning(WarningOnByDefault):
72 class NoMetaclassSupportWarning(WarningOnByDefault):
75 class NoObjectCountWarning(WarningOnByDefault):
78 class NoParallelSupportWarning(WarningOnByDefault):
81 class ReservedVariableWarning(WarningOnByDefault):
84 class StackSizeWarning(WarningOnByDefault):
87 class VisualCMissingWarning(WarningOnByDefault):
90 # Used when MSVC_VERSION and MSVS_VERSION do not point to the
91 # same version (MSVS_VERSION is deprecated)
92 class VisualVersionMismatch(WarningOnByDefault):
95 class VisualStudioMissingWarning(Warning):
98 class FortranCxxMixWarning(LinkWarning):
102 # Deprecation warnings
104 class FutureDeprecatedWarning(Warning):
107 class DeprecatedWarning(Warning):
110 class MandatoryDeprecatedWarning(DeprecatedWarning):
114 # Special case; base always stays DeprecatedWarning
115 class PythonVersionWarning(DeprecatedWarning):
118 class DeprecatedSourceCodeWarning(FutureDeprecatedWarning):
121 class DeprecatedBuildDirWarning(DeprecatedWarning):
124 class TaskmasterNeedsExecuteWarning(DeprecatedWarning):
127 class DeprecatedCopyWarning(MandatoryDeprecatedWarning):
130 class DeprecatedOptionsWarning(MandatoryDeprecatedWarning):
133 class DeprecatedSourceSignaturesWarning(MandatoryDeprecatedWarning):
136 class DeprecatedTargetSignaturesWarning(MandatoryDeprecatedWarning):
139 class DeprecatedDebugOptionsWarning(MandatoryDeprecatedWarning):
142 class DeprecatedSigModuleWarning(MandatoryDeprecatedWarning):
145 class DeprecatedBuilderKeywordsWarning(MandatoryDeprecatedWarning):
149 # The below is a list of 2-tuples. The first element is a class object.
150 # The second element is true if that class is enabled, false if it is disabled.
153 # If set, raise the warning as an exception
154 _warningAsException = 0
156 # If not None, a function to call with the warning
159 def suppressWarningClass(clazz):
160 """Suppresses all warnings that are of type clazz or
161 derived from clazz."""
162 _enabled.insert(0, (clazz, 0))
164 def enableWarningClass(clazz):
165 """Enables all warnings that are of type clazz or
166 derived from clazz."""
167 _enabled.insert(0, (clazz, 1))
169 def warningAsException(flag=1):
170 """Turn warnings into exceptions. Returns the old value of the flag."""
171 global _warningAsException
172 old = _warningAsException
173 _warningAsException = flag
176 def warn(clazz, *args):
177 global _enabled, _warningAsException, _warningOut
179 warning = clazz(args)
180 for clazz, flag in _enabled:
181 if isinstance(warning, clazz):
183 if _warningAsException:
190 def process_warn_strings(arguments):
191 """Process string specifications of enabling/disabling warnings,
192 as passed to the --warn option or the SetOption('warn') function.
195 An argument to this option should be of the form <warning-class>
196 or no-<warning-class>. The warning class is munged in order
197 to get an actual class name from the classes above, which we
198 need to pass to the {enable,disable}WarningClass() functions.
199 The supplied <warning-class> is split on hyphens, each element
200 is capitalized, then smushed back together. Then the string
201 "Warning" is appended to get the class name.
203 For example, 'deprecated' will enable the DeprecatedWarning
204 class. 'no-dependency' will disable the DependencyWarning class.
206 As a special case, --warn=all and --warn=no-all will enable or
207 disable (respectively) the base Warning class of all warnings.
213 return "SCons" + s[5:]
215 return s.capitalize()
217 for arg in arguments:
219 elems = arg.lower().split('-')
225 if len(elems) == 1 and elems[0] == 'all':
226 class_name = "Warning"
228 class_name = ''.join(map(_capitalize, elems)) + "Warning"
230 clazz = globals()[class_name]
232 sys.stderr.write("No warning type: '%s'\n" % arg)
235 enableWarningClass(clazz)
236 elif issubclass(clazz, MandatoryDeprecatedWarning):
237 fmt = "Can not disable mandataory warning: '%s'\n"
238 sys.stderr.write(fmt % arg)
240 suppressWarningClass(clazz)
244 # indent-tabs-mode:nil
246 # vim: set expandtab tabstop=4 shiftwidth=4: