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 3363 2008/09/06 07:34:10 scons"
31
32 import string
33 import sys
34
35 import SCons.Errors
36
37 -class Warning(SCons.Errors.UserError):
39
40
41
42
45
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
100 _warningAsException = 0
101
102
103
104 _enabled = []
105
106 _warningOut = None
107
109 """Suppresses all warnings that are of type clazz or
110 derived from clazz."""
111 _enabled.insert(0, (clazz, 0))
112
114 """Suppresses all warnings that are of type clazz or
115 derived from clazz."""
116 _enabled.insert(0, (clazz, 1))
117
124
125 -def warn(clazz, *args):
138
140 """Process string specifications of enabling/disabling warnings,
141 as passed to the --warn option or the SetOption('warn') function.
142
143
144 An argument to this option should be of the form <warning-class>
145 or no-<warning-class>. The warning class is munged in order
146 to get an actual class name from the classes above, which we
147 need to pass to the {enable,disable}WarningClass() functions.
148 The supplied <warning-class> is split on hyphens, each element
149 is capitalized, then smushed back together. Then the string
150 "Warning" is appended to get the class name.
151
152 For example, 'deprecated' will enable the DeprecatedWarning
153 class. 'no-dependency' will disable the .DependencyWarning
154 class.
155
156 As a special case, --warn=all and --warn=no-all will enable or
157 disable (respectively) the base Warning class of all warnings.
158
159 """
160
161 def _capitalize(s):
162 if s[:5] == "scons":
163 return "SCons" + s[5:]
164 else:
165 return string.capitalize(s)
166
167 for arg in arguments:
168
169 elems = string.split(string.lower(arg), '-')
170 enable = 1
171 if elems[0] == 'no':
172 enable = 0
173 del elems[0]
174
175 if len(elems) == 1 and elems[0] == 'all':
176 class_name = "Warning"
177 else:
178 class_name = string.join(map(_capitalize, elems), '') + "Warning"
179 try:
180 clazz = globals()[class_name]
181 except KeyError:
182 sys.stderr.write("No warning type: '%s'\n" % arg)
183 else:
184 if enable:
185 enableWarningClass(clazz)
186 else:
187 suppressWarningClass(clazz)
188