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 bee7caf9defd6e108fc2998a2520ddb36a967691 2019-12-17 02:07:09 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 TaskmasterNeedsExecuteWarning(DeprecatedWarning):
124 pass
125
126 -class DeprecatedOptionsWarning(MandatoryDeprecatedWarning):
127 pass
128
129 -class DeprecatedDebugOptionsWarning(MandatoryDeprecatedWarning):
130 pass
131
132 -class DeprecatedMissingSConscriptWarning(DeprecatedWarning):
133 pass
134 135 136 # The below is a list of 2-tuples. The first element is a class object. 137 # The second element is true if that class is enabled, false if it is disabled. 138 _enabled = [] 139 140 # If set, raise the warning as an exception 141 _warningAsException = 0 142 143 # If not None, a function to call with the warning 144 _warningOut = None 145
146 -def suppressWarningClass(clazz):
147 """Suppresses all warnings that are of type clazz or 148 derived from clazz.""" 149 _enabled.insert(0, (clazz, 0))
150
151 -def enableWarningClass(clazz):
152 """Enables all warnings that are of type clazz or 153 derived from clazz.""" 154 _enabled.insert(0, (clazz, 1))
155
156 -def warningAsException(flag=1):
157 """Turn warnings into exceptions. Returns the old value of the flag.""" 158 global _warningAsException 159 old = _warningAsException 160 _warningAsException = flag 161 return old
162
163 -def warn(clazz, *args):
164 global _enabled, _warningAsException, _warningOut 165 166 warning = clazz(args) 167 for cls, flag in _enabled: 168 if isinstance(warning, cls): 169 if flag: 170 if _warningAsException: 171 raise warning 172 173 if _warningOut: 174 _warningOut(warning) 175 break
176
177 -def process_warn_strings(arguments):
178 """Process requests to enable/disable warnings. 179 180 The requests are strings passed to the --warn option or the 181 SetOption('warn') function. 182 183 An argument to this option should be of the form <warning-class> 184 or no-<warning-class>. The warning class is munged in order 185 to get an actual class name from the classes above, which we 186 need to pass to the {enable,disable}WarningClass() functions. 187 The supplied <warning-class> is split on hyphens, each element 188 is capitalized, then smushed back together. Then the string 189 "Warning" is appended to get the class name. 190 191 For example, 'deprecated' will enable the DeprecatedWarning 192 class. 'no-dependency' will disable the DependencyWarning class. 193 194 As a special case, --warn=all and --warn=no-all will enable or 195 disable (respectively) the base Warning class of all warnings. 196 """ 197 198 def _capitalize(s): 199 if s[:5] == "scons": 200 return "SCons" + s[5:] 201 else: 202 return s.capitalize()
203 204 for arg in arguments: 205 206 elems = arg.lower().split('-') 207 enable = 1 208 if elems[0] == 'no': 209 enable = 0 210 del elems[0] 211 212 if len(elems) == 1 and elems[0] == 'all': 213 class_name = "Warning" 214 else: 215 class_name = ''.join(map(_capitalize, elems)) + "Warning" 216 try: 217 clazz = globals()[class_name] 218 except KeyError: 219 sys.stderr.write("No warning type: '%s'\n" % arg) 220 else: 221 if enable: 222 enableWarningClass(clazz) 223 elif issubclass(clazz, MandatoryDeprecatedWarning): 224 fmt = "Can not disable mandataory warning: '%s'\n" 225 sys.stderr.write(fmt % arg) 226 else: 227 suppressWarningClass(clazz) 228 229 # Local Variables: 230 # tab-width:4 231 # indent-tabs-mode:nil 232 # End: 233 # vim: set expandtab tabstop=4 shiftwidth=4: 234