-
Notifications
You must be signed in to change notification settings - Fork 457
Expand file tree
/
Copy pathresult_handler.py
More file actions
108 lines (86 loc) · 3.8 KB
/
result_handler.py
File metadata and controls
108 lines (86 loc) · 3.8 KB
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
101
102
103
104
105
106
107
108
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
Result handler for Cppcheck.
"""
from typing import Optional
from codechecker_report_converter.report.parser.base import AnalyzerInfo
from codechecker_report_converter.analyzers.cppcheck.analyzer_result import \
AnalyzerResult
from codechecker_report_converter.report import BugPathEvent, \
Range, report_file, error_file
from codechecker_report_converter.report.hash import get_report_hash, HashType
from codechecker_common.logger import get_logger
from codechecker_common.skiplist_handler import SkipListHandlers
from codechecker_common.review_status_handler import ReviewStatusHandler
from codechecker_analyzer.analyzers.cppcheck.analyzer import Cppcheck
from ..result_handler_base import ResultHandler
LOG = get_logger('analyzer.cppcheck')
class CppcheckResultHandler(ResultHandler):
"""
Create analyzer result file for Cppcheck output.
"""
# This attribute is set dynamically when constructing
# this class.
analyzer: Cppcheck
def __init__(self, *args, **kwargs):
self.analyzer_info = AnalyzerInfo(name=AnalyzerResult.TOOL_NAME)
super().__init__(*args, **kwargs)
def postprocess_result(
self,
skip_handlers: Optional[SkipListHandlers],
rs_handler: Optional[ReviewStatusHandler]
):
"""
Generate analyzer result output file which can be parsed and stored
into the database.
"""
LOG.debug_analyzer(self.analyzer_stdout)
hash_type = HashType.PATH_SENSITIVE
if self.report_hash_type == 'context-free-v2':
hash_type = HashType.CONTEXT_FREE
elif self.report_hash_type == 'diagnostic-message':
hash_type = HashType.DIAGNOSTIC_MESSAGE
checkers = list(map(
lambda x: x[0], self.analyzer.get_analyzer_checkers()))
all_reports = report_file.get_reports(
self.analyzer_result_file, self.checker_labels,
source_dir_path=self.source_dir_path)
reports = []
for report in all_reports:
# TODO check if prefix cascading still occurs.
if not report.checker_name.startswith("cppcheck-"):
report.checker_name = "cppcheck-" + report.checker_name
# Cppcheck generates informative diagnostics that are not related
# to defects, e.g. normalCheckLevelMaxBranches. Reports that are
# not coming from a checker are filtered here.
if report.skip(skip_handlers) or \
report.checker_name not in checkers:
continue
report.report_hash = get_report_hash(report, hash_type)
bpe = BugPathEvent(
report.message,
report.file,
report.line,
report.column,
Range(report.line,
report.column,
report.line,
report.column))
if bpe != report.bug_path_events[-1]:
report.bug_path_events.append(bpe)
reports.append(report)
if rs_handler:
reports = [r for r in reports if not rs_handler.should_ignore(r)]
report_file.create(
self.analyzer_result_file, reports, self.checker_labels,
self.analyzer_info)
error_file.update(
self.analyzer_result_file, self.analyzer_returncode,
self.analyzer_info, self.analyzer_cmd,
self.analyzer_stdout, self.analyzer_stderr)