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 3a41ed6b288cee8d085373ad7fa02894e1903864 2019-01-23 17:30:35 bdeegan"
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
92
93
96
99
102
103
104
105
108
111
114
115
116
119
122
125
128
131
134
137
140
143
146
149
152
153
154
155
156 _enabled = []
157
158
159 _warningAsException = 0
160
161
162 _warningOut = None
163
165 """Suppresses all warnings that are of type clazz or
166 derived from clazz."""
167 _enabled.insert(0, (clazz, 0))
168
170 """Enables all warnings that are of type clazz or
171 derived from clazz."""
172 _enabled.insert(0, (clazz, 1))
173
180
181 -def warn(clazz, *args):
194
196 """Process string specifications of enabling/disabling warnings,
197 as passed to the --warn option or the SetOption('warn') function.
198
199
200 An argument to this option should be of the form <warning-class>
201 or no-<warning-class>. The warning class is munged in order
202 to get an actual class name from the classes above, which we
203 need to pass to the {enable,disable}WarningClass() functions.
204 The supplied <warning-class> is split on hyphens, each element
205 is capitalized, then smushed back together. Then the string
206 "Warning" is appended to get the class name.
207
208 For example, 'deprecated' will enable the DeprecatedWarning
209 class. 'no-dependency' will disable the DependencyWarning class.
210
211 As a special case, --warn=all and --warn=no-all will enable or
212 disable (respectively) the base Warning class of all warnings.
213
214 """
215
216 def _capitalize(s):
217 if s[:5] == "scons":
218 return "SCons" + s[5:]
219 else:
220 return s.capitalize()
221
222 for arg in arguments:
223
224 elems = arg.lower().split('-')
225 enable = 1
226 if elems[0] == 'no':
227 enable = 0
228 del elems[0]
229
230 if len(elems) == 1 and elems[0] == 'all':
231 class_name = "Warning"
232 else:
233 class_name = ''.join(map(_capitalize, elems)) + "Warning"
234 try:
235 clazz = globals()[class_name]
236 except KeyError:
237 sys.stderr.write("No warning type: '%s'\n" % arg)
238 else:
239 if enable:
240 enableWarningClass(clazz)
241 elif issubclass(clazz, MandatoryDeprecatedWarning):
242 fmt = "Can not disable mandataory warning: '%s'\n"
243 sys.stderr.write(fmt % arg)
244 else:
245 suppressWarningClass(clazz)
246
247
248
249
250
251
252