Skip to content

Commit

Permalink
Configurability of analyzer versions
Browse files Browse the repository at this point in the history
The modification can be used to validate the version of each analyzer. The user can specify all desired analyzers after the --analyzers flag, as was possible before. Also, the exact version number can be typed for each analyzer, separated by an '==' char. For example: 'CodeChecker analyze compile_commands.json -o reports --analyzers clangsa==14.0.0 cppcheck==2.7'. If the version number was not the same as in the current environment, error message would be logged and the system exit would trigger. The user can enumerate the analyzers with or without versions, for example: 'CodeChecker analyze compile_commands.json -o reports --analyzers clangsa=14.0.0 cppcheck'.
  • Loading branch information
cservakt committed Sep 15, 2023
1 parent 420cda9 commit 17cb7d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def perform_analysis(args, skip_handlers, actions, metadata_tool,
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
ctu_dir = ''
Expand Down
34 changes: 23 additions & 11 deletions analyzer/codechecker_analyzer/analyzers/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,35 @@ def is_ignore_conflict_supported():
def print_unsupported_analyzers(errored):
""" Print error messages which occured during analyzer detection. """
for analyzer_binary, reason in errored:
LOG.warning("Analyzer '%s' is enabled but CodeChecker is failed to "
LOG.error("Analyzer '%s' is enabled but CodeChecker is failed to "
"execute analysis with it: '%s'. Please check your "
"'PATH' environment variable, the "
"'config/package_layout.json' file "
"and the --analyzers flag!",
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 on the user machine
or wrong analyzer given.
"""
if analyzers and (not errored
or 'analyzers' not in args
or not any("analyzer" in e[1].lower() for e in errored)
):
return

print_unsupported_analyzers(errored)
LOG.error("Failed to run command because no analyzers can be found on "
"your machine!")
sys.exit(1)
elif 'analyzers' in args and errored \
and any("analyzer" in e[1].lower() for e in errored):
print_unsupported_analyzers(errored)
LOG.error("Failed to run command because one or more given analyzers "
"cannot be found on your machine!")
sys.exit(1)
else:
print_unsupported_analyzers(errored)
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 Expand Up @@ -194,12 +206,12 @@ def check_supported_analyzers(analyzers):
bin_version = StrictVersion(str(analyzer.version_info()))
requested_version = StrictVersion(requested_version)
if requested_version != bin_version:
LOG.warning(
LOG.error(
f"Given version: {requested_version}, found version "
f"for {analyzer_name} analyzer: {bin_version}"
)
failed_analyzers.add((analyzer_name,
"Wrong version given."))
"Wrong analyzer version given."))
available_analyzer = False
if not analyzer.version_compatible():
failed_analyzers.add((analyzer_name,
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 @@ -527,7 +527,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 17cb7d8

Please sign in to comment.