diff --git a/analyzer/codechecker_analyzer/analyzer_context.py b/analyzer/codechecker_analyzer/analyzer_context.py index c55c66dabf..1e0ad74a68 100644 --- a/analyzer/codechecker_analyzer/analyzer_context.py +++ b/analyzer/codechecker_analyzer/analyzer_context.py @@ -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 @@ -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=':/path/to/bin1;" + ":/path/to/bin2'") + sys.exit(1) + return env_var_bins + def __get_package_config(self): """ Get package configuration. """ pckg_config_file = os.path.join( @@ -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) diff --git a/analyzer/codechecker_analyzer/cmd/analyze.py b/analyzer/codechecker_analyzer/cmd/analyze.py index 3ea27ecb63..9251c3a221 100644 --- a/analyzer/codechecker_analyzer/cmd/analyze.py +++ b/analyzer/codechecker_analyzer/cmd/analyze.py @@ -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=':/path/to/bin1;" - ":/path/to/bin2'") - sys.exit(1) - - def main(args): """ Perform analysis on the given inputs. Possible inputs are a compilation @@ -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.