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 2014/03/02 14:18:15 garyo"
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
93
94
97
100
103
104
105
106
109
112
115
116
117
120
123
126
129
132
135
138
141
144
147
150
151
152
153
154 _enabled = []
155
156
157 _warningAsException = 0
158
159
160 _warningOut = None
161
163 """Suppresses all warnings that are of type clazz or
164 derived from clazz."""
165 _enabled.insert(0, (clazz, 0))
166
168 """Enables all warnings that are of type clazz or
169 derived from clazz."""
170 _enabled.insert(0, (clazz, 1))
171
178
179 -def warn(clazz, *args):
192
194 """Process string specifications of enabling/disabling warnings,
195 as passed to the --warn option or the SetOption('warn') function.
196
197
198 An argument to this option should be of the form <warning-class>
199 or no-<warning-class>. The warning class is munged in order
200 to get an actual class name from the classes above, which we
201 need to pass to the {enable,disable}WarningClass() functions.
202 The supplied <warning-class> is split on hyphens, each element
203 is capitalized, then smushed back together. Then the string
204 "Warning" is appended to get the class name.
205
206 For example, 'deprecated' will enable the DeprecatedWarning
207 class. 'no-dependency' will disable the DependencyWarning class.
208
209 As a special case, --warn=all and --warn=no-all will enable or
210 disable (respectively) the base Warning class of all warnings.
211
212 """
213
214 def _capitalize(s):
215 if s[:5] == "scons":
216 return "SCons" + s[5:]
217 else:
218 return s.capitalize()
219
220 for arg in arguments:
221
222 elems = arg.lower().split('-')
223 enable = 1
224 if elems[0] == 'no':
225 enable = 0
226 del elems[0]
227
228 if len(elems) == 1 and elems[0] == 'all':
229 class_name = "Warning"
230 else:
231 class_name = ''.join(map(_capitalize, elems)) + "Warning"
232 try:
233 clazz = globals()[class_name]
234 except KeyError:
235 sys.stderr.write("No warning type: '%s'\n" % arg)
236 else:
237 if enable:
238 enableWarningClass(clazz)
239 elif issubclass(clazz, MandatoryDeprecatedWarning):
240 fmt = "Can not disable mandataory warning: '%s'\n"
241 sys.stderr.write(fmt % arg)
242 else:
243 suppressWarningClass(clazz)
244
245
246
247
248
249
250