23 class WarningHandler: |
23 class WarningHandler: |
24 |
24 |
25 # Counters for various warnings |
25 # Counters for various warnings |
26 totalWarnings = 0 |
26 totalWarnings = 0 |
27 badOnes = 0 |
27 badOnes = 0 |
28 pragmaWarnings = 0 |
28 deprecatedWarnings = 0 |
29 compilerWarnings = 0 |
29 compilerWarnings = 0 |
30 linkerWarnings = 0 |
30 linkerWarnings = 0 |
31 postlinkerWarnings = 0 |
31 postlinkerWarnings = 0 |
32 flmWarnings = 0 |
32 flmWarnings = 0 |
33 |
33 |
34 # Constants for matching pragma generated warnings |
34 # Constants for matching warnings related to deprecation |
35 pragmaStart = "warning: preprocessor #warning directive" |
35 deprecatedStart = "warning: preprocessor #warning directive" |
36 pragmaOptionalRest = "warning: " |
36 deprecatedSecondLine = "warning: #warning This header file" |
|
37 deprecatedOptionalThirdLine = "warning: (included from:" |
|
38 deprecatedOptionalRest = "warning: " |
37 |
39 |
38 # This list includes strings from which the BAD warnings can be recognized. |
40 # This list includes strings from which the BAD warnings can be recognized. |
39 # Note that these must be in lower case! |
41 # Note that these must be in lower case! |
40 badWarnings = [ |
42 badWarnings = [ |
41 "#111-d", "#1166-d", "#117-d", "#128-d", "#1293-d", "#1441-d", "#170-d", |
43 "#111-d", "#1166-d", "#117-d", "#128-d", "#1293-d", "#1441-d", "#170-d", |
57 print "Total warnings:", self.totalWarnings |
59 print "Total warnings:", self.totalWarnings |
58 print "Bad ones: ", self.badOnes |
60 print "Bad ones: ", self.badOnes |
59 print "" |
61 print "" |
60 print "Details:" |
62 print "Details:" |
61 print " FLM warnings: ", self.flmWarnings |
63 print " FLM warnings: ", self.flmWarnings |
62 print " Pragma warnings: ", self.pragmaWarnings |
64 print " Use of deprecated api: ", self.deprecatedWarnings |
63 print " Other compiler warnings: ", self.compilerWarnings |
65 print " Other compiler warnings: ", self.compilerWarnings |
64 print " Linker warnings: ", self.linkerWarnings |
66 print " Linker warnings: ", self.linkerWarnings |
65 print " Post-linker warnings: ", self.postlinkerWarnings |
67 print " Post-linker warnings: ", self.postlinkerWarnings |
66 |
68 |
67 |
69 |
68 |
70 |
69 class PrintSettings: |
71 class PrintSettings: |
70 """Class parsing and maintaining the printing settings related to warnings""" |
72 """Class parsing and maintaining the printing settings related to warnings""" |
71 |
73 |
72 printPragmaWarnings = False |
74 printDeprecatedWarnings = False |
73 printCompilerWarnings = False |
75 printCompilerWarnings = False |
74 printLinkerWarnings = False |
76 printLinkerWarnings = False |
75 printFlmWarnings = False |
77 printFlmWarnings = False |
76 |
78 |
77 def parseArgs(self): |
79 def parseArgs(self): |
83 default=False, help="Prints all the warnings") |
85 default=False, help="Prints all the warnings") |
84 parser.add_option("--pc", dest="printcompilerwarnings", action="store_true", |
86 parser.add_option("--pc", dest="printcompilerwarnings", action="store_true", |
85 default=False, help="Prints compiler warnings") |
87 default=False, help="Prints compiler warnings") |
86 parser.add_option("--pl", dest="printlinkerwarnings", action="store_true", |
88 parser.add_option("--pl", dest="printlinkerwarnings", action="store_true", |
87 default=False, help="Prints linker warnings") |
89 default=False, help="Prints linker warnings") |
88 parser.add_option("--pp", dest="printpragmawarnings", action="store_true", |
90 parser.add_option("--pd", dest="printdeprecatedwarnings", action="store_true", |
89 default=False, help="Prints pragma warnings") |
91 default=False, help="Prints deprecation warnings") |
90 parser.add_option("--pf", dest="printflmwarnings", action="store_true", |
92 parser.add_option("--pf", dest="printflmwarnings", action="store_true", |
91 default=False, help="Prints FLM warnings") |
93 default=False, help="Prints FLM warnings") |
92 (opts, args) = parser.parse_args() |
94 (opts, args) = parser.parse_args() |
93 |
95 |
94 if len(args) != 1: |
96 if len(args) != 1: |
95 parser.print_help() |
97 parser.print_help() |
96 sys.exit(-1) |
98 sys.exit(-1) |
97 |
99 |
98 if opts.printall: |
100 if opts.printall: |
99 self.printPragmaWarnings = True |
101 self.printDeprecatedWarnings = True |
100 self.printCompilerWarnings = True |
102 self.printCompilerWarnings = True |
101 self.printLinkerWarnings = True |
103 self.printLinkerWarnings = True |
102 self.printFlmWarnings = True |
104 self.printFlmWarnings = True |
103 else: |
105 else: |
104 self.printPragmaWarnings = opts.printpragmawarnings |
106 self.printDeprecatedWarnings = opts.printdeprecatedwarnings |
105 self.printCompilerWarnings = opts.printcompilerwarnings |
107 self.printCompilerWarnings = opts.printcompilerwarnings |
106 self.printLinkerWarnings = opts.printlinkerwarnings |
108 self.printLinkerWarnings = opts.printlinkerwarnings |
107 self.printFlmWarnings = opts.printflmwarnings |
109 self.printFlmWarnings = opts.printflmwarnings |
108 |
110 |
109 return args[0] |
111 return args[0] |
115 # |
117 # |
116 # BAD warnings are those warnings that are considered so important that builds |
118 # BAD warnings are those warnings that are considered so important that builds |
117 # should have always zero of them. The related log message strings are defined |
119 # should have always zero of them. The related log message strings are defined |
118 # in the variable badWarnings above. |
120 # in the variable badWarnings above. |
119 # |
121 # |
120 # The warnings are further categorized as pragma warnings, compiler |
122 # The warnings are further categorized as deprecated API warnings, compiler |
121 # warnings, linker, and post-linker warnings. |
123 # warnings, linker, and post-linker warnings. |
122 # |
124 # |
123 def main(): |
125 def main(): |
124 |
126 |
125 # Parse command line options and log file name. |
127 # Parse command line options and log file name. |
164 def stateMachine(state, line, underCompilation, settings, wh): |
166 def stateMachine(state, line, underCompilation, settings, wh): |
165 |
167 |
166 # Looking for any warning related to the current target |
168 # Looking for any warning related to the current target |
167 if state == 1: |
169 if state == 1: |
168 |
170 |
169 # Check first for the start of a multiline pragma warning |
171 # Check first for the start of a multiline deprecation warning |
170 if wh.pragmaStart in line: |
172 if wh.deprecatedStart in line: |
171 if settings.printPragmaWarnings: |
173 if settings.printDeprecatedWarnings: |
172 print underCompilation, |
174 print underCompilation, |
173 print line, |
175 print line, |
174 wh.pragmaWarnings += 1 |
176 wh.deprecatedWarnings += 1 |
175 wh.totalWarnings += 1 |
177 wh.totalWarnings += 1 |
176 return 2 |
178 return 2 |
177 |
179 |
178 else: |
180 else: |
179 |
181 |
216 print underCompilation, |
218 print underCompilation, |
217 print line, |
219 print line, |
218 |
220 |
219 return 1 |
221 return 1 |
220 |
222 |
221 # Looking for the optional trailing lines of the multiline pragma warning |
223 # Looking for the second line of the multiline deprecation warning |
222 if state == 2: |
224 if state == 2: |
223 if wh.pragmaOptionalRest in line: |
225 if wh.deprecatedSecondLine in line: |
224 if settings.printPragmaWarnings: |
226 if settings.printDeprecatedWarnings: |
225 print line, |
227 print line, |
226 return 2 |
228 return 3 |
|
229 else: |
|
230 print "Missing second line" |
|
231 return 1 |
|
232 |
|
233 # Looking for the optional third line of the multiline deprecation warning |
|
234 if state == 3: |
|
235 if wh.deprecatedOptionalThirdLine in line: |
|
236 if settings.printDeprecatedWarnings: |
|
237 print line, |
|
238 return 4 |
|
239 else: |
|
240 # Hmm... went one line too far -> need to check the current line again |
|
241 # but now in the state 1 |
|
242 return stateMachine(1, line, underCompilation, settings, wh) |
|
243 |
|
244 # Looking for the optional trailing lines of the multiline deprecation warning |
|
245 if state == 4: |
|
246 if wh.deprecatedOptionalRest in line: |
|
247 if settings.printDeprecatedWarnings: |
|
248 print line, |
|
249 return 4 |
227 else: |
250 else: |
228 # Hmm... went one line too far -> need to check the current line again |
251 # Hmm... went one line too far -> need to check the current line again |
229 # but now in the state 1 |
252 # but now in the state 1 |
230 return stateMachine(1, line, underCompilation, settings, wh) |
253 return stateMachine(1, line, underCompilation, settings, wh) |
231 |
|
232 |
254 |
233 # Looking for MAKEDEF detailed information lines |
255 # Looking for MAKEDEF detailed information lines |
234 if state == 5: |
256 if state == 5: |
235 if settings.printLinkerWarnings: |
257 if settings.printLinkerWarnings: |
236 print line, |
258 print line, |