-
Notifications
You must be signed in to change notification settings - Fork 5
/
cppcheck_import.py
32 lines (27 loc) · 1.12 KB
/
cppcheck_import.py
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
from coverity_import import CoverityIssueCollector, main, get_opts
import xml.etree.ElementTree as ET
class CppCheckCollector(CoverityIssueCollector):
'''
A simple collector for cppcheck reports. The cppcheck analysis should use
the --xml-version=2 option, and we recommend the following additional
options: --enable=all --suppress=missingIncludeSystem
'''
_checker_prefix = 'cppcheck'
def process(self, f):
tree = ET.parse(f)
root = tree.getroot()
for e in root.findall('./errors/error'):
a = e.attrib
msg = self.create_issue(
checker = a['id'],
subcategory = a['severity'],
tag = a['msg'],
description = a['verbose']
)
for loc in e.findall('location'):
msg.add_location(loc.attrib['line'], loc.attrib['file'], loc.attrib.get('description'))
self.add_issue(msg)
if __name__ == '__main__':
import sys
opts = get_opts('cppcheck_import.py', sys.argv)
print CppCheckCollector(**opts).run(sys.argv[-1])