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 5110 2010/07/25 16:14:38 bdeegan"
31
32 import string
33 import sys
34
35 import SCons.Errors
36
37 -class Warning(SCons.Errors.UserError):
39
42
43
44
47
50
53
54
55
56
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
102
105
108
111
114
117
120
121
122
125
128
131
132 _warningAsException = 0
133
134
135
136 _enabled = []
137
138 _warningOut = None
139
141 """Suppresses all warnings that are of type clazz or
142 derived from clazz."""
143 _enabled.insert(0, (clazz, 0))
144
146 """Suppresses all warnings that are of type clazz or
147 derived from clazz."""
148 _enabled.insert(0, (clazz, 1))
149
156
157 -def warn(clazz, *args):
170
172 """Process string specifications of enabling/disabling warnings,
173 as passed to the --warn option or the SetOption('warn') function.
174
175
176 An argument to this option should be of the form <warning-class>
177 or no-<warning-class>. The warning class is munged in order
178 to get an actual class name from the classes above, which we
179 need to pass to the {enable,disable}WarningClass() functions.
180 The supplied <warning-class> is split on hyphens, each element
181 is capitalized, then smushed back together. Then the string
182 "Warning" is appended to get the class name.
183
184 For example, 'deprecated' will enable the DeprecatedWarning
185 class. 'no-dependency' will disable the .DependencyWarning
186 class.
187
188 As a special case, --warn=all and --warn=no-all will enable or
189 disable (respectively) the base Warning class of all warnings.
190
191 """
192
193 def _capitalize(s):
194 if s[:5] == "scons":
195 return "SCons" + s[5:]
196 else:
197 return string.capitalize(s)
198
199 for arg in arguments:
200
201 elems = string.split(string.lower(arg), '-')
202 enable = 1
203 if elems[0] == 'no':
204 enable = 0
205 del elems[0]
206
207 if len(elems) == 1 and elems[0] == 'all':
208 class_name = "Warning"
209 else:
210 class_name = string.join(map(_capitalize, elems), '') + "Warning"
211 try:
212 clazz = globals()[class_name]
213 except KeyError:
214 sys.stderr.write("No warning type: '%s'\n" % arg)
215 else:
216 if enable:
217 enableWarningClass(clazz)
218 elif issubclass(clazz, MandatoryDeprecatedWarning):
219 fmt = "Can not disable mandataory warning: '%s'\n"
220 sys.stderr.write(fmt % arg)
221 else:
222 suppressWarningClass(clazz)
223
224
225
226
227
228
229