Move type handling to make sure we get all created types that aren't
[oota-llvm.git] / utils / clang-parse-diagnostics-file
1 #!/usr/bin/env python
2
3 import plistlib
4
5 def main():
6     from optparse import OptionParser, OptionGroup
7     parser = OptionParser("""\
8 Usage: %prog [options] <path>
9
10 Utility for dumping Clang-style logged diagnostics.\
11 """)
12     parser.add_option("-a", "--all", action="store_true", dest="all", 
13                       default=False, help="dump all messages.")
14     parser.add_option("-e", "--error", action="store_true", dest="error", 
15                       default=False, help="dump 'error' messages.")
16     parser.add_option("-f", "--fatal", action="store_true", dest="fatal", 
17                       default=False, help="dump 'fatal error' messages.")
18     parser.add_option("-i", "--ignored", action="store_true", dest="ignored", 
19                       default=False, help="dump 'ignored' messages.")
20     parser.add_option("-n", "--note", action="store_true", dest="note", 
21                       default=False, help="dump 'note' messages.")
22     parser.add_option("-w", "--warning", action="store_true", dest="warning", 
23                       default=False, help="dump 'warning' messages.")
24     (opts, args) = parser.parse_args()
25
26     if len(args) != 1:
27         parser.error("invalid number of arguments")
28
29     levels = {'error': False, 'fatal error': False, 'ignored': False,
30               'note': False, 'warning': False}
31     if opts.error:
32         levels['error'] = True
33     if opts.fatal:
34         levels['fatal error'] = True
35     if opts.ignored:
36         levels['ignored'] = True
37     if opts.note:
38         levels['note'] = True
39     if opts.warning:
40         levels['warning'] = True
41
42     path, = args
43
44     # Read the diagnostics log.
45     f = open(path)
46     try:
47         data = f.read()
48     finally:
49         f.close()
50
51     # Complete the plist (the log itself is just the chunks).
52     data = """\
53 <?xml version="1.0" encoding="UTF-8"?>
54 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
55                        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
56 <plist version="1.0">
57 <array>
58 %s
59 </array>
60 </plist>""" % data
61
62     # Load the diagnostics.
63     diags = plistlib.readPlistFromString(data)
64
65     # Print out the diagnostics.
66     print
67     print "**** BUILD DIAGNOSTICS ****"
68     for i, file_diags in enumerate(diags):
69         file = file_diags.get('main-file')
70         print "*** %s ***" % file
71         for d in file_diags.get('diagnostics', ()):
72             if levels[d.get('level')] or opts.all:
73                 print " %s:%s:%s: %s: %s" % (
74                     d.get('filename'), d.get('line'), d.get('column'),
75                     d.get('level'), d.get('message'))
76
77 if __name__ == "__main__":
78     main()