Skip to content

Commit

Permalink
Configuring the env for some additional tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrupp authored and bruntib committed Sep 13, 2024
1 parent a613f75 commit 2cc6285
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import subprocess

from codechecker_common.logger import get_logger
from codechecker_analyzer import analyzer_context
from codechecker_analyzer import host_check
from codechecker_analyzer.analyzers.clangsa import version

Expand Down Expand Up @@ -75,7 +76,7 @@ def ctu_mapping(clang_version_info):
return None, None


def invoke_binary_checked(binary_path, args=None, environ=None):
def invoke_binary_checked(binary_path, args=None):
"""
Invoke the binary with the specified args, and return the output if the
command finished running with zero exit code. Return False otherwise.
Expand All @@ -91,6 +92,7 @@ def invoke_binary_checked(binary_path, args=None, environ=None):
args = args or []
invocation = [binary_path]
invocation.extend(args)
environ = analyzer_context.get_context().get_env_for_bin(binary_path)
try:
output = subprocess.check_output(
invocation,
Expand Down Expand Up @@ -123,7 +125,7 @@ def __init__(self, analyzer_binary, environ):
return

analyzer_version = invoke_binary_checked(
self.__analyzer_binary, ['--version'], self.environ)
self.__analyzer_binary, ['--version'])

if analyzer_version is False:
LOG.debug('Failed to invoke command to get Clang version!')
Expand Down Expand Up @@ -222,7 +224,7 @@ def is_ctu_capable(self):
if not tool_path:
return False

return invoke_binary_checked(tool_path, ['-version'], self.environ) \
return invoke_binary_checked(tool_path, ['-version']) \
is not False

@property
Expand All @@ -233,8 +235,7 @@ def is_on_demand_ctu_available(self):
"""

analyzer_options = invoke_binary_checked(
self.__analyzer_binary, ['-cc1', '-analyzer-config-help'],
self.environ)
self.__analyzer_binary, ['-cc1', '-analyzer-config-help'])

if analyzer_options is False:
return False
Expand Down
8 changes: 6 additions & 2 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ def get_diagtool_bin():
return None


def get_warnings(environment=None):
def get_warnings():
"""
Returns list of warning flags by using diagtool.
"""
diagtool_bin = get_diagtool_bin()
environment = analyzer_context.get_context().get_env_for_bin(diagtool_bin)

if not diagtool_bin:
return []
Expand Down Expand Up @@ -285,7 +286,7 @@ def get_analyzer_checkers(cls):

checker_description.extend(
("clang-diagnostic-" + warning, "")
for warning in get_warnings(environ))
for warning in get_warnings())

cls.__analyzer_checkers = checker_description

Expand Down Expand Up @@ -315,6 +316,9 @@ def get_analyzer_config(cls):
"""
Return the analyzer configuration with all checkers enabled.
"""
if not cls.analyzer_binary():
return []

try:
result = subprocess.check_output(
[cls.analyzer_binary(), "-dump-config", "-checks=*"],
Expand Down
7 changes: 5 additions & 2 deletions analyzer/codechecker_analyzer/analyzers/cppcheck/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,13 @@ def get_analyzer_checkers(cls):
"""
Return the list of the supported checkers.
"""
if not cls.analyzer_binary():
return []
command = [cls.analyzer_binary(), "--errorlist"]

environ = analyzer_context.get_context().get_env_for_bin(
command[0])
try:
result = subprocess.check_output(command)
result = subprocess.check_output(command, env=environ)
return parse_checkers(result)
except (subprocess.CalledProcessError) as e:
LOG.error(e.stderr)
Expand Down
8 changes: 7 additions & 1 deletion analyzer/codechecker_analyzer/analyzers/gcc/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def construct_analyzer_cmd(self, result_handler):
# unforeseen exceptions where a general catch is justified?
config = self.config_handler

if not Gcc.analyzer_binary():
return None
# We don't want GCC do start linking, but -fsyntax-only stops the
# compilation process too early for proper diagnostics generation.
analyzer_cmd = [Gcc.analyzer_binary(), '-fanalyzer', '-c',
Expand Down Expand Up @@ -91,10 +93,14 @@ def get_analyzer_checkers(cls):
Return the list of the supported checkers.
"""
command = [cls.analyzer_binary(), "--help=warning"]
if not cls.analyzer_binary():
return []
environ = analyzer_context.get_context().get_env_for_bin(
command[0])
checker_list = []

try:
output = subprocess.check_output(command)
output = subprocess.check_output(command, env=environ)

# Still contains the help message we need to remove.
for entry in output.decode().split('\n'):
Expand Down
8 changes: 6 additions & 2 deletions analyzer/codechecker_analyzer/cmd/analyzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,22 @@ def main(args):

if args.dump_config:
binary = context.analyzer_binaries.get(args.dump_config)
environ = analyzer_context.get_context().get_env_for_bin(
binary)

if args.dump_config == 'clang-tidy':
subprocess.call([binary, '-dump-config', '-checks=*'],
encoding="utf-8", errors="ignore")
encoding="utf-8", errors="ignore",
env=environ)
elif args.dump_config == 'clangsa':
ret = subprocess.call([binary,
'-cc1',
'-analyzer-checker-option-help',
'-analyzer-checker-option-help-alpha'],
stderr=subprocess.PIPE,
encoding="utf-8",
errors="ignore")
errors="ignore",
env=environ)

if ret:
# This flag is supported from Clang 9.
Expand Down

0 comments on commit 2cc6285

Please sign in to comment.