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

Source Code for Module SCons.Warnings

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