7 from optparse
import OptionParser
, OptionGroup
8 parser
= OptionParser("""\
9 Usage: %prog [options] <path>
11 Utility for dumping Clang-style logged diagnostics.\
13 parser
.add_option("-a", "--all", action
="store_true", dest
="all",
14 default
=False, help="dump all messages.")
15 parser
.add_option("-e", "--error", action
="store_true", dest
="error",
16 default
=False, help="dump 'error' messages.")
17 parser
.add_option("-f", "--fatal", action
="store_true", dest
="fatal",
18 default
=False, help="dump 'fatal error' messages.")
19 parser
.add_option("-i", "--ignored", action
="store_true", dest
="ignored",
20 default
=False, help="dump 'ignored' messages.")
21 parser
.add_option("-n", "--note", action
="store_true", dest
="note",
22 default
=False, help="dump 'note' messages.")
23 parser
.add_option("-w", "--warning", action
="store_true", dest
="warning",
24 default
=False, help="dump 'warning' messages.")
25 (opts
, args
) = parser
.parse_args()
28 parser
.error("invalid number of arguments")
30 levels
= {'error': False, 'fatal error': False, 'ignored': False,
31 'note': False, 'warning': False}
33 levels
['error'] = True
35 levels
['fatal error'] = True
37 levels
['ignored'] = True
41 levels
['warning'] = True
45 # Read the diagnostics log.
52 # Complete the plist (the log itself is just the chunks).
54 <?xml version="1.0" encoding="UTF-8"?>
55 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
56 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
63 # Get the list of files and diagnostics to report.
65 diags
= plistlib
.readPlistFromString(data
)
66 for file_diags
in diags
:
67 file = file_diags
.get('main-file')
69 # Diagnostics from modules don't have a main-file listed.
71 file = '<module-includes>'
73 # Ignore diagnostics for 'conftest.c', which is the file autoconf uses
74 # for its tests (which frequently will have warnings).
75 if os
.path
.basename(file) == 'conftest.c':
78 # Get the diagnostics for the selected levels.
80 for d
in file_diags
.get('diagnostics', ())
81 if levels
[d
.get('level')] or opts
.all
]
83 to_report
.append((file, selected_diags
))
85 # If there are no diagnostics to report, show nothing.
89 # Otherwise, print out the diagnostics.
91 print "**** BUILD DIAGNOSTICS ****"
92 for file,selected_diags
in to_report
:
93 print "*** %s ***" % file
94 for d
in selected_diags
:
95 print " %s:%s:%s: %s: %s" % (
96 d
.get('filename'), d
.get('line'), d
.get('column'),
97 d
.get('level'), d
.get('message'))
99 if __name__
== "__main__":