Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyze] Handle no analyzer use cases #3194

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ def perform_analysis(args, skip_handler, context, actions, metadata_tool,

analyzers = args.analyzers if 'analyzers' in args \
else analyzer_types.supported_analyzers
analyzers, _ = analyzer_types.check_supported_analyzers(
analyzers, errored = analyzer_types.check_supported_analyzers(
analyzers, context)
analyzer_types.check_available_analyzers(analyzers, errored)

ctu_collect = False
ctu_analyze = False
Expand Down Expand Up @@ -366,6 +367,8 @@ def perform_analysis(args, skip_handler, context, actions, metadata_tool,
end_time = time.time()
LOG.info("Analysis length: %s sec.", end_time - start_time)

analyzer_types.print_unsupported_analyzers(errored)

metadata_tool['timestamps'] = {'begin': start_time,
'end': end_time}

Expand Down
4 changes: 2 additions & 2 deletions analyzer/codechecker_analyzer/analyzer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def __populate_analyzers(self):
env_path = analyzer_env['PATH'] if analyzer_env else None
compiler_binary = find_executable(value, env_path)
if not compiler_binary:
LOG.warning("'%s' binary can not be found in your PATH!",
value)
LOG.debug("'%s' binary can not be found in your PATH!",
value)
continue

self.__analyzers[name] = os.path.realpath(compiler_binary)
Expand Down
30 changes: 26 additions & 4 deletions analyzer/codechecker_analyzer/analyzers/analyzer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import os
import re
import sys

from codechecker_analyzer import env
from codechecker_common.logger import get_logger
Expand Down Expand Up @@ -114,6 +115,27 @@ def is_z3_refutation_capable(context):
analyzer_env)


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 "
"execute analysis with it: '%s'. Please check your "
"'PATH' environment variable and the "
"'config/package_layout.json' file!",
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_supported_analyzers(analyzers, context):
"""
Checks the given analyzers in the current context for their executability
Expand All @@ -137,16 +159,16 @@ def check_supported_analyzers(analyzers, context):
for analyzer_name in analyzers:
if analyzer_name not in supported_analyzers:
failed_analyzers.add((analyzer_name,
"Analyzer unsupported by CodeChecker."))
"Analyzer unsupported by CodeChecker!"))
continue

# Get the compiler binary to check if it can run.
available_analyzer = True
analyzer_bin = analyzer_binaries.get(analyzer_name)
if not analyzer_bin:
failed_analyzers.add((analyzer_name,
"Failed to detect analyzer binary."))
available_analyzer = False
"Failed to detect analyzer binary!"))
continue
elif not os.path.isabs(analyzer_bin):
# If the analyzer is not in an absolute path, try to find it...
found_bin = supported_analyzers[analyzer_name].\
Expand All @@ -171,7 +193,7 @@ def check_supported_analyzers(analyzers, context):
# Analyzers unavailable under absolute paths are deliberately a
# configuration problem.
failed_analyzers.add((analyzer_name,
"Cannot execute analyzer binary."))
"Cannot execute analyzer binary!"))
available_analyzer = False

if available_analyzer:
Expand Down
7 changes: 5 additions & 2 deletions analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,11 @@ def main(args):
analyzer_clang_binary = \
context.analyzer_binaries.get(
clangsa.analyzer.ClangSA.ANALYZER_NAME)
analyzer_clang_version = clangsa.version.get(analyzer_clang_binary,
analyzer_env)

analyzer_clang_version = None
if analyzer_clang_binary:
analyzer_clang_version = clangsa.version.get(analyzer_clang_binary,
analyzer_env)

actions, skipped_cmp_cmd_count = log_parser.parse_unique_log(
compile_commands,
Expand Down
7 changes: 2 additions & 5 deletions analyzer/codechecker_analyzer/cmd/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def main(args):
working_analyzers, errored = analyzer_types.check_supported_analyzers(
args.analyzers,
context)
analyzer_types.check_available_analyzers(working_analyzers, errored)

analyzer_environment = env.extend(context.path_env_extra,
context.ld_lib_path_extra)
Expand Down Expand Up @@ -400,8 +401,4 @@ def format_guideline(guideline):
if rows:
print(twodim.to_str(args.output_format, header, rows))

for analyzer_binary, reason in errored:
LOG.error("Failed to get checkers for '%s'!"
"The error reason was: '%s'", analyzer_binary, reason)
LOG.error("Please check your installation and the "
"'config/package_layout.json' file!")
analyzer_types.print_unsupported_analyzers(errored)