Skip to content

Commit

Permalink
[fix] Missing analyzer error
Browse files Browse the repository at this point in the history
`CodeChecker analyzers` gives python error for the user if a supported analyzer is missing. In addition, CodeChecker `analyze` and `check` should have provided an error and sys.exit when the specified (with `--analyzers`) analyzer was missing.

With this PR, `CodeChecker analyzers` can give a warning message with `NOT FOUND` status if a supported analyzer can't be found on the machine.

In case of explicitly defined missing analyzer, the `analyze` and `check` command will be failed and will give warrning and error message for the user.
  • Loading branch information
cservakt committed Aug 28, 2024
1 parent e7fab3e commit 107bf4a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
analyzers = args.analyzers if 'analyzers' in args \
else analyzer_types.supported_analyzers
analyzers, errored = analyzer_types.check_supported_analyzers(analyzers)
analyzer_types.check_available_analyzers(analyzers, errored)
analyzer_types.check_available_analyzers(analyzers, errored, args)

ctu_collect = False
ctu_analyze = False
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/analyzer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __populate_analyzers(self):
self.__analyzers[name] = compiler_binary

def get_analyzer_env(self, analyzer_name):
return self.__analyzer_envs[analyzer_name]
return self.__analyzer_envs.get(analyzer_name)

def __populate_replacer(self):
""" Set clang-apply-replacements tool. """
Expand Down
22 changes: 16 additions & 6 deletions analyzer/codechecker_analyzer/analyzers/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,25 @@ def print_unsupported_analyzers(errored):
analyzer_binary, reason)


def check_available_analyzers(analyzers, errored):
""" Handle use case when no analyzer can be found on the user machine. """
if analyzers:
def check_available_analyzers(analyzers, errored, args):
"""
Handle use case when no analyzer can be found or a supported, explicitly
given analyzer cannot be found on the user machine.
"""
if analyzers and (not errored or 'analyzers' not in args):
return

print_unsupported_analyzers(errored)
LOG.error("Failed to run command because no analyzers can be found on "
"your machine!")
sys.exit(1)

if 'analyzers' in args:
LOG.error("Failed to run command because the given analyzer(s) "
"cannot be found on your machine!")
sys.exit(1)

if not analyzers:
LOG.error("Failed to run command because no analyzers can be found "
"on your machine!")
sys.exit(1)


def check_supported_analyzers(analyzers):
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/cmd/analyzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def uglify(text):
check_env = context.get_analyzer_env(analyzer_name)
version = analyzer_class.get_binary_version(check_env)
if not version:
version = 'ERROR'
version = 'NOT FOUND'

binary = context.analyzer_binaries.get(analyzer_name)
rows.append([analyzer_name, binary, version])
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/cmd/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def __print_checker_config(args: argparse.Namespace):

working_analyzers, errored = analyzer_types.check_supported_analyzers(
args.analyzers)
analyzer_types.check_available_analyzers(working_analyzers, errored)
analyzer_types.check_available_analyzers(working_analyzers, errored, args)

if 'details' in args:
header = ['Option', 'Description']
Expand Down

0 comments on commit 107bf4a

Please sign in to comment.