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

Source Code for Module SCons.Warnings

  1  # 
  2  # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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 2928 2008/04/29 22:44:09 knight" 
 31   
 32  import string 
 33  import sys 
 34   
 35  import SCons.Errors 
 36   
37 -class Warning(SCons.Errors.UserError):
38 pass
39 40 41 # NOTE: If you add a new warning class, add it to the man page, too! 42
43 -class CacheWriteErrorWarning(Warning):
44 pass
45
46 -class CorruptSConsignWarning(Warning):
47 pass
48
49 -class DependencyWarning(Warning):
50 pass
51
52 -class DeprecatedWarning(Warning):
53 pass
54
55 -class DeprecatedCopyWarning(DeprecatedWarning):
56 pass
57
58 -class DeprecatedSourceSignaturesWarning(DeprecatedWarning):
59 pass
60
61 -class DeprecatedTargetSignaturesWarning(DeprecatedWarning):
62 pass
63
64 -class DuplicateEnvironmentWarning(Warning):
65 pass
66
67 -class MisleadingKeywordsWarning(Warning):
68 pass
69
70 -class MissingSConscriptWarning(Warning):
71 pass
72
73 -class NoMD5ModuleWarning(Warning):
74 pass
75
76 -class NoMetaclassSupportWarning(Warning):
77 pass
78
79 -class NoObjectCountWarning(Warning):
80 pass
81
82 -class NoParallelSupportWarning(Warning):
83 pass
84
85 -class PythonVersionWarning(DeprecatedWarning):
86 pass
87
88 -class ReservedVariableWarning(Warning):
89 pass
90
91 -class StackSizeWarning(Warning):
92 pass
93 94 _warningAsException = 0 95 96 # The below is a list of 2-tuples. The first element is a class object. 97 # The second element is true if that class is enabled, false if it is disabled. 98 _enabled = [] 99 100 _warningOut = None 101
102 -def suppressWarningClass(clazz):
103 """Suppresses all warnings that are of type clazz or 104 derived from clazz.""" 105 _enabled.insert(0, (clazz, 0))
106
107 -def enableWarningClass(clazz):
108 """Suppresses all warnings that are of type clazz or 109 derived from clazz.""" 110 _enabled.insert(0, (clazz, 1))
111
112 -def warningAsException(flag=1):
113 """Turn warnings into exceptions. Returns the old value of the flag.""" 114 global _warningAsException 115 old = _warningAsException 116 _warningAsException = flag 117 return old
118
119 -def warn(clazz, *args):
120 global _enabled, _warningAsException, _warningOut 121 122 warning = clazz(args) 123 for clazz, flag in _enabled: 124 if isinstance(warning, clazz): 125 if flag: 126 if _warningAsException: 127 raise warning 128 129 if _warningOut: 130 _warningOut(warning) 131 break
132
133 -def process_warn_strings(arguments):
134 """Process string specifications of enabling/disabling warnings, 135 as passed to the --warn option or the SetOption('warn') function. 136 137 138 An argument to this option should be of the form <warning-class> 139 or no-<warning-class>. The warning class is munged in order 140 to get an actual class name from the classes above, which we 141 need to pass to the {enable,disable}WarningClass() functions. 142 The supplied <warning-class> is split on hyphens, each element 143 is capitalized, then smushed back together. Then the string 144 "Warning" is appended to get the class name. 145 146 For example, 'deprecated' will enable the DeprecatedWarning 147 class. 'no-dependency' will disable the .DependencyWarning 148 class. 149 150 As a special case, --warn=all and --warn=no-all will enable or 151 disable (respectively) the base Warning class of all warnings. 152 153 """ 154 155 def _capitalize(s): 156 if s[:5] == "scons": 157 return "SCons" + s[5:] 158 else: 159 return string.capitalize(s)
160 161 for arg in arguments: 162 163 elems = string.split(string.lower(arg), '-') 164 enable = 1 165 if elems[0] == 'no': 166 enable = 0 167 del elems[0] 168 169 if len(elems) == 1 and elems[0] == 'all': 170 class_name = "Warning" 171 else: 172 class_name = string.join(map(_capitalize, elems), '') + "Warning" 173 try: 174 clazz = globals()[class_name] 175 except KeyError: 176 sys.stderr.write("No warning type: '%s'\n" % arg) 177 else: 178 if enable: 179 enableWarningClass(clazz) 180 else: 181 suppressWarningClass(clazz) 182