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 5023 2010/06/14 22:05:46 scons"
31
32 import sys
33
34 import SCons.Errors
35
36 -class Warning(SCons.Errors.UserError):
38
41
42
43
44
47
50
53
56
59
62
65
68
71
74
77
80
83
86
89
90
91
94
97
100
101
102
103
106
109
112
113
114
117
120
123
126
129
132
135
138
141
144
147
148
149
150
151 _enabled = []
152
153
154 _warningAsException = 0
155
156
157 _warningOut = None
158
160 """Suppresses all warnings that are of type clazz or
161 derived from clazz."""
162 _enabled.insert(0, (clazz, 0))
163
165 """Enables all warnings that are of type clazz or
166 derived from clazz."""
167 _enabled.insert(0, (clazz, 1))
168
175
176 -def warn(clazz, *args):
189
191 """Process string specifications of enabling/disabling warnings,
192 as passed to the --warn option or the SetOption('warn') function.
193
194
195 An argument to this option should be of the form <warning-class>
196 or no-<warning-class>. The warning class is munged in order
197 to get an actual class name from the classes above, which we
198 need to pass to the {enable,disable}WarningClass() functions.
199 The supplied <warning-class> is split on hyphens, each element
200 is capitalized, then smushed back together. Then the string
201 "Warning" is appended to get the class name.
202
203 For example, 'deprecated' will enable the DeprecatedWarning
204 class. 'no-dependency' will disable the DependencyWarning class.
205
206 As a special case, --warn=all and --warn=no-all will enable or
207 disable (respectively) the base Warning class of all warnings.
208
209 """
210
211 def _capitalize(s):
212 if s[:5] == "scons":
213 return "SCons" + s[5:]
214 else:
215 return s.capitalize()
216
217 for arg in arguments:
218
219 elems = arg.lower().split('-')
220 enable = 1
221 if elems[0] == 'no':
222 enable = 0
223 del elems[0]
224
225 if len(elems) == 1 and elems[0] == 'all':
226 class_name = "Warning"
227 else:
228 class_name = ''.join(map(_capitalize, elems)) + "Warning"
229 try:
230 clazz = globals()[class_name]
231 except KeyError:
232 sys.stderr.write("No warning type: '%s'\n" % arg)
233 else:
234 if enable:
235 enableWarningClass(clazz)
236 elif issubclass(clazz, MandatoryDeprecatedWarning):
237 fmt = "Can not disable mandataory warning: '%s'\n"
238 sys.stderr.write(fmt % arg)
239 else:
240 suppressWarningClass(clazz)
241
242
243
244
245
246
247