Skip to content

Commit

Permalink
Move the implementation to Context
Browse files Browse the repository at this point in the history
  • Loading branch information
Szelethus committed Oct 24, 2023
1 parent fb981b2 commit 5ebdd4d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
38 changes: 38 additions & 0 deletions analyzer/codechecker_analyzer/analyzer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pathlib import Path

from codechecker_common import logger
from codechecker_analyzer.arg import analyzer_binary
from codechecker_common.checker_labels import CheckerLabels
from codechecker_common.singleton import Singleton
from codechecker_common.util import load_json
Expand Down Expand Up @@ -90,6 +91,38 @@ def __init__(self):
self.__populate_analyzers()
self.__populate_replacer()


def __parse_CC_ANALYZER_BIN(self):
env_var_bins = {}
if 'CC_ANALYZER_BIN' in self.__analyzer_env:
had_error = False
for value in self.__analyzer_env['CC_ANALYZER_BIN'].split(';'):
try:
analyzer_name, path = analyzer_binary(value)
except argparse.ArgumentTypeError as e:
LOG.error(e)
had_error = True
continue

if not os.path.isfile(path):
LOG.error(f"'{path}' is not a path to an analyzer binary "
"given to CC_ANALYZER_BIN!")
had_error = True

if had_error:
continue

LOG.info(f"Using '{path}' for analyzer '{analyzer_name}'")
env_var_bins[analyzer_name] = path

if had_error:
LOG.info("The value of CC_ANALYZER_BIN should be in the"
"format of "
"CC_ANALYZER_BIN='<analyzer1>:/path/to/bin1;"
"<analyzer2>:/path/to/bin2'")
sys.exit(1)
return env_var_bins

def __get_package_config(self):
""" Get package configuration. """
pckg_config_file = os.path.join(
Expand Down Expand Up @@ -166,8 +199,13 @@ def __populate_analyzers(self):
if not analyzer_from_path:
analyzer_env = self.analyzer_env

env_var_bin = self.__parse_CC_ANALYZER_BIN()

compiler_binaries = self.pckg_layout.get('analyzers')
for name, value in compiler_binaries.items():
if name in env_var_bin:
self.__analyzers[name] = env_var_bin[name]
continue

if analyzer_from_path:
value = os.path.basename(value)
Expand Down
35 changes: 0 additions & 35 deletions analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,40 +904,6 @@ def __get_result_source_files(metadata):
return result_src_files


def __parse_CC_ANALYZER_BIN():
context = analyzer_context.get_context()
if 'CC_ANALYZER_BIN' in context.analyzer_env:
had_error = False
for value in context.analyzer_env['CC_ANALYZER_BIN'].split(';'):
try:
analyzer_name, path = analyzer_binary(value)
except argparse.ArgumentTypeError as e:
LOG.error(e)
had_error = True
continue

if analyzer_name not in analyzer_types.supported_analyzers:
LOG.error(f"Unsupported analyzer_name name '{analyzer_name}' "
"given to CC_ANALYZER_BIN!")
had_error = True
if not os.path.isfile(path):
LOG.error(f"'{path}' is not a path to an analyzer binary "
"given to CC_ANALYZER_BIN!")
had_error = True

if had_error:
continue

LOG.info(f"Using '{path}' for analyzer '{analyzer_name}'")
context.analyzer_binaries[analyzer_name] = path

if had_error:
LOG.info("The value of CC_ANALYZER_BIN should be in the format of "
"CC_ANALYZER_BIN='<analyzer1>:/path/to/bin1;"
"<analyzer2>:/path/to/bin2'")
sys.exit(1)


def main(args):
"""
Perform analysis on the given inputs. Possible inputs are a compilation
Expand Down Expand Up @@ -1020,7 +986,6 @@ def main(args):
ctu_or_stats_enabled = True

context = analyzer_context.get_context()
__parse_CC_ANALYZER_BIN()

# Number of all the compilation commands in the parsed log files,
# logged by the logger.
Expand Down

0 comments on commit 5ebdd4d

Please sign in to comment.