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

Source Code for Module SCons.Warnings

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