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

Source Code for Module SCons.Warnings

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