Skip to content

Commit

Permalink
Run ConfigHandler construction before version check
Browse files Browse the repository at this point in the history
Also, make sure the first thing we do is to parse the 'executable'
config.
  • Loading branch information
Szelethus committed Oct 20, 2023
1 parent 2713597 commit a50b4f6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
3 changes: 1 addition & 2 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def perform_analysis(args, skip_handlers, actions, metadata_tool,

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

Expand All @@ -164,8 +165,6 @@ def perform_analysis(args, skip_handlers, actions, metadata_tool,
"the Clang Static Analyzer.")
return

config_map = analyzer_types.build_config_handlers(args, analyzers)

no_checker_analyzers = \
[a for a in analyzers if not __has_enabled_checker(config_map[a])]
for analyzer in no_checker_analyzers:
Expand Down
32 changes: 16 additions & 16 deletions analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,22 @@ def construct_config_handler(cls, args):

handler = config_handler.ClangSAConfigHandler(environ)

handler.checker_config = []

# TODO: This extra "isinstance" check is needed for
# CodeChecker analyzers --analyzer-config. This command also runs
# this function in order to construct a config handler.
if 'analyzer_config' in args and \
isinstance(args.analyzer_config, list):
for cfg in args.analyzer_config:
if cfg.analyzer == cls.ANALYZER_NAME:
if cfg.option == 'executable':
analyzer_base.handle_analyzer_executable_from_config(
cfg.analyzer, cfg.value)
LOG.info(f"Using clangsa binary '{cfg.value}'")
continue
handler.checker_config.append(f"{cfg.option}={cfg.value}")

handler.report_hash = args.report_hash \
if 'report_hash' in args else None

Expand Down Expand Up @@ -692,8 +708,6 @@ def construct_config_handler(cls, args):
handler.set_checker_enabled(
ReturnValueCollector.checker_collect, False)

handler.checker_config = []

# TODO: This extra "isinstance" check is needed for
# CodeChecker checkers --checker-config. This command also runs
# this function in order to construct a config handler.
Expand All @@ -703,18 +717,4 @@ def construct_config_handler(cls, args):
handler.checker_config.append(
f"{cfg.checker}:{cfg.option}={cfg.value}")

# TODO: This extra "isinstance" check is needed for
# CodeChecker analyzers --analyzer-config. This command also runs
# this function in order to construct a config handler.
if 'analyzer_config' in args and \
isinstance(args.analyzer_config, list):
for cfg in args.analyzer_config:
if cfg.analyzer == cls.ANALYZER_NAME:
if cfg.option == 'executable':
analyzer_base.handle_analyzer_executable_from_config(
cfg.analyzer, cfg.value)
LOG.info(f"Using clangsa binary '{cfg.value}'")
continue
handler.checker_config.append(f"{cfg.option}={cfg.value}")

return handler
36 changes: 18 additions & 18 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,24 +575,6 @@ def construct_config_handler(cls, args):
handler.report_hash = args.report_hash \
if 'report_hash' in args else None

# FIXME We cannot get the resource dir from the clang-tidy binary,
# therefore we get a sibling clang binary which of clang-tidy.
# TODO Support "clang-tidy -print-resource-dir" .
try:
with open(args.tidy_args_cfg_file, 'r', encoding='utf-8',
errors='ignore') as tidy_cfg:
handler.analyzer_extra_arguments = \
re.sub(r'\$\((.*?)\)',
env.replace_env_var(args.tidy_args_cfg_file),
tidy_cfg.read().strip())
handler.analyzer_extra_arguments = \
shlex.split(handler.analyzer_extra_arguments)
except IOError as ioerr:
LOG.debug_analyzer(ioerr)
except AttributeError as aerr:
# No clang tidy arguments file was given in the command line.
LOG.debug_analyzer(aerr)

analyzer_config = {}
# TODO: This extra "isinstance" check is needed for
# CodeChecker analyzers --analyzer-config. This command also
Expand All @@ -613,6 +595,24 @@ def construct_config_handler(cls, args):
if not analyzer_config:
analyzer_config["HeaderFilterRegex"] = ".*"

# FIXME We cannot get the resource dir from the clang-tidy binary,
# therefore we get a sibling clang binary which of clang-tidy.
# TODO Support "clang-tidy -print-resource-dir" .
try:
with open(args.tidy_args_cfg_file, 'r', encoding='utf-8',
errors='ignore') as tidy_cfg:
handler.analyzer_extra_arguments = \
re.sub(r'\$\((.*?)\)',
env.replace_env_var(args.tidy_args_cfg_file),
tidy_cfg.read().strip())
handler.analyzer_extra_arguments = \
shlex.split(handler.analyzer_extra_arguments)
except IOError as ioerr:
LOG.debug_analyzer(ioerr)
except AttributeError as aerr:
# No clang tidy arguments file was given in the command line.
LOG.debug_analyzer(aerr)

# If both --analyzer-config and -config (in --tidyargs) is given then
# these need to be merged. Since "HeaderFilterRegex" has a default
# value in --analyzer-config, we take --tidyargs stronger so user can
Expand Down
5 changes: 5 additions & 0 deletions analyzer/codechecker_analyzer/analyzers/gcc/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def construct_config_handler(cls, args):
isinstance(args.analyzer_config, list):
for cfg in args.analyzer_config:
if cfg.analyzer == cls.ANALYZER_NAME:
if cfg.option == 'executable':
analyzer_base.handle_analyzer_executable_from_config(
cfg.analyzer, cfg.value)
LOG.info(f"Using gcc binary '{cfg.value}'")
continue
analyzer_config[cfg.option].append(cfg.value)

handler.analyzer_config = analyzer_config
Expand Down

0 comments on commit a50b4f6

Please sign in to comment.