OLD | NEW |
(Empty) | |
| 1 # |
| 2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S
Cons 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 |
| 24 """SCons.Warnings |
| 25 |
| 26 This file implements the warnings framework for SCons. |
| 27 |
| 28 """ |
| 29 |
| 30 __revision__ = "src/engine/SCons/Warnings.py 5134 2010/08/16 23:02:40 bdeegan" |
| 31 |
| 32 import sys |
| 33 |
| 34 import SCons.Errors |
| 35 |
| 36 class Warning(SCons.Errors.UserError): |
| 37 pass |
| 38 |
| 39 class WarningOnByDefault(Warning): |
| 40 pass |
| 41 |
| 42 |
| 43 # NOTE: If you add a new warning class, add it to the man page, too! |
| 44 |
| 45 class CacheWriteErrorWarning(Warning): |
| 46 pass |
| 47 |
| 48 class CorruptSConsignWarning(WarningOnByDefault): |
| 49 pass |
| 50 |
| 51 class DependencyWarning(Warning): |
| 52 pass |
| 53 |
| 54 class DuplicateEnvironmentWarning(WarningOnByDefault): |
| 55 pass |
| 56 |
| 57 class FutureReservedVariableWarning(WarningOnByDefault): |
| 58 pass |
| 59 |
| 60 class LinkWarning(WarningOnByDefault): |
| 61 pass |
| 62 |
| 63 class MisleadingKeywordsWarning(WarningOnByDefault): |
| 64 pass |
| 65 |
| 66 class MissingSConscriptWarning(WarningOnByDefault): |
| 67 pass |
| 68 |
| 69 class NoMD5ModuleWarning(WarningOnByDefault): |
| 70 pass |
| 71 |
| 72 class NoMetaclassSupportWarning(WarningOnByDefault): |
| 73 pass |
| 74 |
| 75 class NoObjectCountWarning(WarningOnByDefault): |
| 76 pass |
| 77 |
| 78 class NoParallelSupportWarning(WarningOnByDefault): |
| 79 pass |
| 80 |
| 81 class ReservedVariableWarning(WarningOnByDefault): |
| 82 pass |
| 83 |
| 84 class StackSizeWarning(WarningOnByDefault): |
| 85 pass |
| 86 |
| 87 class VisualCMissingWarning(WarningOnByDefault): |
| 88 pass |
| 89 |
| 90 # Used when MSVC_VERSION and MSVS_VERSION do not point to the |
| 91 # same version (MSVS_VERSION is deprecated) |
| 92 class VisualVersionMismatch(WarningOnByDefault): |
| 93 pass |
| 94 |
| 95 class VisualStudioMissingWarning(Warning): |
| 96 pass |
| 97 |
| 98 class FortranCxxMixWarning(LinkWarning): |
| 99 pass |
| 100 |
| 101 |
| 102 # Deprecation warnings |
| 103 |
| 104 class FutureDeprecatedWarning(Warning): |
| 105 pass |
| 106 |
| 107 class DeprecatedWarning(Warning): |
| 108 pass |
| 109 |
| 110 class MandatoryDeprecatedWarning(DeprecatedWarning): |
| 111 pass |
| 112 |
| 113 |
| 114 # Special case; base always stays DeprecatedWarning |
| 115 class PythonVersionWarning(DeprecatedWarning): |
| 116 pass |
| 117 |
| 118 class DeprecatedSourceCodeWarning(FutureDeprecatedWarning): |
| 119 pass |
| 120 |
| 121 class DeprecatedBuildDirWarning(DeprecatedWarning): |
| 122 pass |
| 123 |
| 124 class TaskmasterNeedsExecuteWarning(DeprecatedWarning): |
| 125 pass |
| 126 |
| 127 class DeprecatedCopyWarning(MandatoryDeprecatedWarning): |
| 128 pass |
| 129 |
| 130 class DeprecatedOptionsWarning(MandatoryDeprecatedWarning): |
| 131 pass |
| 132 |
| 133 class DeprecatedSourceSignaturesWarning(MandatoryDeprecatedWarning): |
| 134 pass |
| 135 |
| 136 class DeprecatedTargetSignaturesWarning(MandatoryDeprecatedWarning): |
| 137 pass |
| 138 |
| 139 class DeprecatedDebugOptionsWarning(MandatoryDeprecatedWarning): |
| 140 pass |
| 141 |
| 142 class DeprecatedSigModuleWarning(MandatoryDeprecatedWarning): |
| 143 pass |
| 144 |
| 145 class DeprecatedBuilderKeywordsWarning(MandatoryDeprecatedWarning): |
| 146 pass |
| 147 |
| 148 |
| 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. |
| 151 _enabled = [] |
| 152 |
| 153 # If set, raise the warning as an exception |
| 154 _warningAsException = 0 |
| 155 |
| 156 # If not None, a function to call with the warning |
| 157 _warningOut = None |
| 158 |
| 159 def suppressWarningClass(clazz): |
| 160 """Suppresses all warnings that are of type clazz or |
| 161 derived from clazz.""" |
| 162 _enabled.insert(0, (clazz, 0)) |
| 163 |
| 164 def enableWarningClass(clazz): |
| 165 """Enables all warnings that are of type clazz or |
| 166 derived from clazz.""" |
| 167 _enabled.insert(0, (clazz, 1)) |
| 168 |
| 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 |
| 174 return old |
| 175 |
| 176 def warn(clazz, *args): |
| 177 global _enabled, _warningAsException, _warningOut |
| 178 |
| 179 warning = clazz(args) |
| 180 for clazz, flag in _enabled: |
| 181 if isinstance(warning, clazz): |
| 182 if flag: |
| 183 if _warningAsException: |
| 184 raise warning |
| 185 |
| 186 if _warningOut: |
| 187 _warningOut(warning) |
| 188 break |
| 189 |
| 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. |
| 193 |
| 194 |
| 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. |
| 202 |
| 203 For example, 'deprecated' will enable the DeprecatedWarning |
| 204 class. 'no-dependency' will disable the DependencyWarning class. |
| 205 |
| 206 As a special case, --warn=all and --warn=no-all will enable or |
| 207 disable (respectively) the base Warning class of all warnings. |
| 208 |
| 209 """ |
| 210 |
| 211 def _capitalize(s): |
| 212 if s[:5] == "scons": |
| 213 return "SCons" + s[5:] |
| 214 else: |
| 215 return s.capitalize() |
| 216 |
| 217 for arg in arguments: |
| 218 |
| 219 elems = arg.lower().split('-') |
| 220 enable = 1 |
| 221 if elems[0] == 'no': |
| 222 enable = 0 |
| 223 del elems[0] |
| 224 |
| 225 if len(elems) == 1 and elems[0] == 'all': |
| 226 class_name = "Warning" |
| 227 else: |
| 228 class_name = ''.join(map(_capitalize, elems)) + "Warning" |
| 229 try: |
| 230 clazz = globals()[class_name] |
| 231 except KeyError: |
| 232 sys.stderr.write("No warning type: '%s'\n" % arg) |
| 233 else: |
| 234 if enable: |
| 235 enableWarningClass(clazz) |
| 236 elif issubclass(clazz, MandatoryDeprecatedWarning): |
| 237 fmt = "Can not disable mandataory warning: '%s'\n" |
| 238 sys.stderr.write(fmt % arg) |
| 239 else: |
| 240 suppressWarningClass(clazz) |
| 241 |
| 242 # Local Variables: |
| 243 # tab-width:4 |
| 244 # indent-tabs-mode:nil |
| 245 # End: |
| 246 # vim: set expandtab tabstop=4 shiftwidth=4: |
OLD | NEW |