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 2928 2008/04/29 22:44:09 knight"
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
94 _warningAsException = 0
95
96
97
98 _enabled = []
99
100 _warningOut = None
101
103 """Suppresses all warnings that are of type clazz or
104 derived from clazz."""
105 _enabled.insert(0, (clazz, 0))
106
108 """Suppresses all warnings that are of type clazz or
109 derived from clazz."""
110 _enabled.insert(0, (clazz, 1))
111
118
119 -def warn(clazz, *args):
132
134 """Process string specifications of enabling/disabling warnings,
135 as passed to the --warn option or the SetOption('warn') function.
136
137
138 An argument to this option should be of the form <warning-class>
139 or no-<warning-class>. The warning class is munged in order
140 to get an actual class name from the classes above, which we
141 need to pass to the {enable,disable}WarningClass() functions.
142 The supplied <warning-class> is split on hyphens, each element
143 is capitalized, then smushed back together. Then the string
144 "Warning" is appended to get the class name.
145
146 For example, 'deprecated' will enable the DeprecatedWarning
147 class. 'no-dependency' will disable the .DependencyWarning
148 class.
149
150 As a special case, --warn=all and --warn=no-all will enable or
151 disable (respectively) the base Warning class of all warnings.
152
153 """
154
155 def _capitalize(s):
156 if s[:5] == "scons":
157 return "SCons" + s[5:]
158 else:
159 return string.capitalize(s)
160
161 for arg in arguments:
162
163 elems = string.split(string.lower(arg), '-')
164 enable = 1
165 if elems[0] == 'no':
166 enable = 0
167 del elems[0]
168
169 if len(elems) == 1 and elems[0] == 'all':
170 class_name = "Warning"
171 else:
172 class_name = string.join(map(_capitalize, elems), '') + "Warning"
173 try:
174 clazz = globals()[class_name]
175 except KeyError:
176 sys.stderr.write("No warning type: '%s'\n" % arg)
177 else:
178 if enable:
179 enableWarningClass(clazz)
180 else:
181 suppressWarningClass(clazz)
182