1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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):
39
40
41
42
45
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
102
105
106 _warningAsException = 0
107
108
109
110 _enabled = []
111
112 _warningOut = None
113
115 """Suppresses all warnings that are of type clazz or
116 derived from clazz."""
117 _enabled.insert(0, (clazz, 0))
118
120 """Suppresses all warnings that are of type clazz or
121 derived from clazz."""
122 _enabled.insert(0, (clazz, 1))
123
130
131 -def warn(clazz, *args):
144
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