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 bee7caf9defd6e108fc2998a2520ddb36a967691 2019-12-17 02:07:09 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
135
136
137
138 _enabled = []
139
140
141 _warningAsException = 0
142
143
144 _warningOut = None
145
147 """Suppresses all warnings that are of type clazz or
148 derived from clazz."""
149 _enabled.insert(0, (clazz, 0))
150
152 """Enables all warnings that are of type clazz or
153 derived from clazz."""
154 _enabled.insert(0, (clazz, 1))
155
162
163 -def warn(clazz, *args):
176
178 """Process requests to enable/disable warnings.
179
180 The requests are strings passed to the --warn option or the
181 SetOption('warn') function.
182
183 An argument to this option should be of the form <warning-class>
184 or no-<warning-class>. The warning class is munged in order
185 to get an actual class name from the classes above, which we
186 need to pass to the {enable,disable}WarningClass() functions.
187 The supplied <warning-class> is split on hyphens, each element
188 is capitalized, then smushed back together. Then the string
189 "Warning" is appended to get the class name.
190
191 For example, 'deprecated' will enable the DeprecatedWarning
192 class. 'no-dependency' will disable the DependencyWarning class.
193
194 As a special case, --warn=all and --warn=no-all will enable or
195 disable (respectively) the base Warning class of all warnings.
196 """
197
198 def _capitalize(s):
199 if s[:5] == "scons":
200 return "SCons" + s[5:]
201 else:
202 return s.capitalize()
203
204 for arg in arguments:
205
206 elems = arg.lower().split('-')
207 enable = 1
208 if elems[0] == 'no':
209 enable = 0
210 del elems[0]
211
212 if len(elems) == 1 and elems[0] == 'all':
213 class_name = "Warning"
214 else:
215 class_name = ''.join(map(_capitalize, elems)) + "Warning"
216 try:
217 clazz = globals()[class_name]
218 except KeyError:
219 sys.stderr.write("No warning type: '%s'\n" % arg)
220 else:
221 if enable:
222 enableWarningClass(clazz)
223 elif issubclass(clazz, MandatoryDeprecatedWarning):
224 fmt = "Can not disable mandataory warning: '%s'\n"
225 sys.stderr.write(fmt % arg)
226 else:
227 suppressWarningClass(clazz)
228
229
230
231
232
233
234