Package SCons :: Module Warnings
[hide private]
[frames] | no frames]

Source Code for Module SCons.Warnings

  1  # 
  2  # Copyright (c) 2001 - 2014 The SCons 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  2014/07/05 09:42:21 garyo" 
 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 TargetNotBuiltWarning(Warning): # Should go to OnByDefault
46 pass 47
48 -class CacheWriteErrorWarning(Warning):
49 pass
50
51 -class CorruptSConsignWarning(WarningOnByDefault):
52 pass
53
54 -class DependencyWarning(Warning):
55 pass
56
57 -class DuplicateEnvironmentWarning(WarningOnByDefault):
58 pass
59
60 -class FutureReservedVariableWarning(WarningOnByDefault):
61 pass
62
63 -class LinkWarning(WarningOnByDefault):
64 pass
65
66 -class MisleadingKeywordsWarning(WarningOnByDefault):
67 pass
68
69 -class MissingSConscriptWarning(WarningOnByDefault):
70 pass
71
72 -class NoMD5ModuleWarning(WarningOnByDefault):
73 pass
74
75 -class NoMetaclassSupportWarning(WarningOnByDefault):
76 pass
77
78 -class NoObjectCountWarning(WarningOnByDefault):
79 pass
80
81 -class NoParallelSupportWarning(WarningOnByDefault):
82 pass
83
84 -class ReservedVariableWarning(WarningOnByDefault):
85 pass
86
87 -class StackSizeWarning(WarningOnByDefault):
88 pass
89
90 -class VisualCMissingWarning(WarningOnByDefault):
91 pass
92 93 # Used when MSVC_VERSION and MSVS_VERSION do not point to the 94 # same version (MSVS_VERSION is deprecated)
95 -class VisualVersionMismatch(WarningOnByDefault):
96 pass
97
98 -class VisualStudioMissingWarning(Warning):
99 pass
100
101 -class FortranCxxMixWarning(LinkWarning):
102 pass
103 104 105 # Deprecation warnings 106
107 -class FutureDeprecatedWarning(Warning):
108 pass
109
110 -class DeprecatedWarning(Warning):
111 pass
112
113 -class MandatoryDeprecatedWarning(DeprecatedWarning):
114 pass
115 116 117 # Special case; base always stays DeprecatedWarning
118 -class PythonVersionWarning(DeprecatedWarning):
119 pass
120
121 -class DeprecatedSourceCodeWarning(FutureDeprecatedWarning):
122 pass
123
124 -class DeprecatedBuildDirWarning(DeprecatedWarning):
125 pass
126
127 -class TaskmasterNeedsExecuteWarning(DeprecatedWarning):
128 pass
129
130 -class DeprecatedCopyWarning(MandatoryDeprecatedWarning):
131 pass
132
133 -class DeprecatedOptionsWarning(MandatoryDeprecatedWarning):
134 pass
135
136 -class DeprecatedSourceSignaturesWarning(MandatoryDeprecatedWarning):
137 pass
138
139 -class DeprecatedTargetSignaturesWarning(MandatoryDeprecatedWarning):
140 pass
141
142 -class DeprecatedDebugOptionsWarning(MandatoryDeprecatedWarning):
143 pass
144
145 -class DeprecatedSigModuleWarning(MandatoryDeprecatedWarning):
146 pass
147
148 -class DeprecatedBuilderKeywordsWarning(MandatoryDeprecatedWarning):
149 pass
150 151 152 # The below is a list of 2-tuples. The first element is a class object. 153 # The second element is true if that class is enabled, false if it is disabled. 154 _enabled = [] 155 156 # If set, raise the warning as an exception 157 _warningAsException = 0 158 159 # If not None, a function to call with the warning 160 _warningOut = None 161
162 -def suppressWarningClass(clazz):
163 """Suppresses all warnings that are of type clazz or 164 derived from clazz.""" 165 _enabled.insert(0, (clazz, 0))
166
167 -def enableWarningClass(clazz):
168 """Enables all warnings that are of type clazz or 169 derived from clazz.""" 170 _enabled.insert(0, (clazz, 1))
171
172 -def warningAsException(flag=1):
173 """Turn warnings into exceptions. Returns the old value of the flag.""" 174 global _warningAsException 175 old = _warningAsException 176 _warningAsException = flag 177 return old
178
179 -def warn(clazz, *args):
180 global _enabled, _warningAsException, _warningOut 181 182 warning = clazz(args) 183 for clazz, flag in _enabled: 184 if isinstance(warning, clazz): 185 if flag: 186 if _warningAsException: 187 raise warning 188 189 if _warningOut: 190 _warningOut(warning) 191 break
192
193 -def process_warn_strings(arguments):
194 """Process string specifications of enabling/disabling warnings, 195 as passed to the --warn option or the SetOption('warn') function. 196 197 198 An argument to this option should be of the form <warning-class> 199 or no-<warning-class>. The warning class is munged in order 200 to get an actual class name from the classes above, which we 201 need to pass to the {enable,disable}WarningClass() functions. 202 The supplied <warning-class> is split on hyphens, each element 203 is capitalized, then smushed back together. Then the string 204 "Warning" is appended to get the class name. 205 206 For example, 'deprecated' will enable the DeprecatedWarning 207 class. 'no-dependency' will disable the DependencyWarning class. 208 209 As a special case, --warn=all and --warn=no-all will enable or 210 disable (respectively) the base Warning class of all warnings. 211 212 """ 213 214 def _capitalize(s): 215 if s[:5] == "scons": 216 return "SCons" + s[5:] 217 else: 218 return s.capitalize()
219 220 for arg in arguments: 221 222 elems = arg.lower().split('-') 223 enable = 1 224 if elems[0] == 'no': 225 enable = 0 226 del elems[0] 227 228 if len(elems) == 1 and elems[0] == 'all': 229 class_name = "Warning" 230 else: 231 class_name = ''.join(map(_capitalize, elems)) + "Warning" 232 try: 233 clazz = globals()[class_name] 234 except KeyError: 235 sys.stderr.write("No warning type: '%s'\n" % arg) 236 else: 237 if enable: 238 enableWarningClass(clazz) 239 elif issubclass(clazz, MandatoryDeprecatedWarning): 240 fmt = "Can not disable mandataory warning: '%s'\n" 241 sys.stderr.write(fmt % arg) 242 else: 243 suppressWarningClass(clazz) 244 245 # Local Variables: 246 # tab-width:4 247 # indent-tabs-mode:nil 248 # End: 249 # vim: set expandtab tabstop=4 shiftwidth=4: 250