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 VisualCMissingWarning(Warning):
121 # Used when MSVC_VERSION and MSVS_VERSION do not point to the
122 # same version (MSVS_VERSION is deprecated)
123 class VisualVersionMismatch(Warning):
126 class VisualStudioMissingWarning(Warning):
129 class FortranCxxMixWarning(LinkWarning):
132 _warningAsException = 0
134 # The below is a list of 2-tuples. The first element is a class object.
135 # The second element is true if that class is enabled, false if it is disabled.
140 def suppressWarningClass(clazz):
141 """Suppresses all warnings that are of type clazz or
142 derived from clazz."""
143 _enabled.insert(0, (clazz, 0))
145 def enableWarningClass(clazz):
146 """Suppresses all warnings that are of type clazz or
147 derived from clazz."""
148 _enabled.insert(0, (clazz, 1))
150 def warningAsException(flag=1):
151 """Turn warnings into exceptions. Returns the old value of the flag."""
152 global _warningAsException
153 old = _warningAsException
154 _warningAsException = flag
157 def warn(clazz, *args):
158 global _enabled, _warningAsException, _warningOut
160 warning = clazz(args)
161 for clazz, flag in _enabled:
162 if isinstance(warning, clazz):
164 if _warningAsException:
171 def process_warn_strings(arguments):
172 """Process string specifications of enabling/disabling warnings,
173 as passed to the --warn option or the SetOption('warn') function.
176 An argument to this option should be of the form <warning-class>
177 or no-<warning-class>. The warning class is munged in order
178 to get an actual class name from the classes above, which we
179 need to pass to the {enable,disable}WarningClass() functions.
180 The supplied <warning-class> is split on hyphens, each element
181 is capitalized, then smushed back together. Then the string
182 "Warning" is appended to get the class name.
184 For example, 'deprecated' will enable the DeprecatedWarning
185 class. 'no-dependency' will disable the .DependencyWarning
188 As a special case, --warn=all and --warn=no-all will enable or
189 disable (respectively) the base Warning class of all warnings.
195 return "SCons" + s[5:]
197 return string.capitalize(s)
199 for arg in arguments:
201 elems = string.split(string.lower(arg), '-')
207 if len(elems) == 1 and elems[0] == 'all':
208 class_name = "Warning"
210 class_name = string.join(map(_capitalize, elems), '') + "Warning"
212 clazz = globals()[class_name]
214 sys.stderr.write("No warning type: '%s'\n" % arg)
217 enableWarningClass(clazz)
218 elif issubclass(clazz, MandatoryDeprecatedWarning):
219 fmt = "Can not disable mandataory warning: '%s'\n"
220 sys.stderr.write(fmt % arg)
222 suppressWarningClass(clazz)
226 # indent-tabs-mode:nil
228 # vim: set expandtab tabstop=4 shiftwidth=4: