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__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
37 class Warning(SCons.Errors.UserError):
40 class MandatoryWarning(Warning):
45 class FutureDeprecatedWarning(Warning):
48 class DeprecatedWarning(Warning):
51 class MandatoryDeprecatedWarning(MandatoryWarning):
56 # NOTE: If you add a new warning class, add it to the man page, too!
58 class CacheWriteErrorWarning(Warning):
61 class CorruptSConsignWarning(Warning):
64 class DependencyWarning(Warning):
67 class DeprecatedCopyWarning(DeprecatedWarning):
70 class DeprecatedOptionsWarning(DeprecatedWarning):
73 class DeprecatedSourceSignaturesWarning(DeprecatedWarning):
76 class DeprecatedTargetSignaturesWarning(DeprecatedWarning):
79 class DuplicateEnvironmentWarning(Warning):
82 class FutureReservedVariableWarning(Warning):
85 class LinkWarning(Warning):
88 class MisleadingKeywordsWarning(Warning):
91 class MissingSConscriptWarning(Warning):
94 class NoMD5ModuleWarning(Warning):
97 class NoMetaclassSupportWarning(Warning):
100 class NoObjectCountWarning(Warning):
103 class NoParallelSupportWarning(Warning):
106 class PythonVersionWarning(DeprecatedWarning):
109 class ReservedVariableWarning(Warning):
112 class StackSizeWarning(Warning):
115 class TaskmasterNeedsExecuteWarning(FutureDeprecatedWarning):
118 class FortranCxxMixWarning(LinkWarning):
121 _warningAsException = 0
123 # The below is a list of 2-tuples. The first element is a class object.
124 # The second element is true if that class is enabled, false if it is disabled.
129 def suppressWarningClass(clazz):
130 """Suppresses all warnings that are of type clazz or
131 derived from clazz."""
132 _enabled.insert(0, (clazz, 0))
134 def enableWarningClass(clazz):
135 """Suppresses all warnings that are of type clazz or
136 derived from clazz."""
137 _enabled.insert(0, (clazz, 1))
139 def warningAsException(flag=1):
140 """Turn warnings into exceptions. Returns the old value of the flag."""
141 global _warningAsException
142 old = _warningAsException
143 _warningAsException = flag
146 def warn(clazz, *args):
147 global _enabled, _warningAsException, _warningOut
149 warning = clazz(args)
150 for clazz, flag in _enabled:
151 if isinstance(warning, clazz):
153 if _warningAsException:
160 def process_warn_strings(arguments):
161 """Process string specifications of enabling/disabling warnings,
162 as passed to the --warn option or the SetOption('warn') function.
165 An argument to this option should be of the form <warning-class>
166 or no-<warning-class>. The warning class is munged in order
167 to get an actual class name from the classes above, which we
168 need to pass to the {enable,disable}WarningClass() functions.
169 The supplied <warning-class> is split on hyphens, each element
170 is capitalized, then smushed back together. Then the string
171 "Warning" is appended to get the class name.
173 For example, 'deprecated' will enable the DeprecatedWarning
174 class. 'no-dependency' will disable the .DependencyWarning
177 As a special case, --warn=all and --warn=no-all will enable or
178 disable (respectively) the base Warning class of all warnings.
184 return "SCons" + s[5:]
186 return string.capitalize(s)
188 for arg in arguments:
190 elems = string.split(string.lower(arg), '-')
196 if len(elems) == 1 and elems[0] == 'all':
197 class_name = "Warning"
199 class_name = string.join(map(_capitalize, elems), '') + "Warning"
201 clazz = globals()[class_name]
203 sys.stderr.write("No warning type: '%s'\n" % arg)
206 enableWarningClass(clazz)
207 elif issubclass(clazz, MandatoryDeprecatedWarning):
208 fmt = "Can not disable mandataory warning: '%s'\n"
209 sys.stderr.write(fmt % arg)
211 suppressWarningClass(clazz)
215 # indent-tabs-mode:nil
217 # vim: set expandtab tabstop=4 shiftwidth=4: