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 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog"
31
32 import sys
33
34 import SCons.Errors
35
36 -class Warning(SCons.Errors.UserError):
38
41
42
43
45 pass
46
49
52
55
58
61
64
67
70
73
76
79
82
85
88
91
94
97
98
99
102
105
108
109
110
111
114
117
120
121
122
125
128
131
134
137
140
143
146
149
152
155
156
157
158
159 _enabled = []
160
161
162 _warningAsException = 0
163
164
165 _warningOut = None
166
168 """Suppresses all warnings that are of type clazz or
169 derived from clazz."""
170 _enabled.insert(0, (clazz, 0))
171
173 """Enables all warnings that are of type clazz or
174 derived from clazz."""
175 _enabled.insert(0, (clazz, 1))
176
183
184 -def warn(clazz, *args):
197
199 """Process string specifications of enabling/disabling warnings,
200 as passed to the --warn option or the SetOption('warn') function.
201
202
203 An argument to this option should be of the form <warning-class>
204 or no-<warning-class>. The warning class is munged in order
205 to get an actual class name from the classes above, which we
206 need to pass to the {enable,disable}WarningClass() functions.
207 The supplied <warning-class> is split on hyphens, each element
208 is capitalized, then smushed back together. Then the string
209 "Warning" is appended to get the class name.
210
211 For example, 'deprecated' will enable the DeprecatedWarning
212 class. 'no-dependency' will disable the DependencyWarning class.
213
214 As a special case, --warn=all and --warn=no-all will enable or
215 disable (respectively) the base Warning class of all warnings.
216
217 """
218
219 def _capitalize(s):
220 if s[:5] == "scons":
221 return "SCons" + s[5:]
222 else:
223 return s.capitalize()
224
225 for arg in arguments:
226
227 elems = arg.lower().split('-')
228 enable = 1
229 if elems[0] == 'no':
230 enable = 0
231 del elems[0]
232
233 if len(elems) == 1 and elems[0] == 'all':
234 class_name = "Warning"
235 else:
236 class_name = ''.join(map(_capitalize, elems)) + "Warning"
237 try:
238 clazz = globals()[class_name]
239 except KeyError:
240 sys.stderr.write("No warning type: '%s'\n" % arg)
241 else:
242 if enable:
243 enableWarningClass(clazz)
244 elif issubclass(clazz, MandatoryDeprecatedWarning):
245 fmt = "Can not disable mandataory warning: '%s'\n"
246 sys.stderr.write(fmt % arg)
247 else:
248 suppressWarningClass(clazz)
249
250
251
252
253
254
255