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