-
Notifications
You must be signed in to change notification settings - Fork 36
/
cppcheck.py
97 lines (82 loc) · 3.49 KB
/
cppcheck.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
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
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
import re
from buildbot.process import logobserver
from buildbot.status.results import FAILURE
from buildbot.status.results import SUCCESS
from buildbot.status.results import WARNINGS
from buildbot.steps.shell import ShellCommand
class Cppcheck(ShellCommand):
# Highly inspirated from the Pylint step.
name = "cppcheck"
description = ["running", "cppcheck"]
descriptionDone = ["cppcheck"]
flunkingIssues = ('error',)
MESSAGES = (
'error', 'warning', 'style', 'performance', 'portability', 'information')
renderables = ('binary', 'source', 'extra_args')
def __init__(self, *args, **kwargs):
for name, default in [('binary', 'cppcheck'),
('source', ['.']),
('enable', []),
('inconclusive', False),
('extra_args', [])]:
setattr(self, name, default)
if name in kwargs:
setattr(self, name, kwargs[name])
del kwargs[name]
ShellCommand.__init__(self, *args, **kwargs)
self.addLogObserver(
'stdio', logobserver.LogLineObserver())
command = [self.binary]
command.extend(self.source)
if self.enable:
command.append('--enable=%s' % ','.join(self.enable))
if self.inconclusive:
command.append('--inconclusive')
command.extend(self.extra_args)
self.setCommand(command)
counts = self.counts = {}
summaries = self.summaries = {}
for m in self.MESSAGES:
counts[m] = 0
summaries[m] = []
def logConsumer(self):
line_re = re.compile(
r'(?:\[.+\]: )?\((?P<severity>%s)\) .+' % '|'.join(self.MESSAGES))
while True:
stream, line = yield
m = line_re.match(line)
if m is not None:
msgsev = m.group('severity')
self.summaries[msgsev].append(line)
self.counts[msgsev] += 1
def createSummary(self, log):
self.descriptionDone = self.descriptionDone[:]
for msg in self.MESSAGES:
self.setProperty('cppcheck-%s' % msg, self.counts[msg], 'Cppcheck')
if not self.counts[msg]:
continue
self.descriptionDone.append("%s=%d" % (msg, self.counts[msg]))
self.addCompleteLog(msg, '\n'.join(self.summaries[msg]))
self.setProperty('cppcheck-total', sum(self.counts.values()), 'Cppcheck')
def evaluateCommand(self, cmd):
""" cppcheck always return 0, unless a special parameter is given """
for msg in self.flunkingIssues:
if self.counts[msg] != 0:
return FAILURE
if self.getProperty('cppcheck-total') != 0:
return WARNINGS
return SUCCESS