Skip to content

Commit

Permalink
Merge pull request Ericsson#4330 from cservakt/missing-analyzer-error
Browse files Browse the repository at this point in the history
[fix] Missing analyzer error
  • Loading branch information
bruntib authored Aug 30, 2024
2 parents 6123768 + 39868a8 commit 99fcaf4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
6 changes: 2 additions & 4 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
ctu_reanalyze_on_failure = 'ctu_reanalyze_on_failure' in args and \
args.ctu_reanalyze_on_failure

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)
analyzers, errored = \
analyzer_types.check_available_analyzers(args.analyzers)

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
31 changes: 22 additions & 9 deletions analyzer/codechecker_analyzer/analyzers/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,28 @@ 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:
return

print_unsupported_analyzers(errored)
LOG.error("Failed to run command because no analyzers can be found on "
"your machine!")
sys.exit(1)
def check_available_analyzers(args_analyzers=None):
"""
Handle use case when no analyzer can be found or a supported, explicitly
given analyzer cannot be found on the user machine.
"""

if args_analyzers:
analyzers, errored = check_supported_analyzers(args_analyzers)
if errored:
print_unsupported_analyzers(errored)
LOG.error("Failed to run command because the given analyzer(s) "
"cannot be found on your machine!")
sys.exit(1)

else:
analyzers, errored = check_supported_analyzers(supported_analyzers)
if not analyzers:
print_unsupported_analyzers(errored)
LOG.error("Failed to run command because no analyzers can be "
"found on your machine!")
sys.exit(1)
return analyzers, errored


def check_supported_analyzers(analyzers):
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def add_arguments_to_parser(parser):
metavar='ANALYZER',
required=False,
choices=analyzer_types.supported_analyzers,
default=argparse.SUPPRESS,
default=None,
help="Run analysis only with the analyzers "
"specified. Currently supported analyzers "
"are: " +
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/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def add_arguments_to_parser(parser):
metavar='ANALYZER',
required=False,
choices=analyzer_types.supported_analyzers,
default=argparse.SUPPRESS,
default=None,
help="Run analysis only with the analyzers "
"specified. Currently supported analyzers "
"are: " +
Expand Down
5 changes: 2 additions & 3 deletions analyzer/codechecker_analyzer/cmd/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,8 @@ def __print_checker_config(args: argparse.Namespace):
if args.output_format == 'custom':
args.output_format = 'rows'

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

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

0 comments on commit 99fcaf4

Please sign in to comment.