Skip to content

Commit

Permalink
Merge pull request #4054 from bruntib/review_status_handler_1_source_…
Browse files Browse the repository at this point in the history
…code

[feat] Introduce review status config file
  • Loading branch information
dkrupp authored Oct 26, 2023
2 parents 6a5af0e + c040e60 commit afb3bd6
Show file tree
Hide file tree
Showing 28 changed files with 666 additions and 331 deletions.
22 changes: 22 additions & 0 deletions analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ def add_arguments_to_parser(parser):
"Example: '/path/to/main.cpp', 'lib/*.cpp', "
"*/test*'.")

parser.add_argument('--review-status-config',
dest="review_status_config",
required=False,
type=existing_abspath,
default=argparse.SUPPRESS,
help="Path of review_status.yaml config file which "
"contains review status settings assigned to "
"specific directories, checkers, bug hashes.")

parser.add_argument('-o', '--output',
dest="output_path",
required=True,
Expand Down Expand Up @@ -858,6 +867,18 @@ def __update_skip_file(args):
shutil.copyfile(args.skipfile, skip_file_to_send)


def __update_review_status_config(args):
rs_config_to_send = os.path.join(args.output_path, 'review_status.yaml')

if os.path.exists(rs_config_to_send):
os.remove(rs_config_to_send)

if 'review_status_config' in args:
LOG.debug("Copying review status config file %s to %s",
args.review_status_config, rs_config_to_send)
shutil.copyfile(args.review_status_config, rs_config_to_send)


def __cleanup_metadata(metadata_prev, metadata):
""" Cleanup metadata.
Expand Down Expand Up @@ -1103,6 +1124,7 @@ def main(args):
compile_cmd_count)

__update_skip_file(args)
__update_review_status_config(args)

LOG.debug("Cleanup metadata file started.")
__cleanup_metadata(metadata_prev, metadata)
Expand Down
15 changes: 13 additions & 2 deletions analyzer/codechecker_analyzer/cmd/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from codechecker_analyzer.analyzers import analyzer_types
from codechecker_analyzer.arg import \
OrderedCheckersAction, OrderedConfigAction, \
analyzer_config, checker_config
analyzer_config, checker_config, existing_abspath

from codechecker_common import arg, cmd_config, logger
from codechecker_report_converter.source_code_comment_handler import \
from codechecker_common.source_code_comment_handler import \
REVIEW_STATUS_VALUES

from codechecker_analyzer.cmd.analyze import \
Expand Down Expand Up @@ -400,6 +400,16 @@ def add_arguments_to_parser(parser):
"the analysis is considered as a failed "
"one.")

analyzer_opts.add_argument('--review-status-config',
dest="review_status_config",
required=False,
type=existing_abspath,
default=argparse.SUPPRESS,
help="Path of review_status.yaml config file "
"which contains review status settings "
"assigned to specific directories, "
"checkers, bug hashes.")

clang_has_z3 = analyzer_types.is_z3_capable()

if clang_has_z3:
Expand Down Expand Up @@ -872,6 +882,7 @@ def __update_if_key_exists(source, target, key):
'disable_all',
'ordered_checkers', # --enable and --disable.
'timeout',
'review_status_config',
'compile_uniqueing',
'report_hash',
'enable_z3',
Expand Down
33 changes: 31 additions & 2 deletions analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
from codechecker_report_converter.report.output.html import \
html as report_to_html
from codechecker_report_converter.report.statistics import Statistics
from codechecker_report_converter.source_code_comment_handler import \
REVIEW_STATUS_VALUES


from codechecker_analyzer import analyzer_context, suppress_handler

from codechecker_common import arg, logger, cmd_config
from codechecker_common.review_status_handler import ReviewStatusHandler
from codechecker_common.skiplist_handler import SkipListHandler, \
SkipListHandlers
from codechecker_common.source_code_comment_handler import \
REVIEW_STATUS_VALUES
from codechecker_common.util import load_json


Expand Down Expand Up @@ -384,6 +385,7 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
processed_path_hashes = set()
processed_file_paths = set()
print_steps = 'print_steps' in args
review_status_handler = ReviewStatusHandler()

html_builder: Optional[report_to_html.HtmlBuilder] = None
if export == 'html':
Expand All @@ -392,6 +394,15 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
context.checker_labels)

for dir_path, file_paths in report_file.analyzer_result_files(args.input):
review_status_cfg = os.path.join(dir_path, 'review_status.yaml')
if os.path.isfile(review_status_cfg):
try:
review_status_handler.set_review_status_config(
review_status_cfg)
except ValueError as err:
LOG.error(err)
sys.exit(1)

metadata = get_metadata(dir_path)

if metadata and 'files' in args:
Expand All @@ -413,6 +424,20 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
reports = report_file.get_reports(
file_path, context.checker_labels, file_cache)

for report in reports:
try:
# TODO: skip_handler is used later in reports_helper.skip()
# too. However, skipped reports shouldn't check source code
# comments because they potentially raise an exception.
# Skipped files shouldn't raise an exception, also, "skip"
# shouldn't be checked twice.
if not report.skip(skip_handlers):
report.review_status = \
review_status_handler.get_review_status(report)
except ValueError as err:
LOG.error(err)
sys.exit(1)

reports = reports_helper.skip(
reports, processed_path_hashes, skip_handlers, suppr_handler,
src_comment_status_filter)
Expand All @@ -434,13 +459,17 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
file_report_map = plaintext.get_file_report_map(
reports, file_path, metadata)
plaintext.convert(
review_status_handler,
file_report_map, processed_file_paths, print_steps)
elif export == 'html':
print(f"Parsing input file '{file_path}'.")
report_to_html.convert(
file_path, reports, output_dir_path,
html_builder)

for warning in review_status_handler.source_comment_warnings():
LOG.warning(warning)

if export is None: # Plain text output
statistics.write()
elif export == 'html':
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/suppress_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import re

from codechecker_common.logger import get_logger
from codechecker_report_converter.source_code_comment_handler import \
from codechecker_common.source_code_comment_handler import \
SourceCodeCommentHandler

LOG = get_logger('system')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,21 @@ def check_one_file(self, path, mode):

# Replace full path only to file name on the following
# formatted lines:
# 1.
# [severity] /a/b/x.cpp:line:col: message [checker]
# The replacement on this line will be the following:
# [severity] x.cpp:line:col: message [checker]
# 2.
# [] - /a/b/x.cpp contains misspelled ...
# The replacement on this line will be the following:
# [] - x.cpp contains misspelled ...
sep = re.escape(os.sep)
line = re.sub(r'^(\[\w+\]\s)(?P<path>.+{0})'
r'(.+\:\d+\:\d+\:\s.*\s\[.*\])$'.format(sep),
r'\1\3', line)
line = re.sub(r'^\[\] - (?P<path>.+{0})'
r'(.+ contains misspelled.+)'.format(sep),
r'[] - \2', line)

if not any([line.startswith(prefix) for prefix
in skip_prefixes]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ CHECK#CodeChecker check --build "make multi_error_suppress_typo" --output $OUTPU
return x/0;
^

[] - multi_error_suppress_typo.cpp contains misspelled review status comment @9: // codechecker_suppressssss [all] some comment
[LOW] multi_error_suppress_typo.cpp:10:3: Value stored to 'y' is never read [deadcode.DeadStores]
y = 7;
^

Found 2 defect(s) in multi_error_suppress_typo.cpp

[] - multi_error_suppress_typo.cpp contains misspelled review status comment @9: // codechecker_suppressssss [all] some comment

----==== Severity Statistics ====----
----------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
import unittest

from codechecker_report_converter.source_code_comment_handler import \
from codechecker_common.source_code_comment_handler import \
SourceCodeComment, SourceCodeCommentHandler


Expand Down
Loading

0 comments on commit afb3bd6

Please sign in to comment.