Skip to content

Commit

Permalink
[fix] Validate checkers ordered with prefix
Browse files Browse the repository at this point in the history
CC validates ordered checkers before analyzing, but didn't use to
validate the checkers ordered with the "checker:" or "prefix:"
option. With this fix, all ordered checkers will be validated.
Fixes #4405
  • Loading branch information
Nora Zinaeddin committed Jan 6, 2025
1 parent 5d4530d commit 89a1b1a
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


from collections import defaultdict
from string import Template
import os
import shutil
import signal
Expand Down Expand Up @@ -212,16 +213,46 @@ def perform_analysis(args, skip_handlers, filter_handlers,
available_checkers.add(checker_name)

if 'ordered_checkers' in args:
missing_checkers = checkers.available(args.ordered_checkers,
missing_prefixes = []
for checker in args.ordered_checkers:
if checker[0].startswith("prefix:"):
prefix = checker[0][len("prefix:"):]
if prefix not in available_checkers and not any(
item.startswith(prefix + '.') or
item.startswith(prefix + '-') for item in
available_checkers):
missing_prefixes.append(prefix)

ordered_checkers = [(checker[0].replace("checker:", ""), checker[1])
if checker[0].startswith("checker:") else checker
for checker in args.ordered_checkers]
missing_checkers = checkers.available(ordered_checkers,
available_checkers)
if missing_checkers:
diag_msg = "No checker(s) with these names was found:\n{}".format(
'\n'.join(missing_checkers))
if 'no_missing_checker_error' in args:
LOG.warning(diag_msg)
else:
LOG.error(diag_msg)
LOG.info("Although it is not reccomended, if you want to "

error_lists = {
'prefixes': missing_prefixes,
'checkers': missing_checkers
}

errors = [(name, lst) for name, lst in error_lists.items() if lst]

if errors:
msg_template = Template(
"No $err_list_name with these names was found: $items.")

for err_list_name, missing_items in errors:
missing_items_str = ', '.join(missing_items)

diag_msg = msg_template.substitute(err_list_name=err_list_name,
items=missing_items_str)

if 'no_missing_checker_error' in args:
LOG.warning(diag_msg)
else:
LOG.error(diag_msg)

if 'no_missing_checker_error' not in args:
LOG.info("Although it is not recommended, if you want to "
"suppress errors relating to unknown "
"checker names, consider using the option "
"'--no-missing-checker-error'")
Expand Down

0 comments on commit 89a1b1a

Please sign in to comment.