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