forked from llvm/llvm-project
- Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathclang-parse-diagnostics-file
executable file
·100 lines (85 loc) · 3.3 KB
/
clang-parse-diagnostics-file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
importos
importplistlib
defmain():
fromoptparseimportOptionParser, OptionGroup
parser=OptionParser("""\
Usage: %prog [options] <path>
Utility for dumping Clang-style logged diagnostics.\
""")
parser.add_option("-a", "--all", action="store_true", dest="all",
default=False, help="dump all messages.")
parser.add_option("-e", "--error", action="store_true", dest="error",
default=False, help="dump 'error' messages.")
parser.add_option("-f", "--fatal", action="store_true", dest="fatal",
default=False, help="dump 'fatal error' messages.")
parser.add_option("-i", "--ignored", action="store_true", dest="ignored",
default=False, help="dump 'ignored' messages.")
parser.add_option("-n", "--note", action="store_true", dest="note",
default=False, help="dump 'note' messages.")
parser.add_option("-w", "--warning", action="store_true", dest="warning",
default=False, help="dump 'warning' messages.")
(opts, args) =parser.parse_args()
iflen(args) !=1:
parser.error("invalid number of arguments")
levels= {'error': False, 'fatal error': False, 'ignored': False,
'note': False, 'warning': False}
ifopts.error:
levels['error'] =True
ifopts.fatal:
levels['fatal error'] =True
ifopts.ignored:
levels['ignored'] =True
ifopts.note:
levels['note'] =True
ifopts.warning:
levels['warning'] =True
path, =args
# Read the diagnostics log.
f=open(path)
try:
data=f.read()
finally:
f.close()
# Complete the plist (the log itself is just the chunks).
data="""\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
%s
</array>
</plist>"""%data
# Get the list of files and diagnostics to report.
to_report= []
diags=plistlib.readPlistFromString(data)
forfile_diagsindiags:
file=file_diags.get('main-file')
# Diagnostics from modules don't have a main-file listed.
ifnotfile:
file='<module-includes>'
# Ignore diagnostics for 'conftest.c', which is the file autoconf uses
# for its tests (which frequently will have warnings).
ifos.path.basename(file) =='conftest.c':
continue
# Get the diagnostics for the selected levels.
selected_diags= [d
fordinfile_diags.get('diagnostics', ())
iflevels[d.get('level')] oropts.all]
ifselected_diags:
to_report.append((file, selected_diags))
# If there are no diagnostics to report, show nothing.
ifnotto_report:
return
# Otherwise, print out the diagnostics.
print
print"**** BUILD DIAGNOSTICS ****"
forfile,selected_diagsinto_report:
print"*** %s ***"%file
fordinselected_diags:
print" %s:%s:%s: %s: %s"% (
d.get('filename'), d.get('line'), d.get('column'),
d.get('level'), d.get('message'))
if__name__=="__main__":
main()