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