Skip to content

Commit 2cc6285

Browse files
dkruppbruntib
authored andcommitted
Configuring the env for some additional tools
1 parent a613f75 commit 2cc6285

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

analyzer/codechecker_analyzer/analyzers/clangsa/ctu_autodetection.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import subprocess
1414

1515
from codechecker_common.logger import get_logger
16+
from codechecker_analyzer import analyzer_context
1617
from codechecker_analyzer import host_check
1718
from codechecker_analyzer.analyzers.clangsa import version
1819

@@ -75,7 +76,7 @@ def ctu_mapping(clang_version_info):
7576
return None, None
7677

7778

78-
def invoke_binary_checked(binary_path, args=None, environ=None):
79+
def invoke_binary_checked(binary_path, args=None):
7980
"""
8081
Invoke the binary with the specified args, and return the output if the
8182
command finished running with zero exit code. Return False otherwise.
@@ -91,6 +92,7 @@ def invoke_binary_checked(binary_path, args=None, environ=None):
9192
args = args or []
9293
invocation = [binary_path]
9394
invocation.extend(args)
95+
environ = analyzer_context.get_context().get_env_for_bin(binary_path)
9496
try:
9597
output = subprocess.check_output(
9698
invocation,
@@ -123,7 +125,7 @@ def __init__(self, analyzer_binary, environ):
123125
return
124126

125127
analyzer_version = invoke_binary_checked(
126-
self.__analyzer_binary, ['--version'], self.environ)
128+
self.__analyzer_binary, ['--version'])
127129

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

225-
return invoke_binary_checked(tool_path, ['-version'], self.environ) \
227+
return invoke_binary_checked(tool_path, ['-version']) \
226228
is not False
227229

228230
@property
@@ -233,8 +235,7 @@ def is_on_demand_ctu_available(self):
233235
"""
234236

235237
analyzer_options = invoke_binary_checked(
236-
self.__analyzer_binary, ['-cc1', '-analyzer-config-help'],
237-
self.environ)
238+
self.__analyzer_binary, ['-cc1', '-analyzer-config-help'])
238239

239240
if analyzer_options is False:
240241
return False

analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ def get_diagtool_bin():
143143
return None
144144

145145

146-
def get_warnings(environment=None):
146+
def get_warnings():
147147
"""
148148
Returns list of warning flags by using diagtool.
149149
"""
150150
diagtool_bin = get_diagtool_bin()
151+
environment = analyzer_context.get_context().get_env_for_bin(diagtool_bin)
151152

152153
if not diagtool_bin:
153154
return []
@@ -285,7 +286,7 @@ def get_analyzer_checkers(cls):
285286

286287
checker_description.extend(
287288
("clang-diagnostic-" + warning, "")
288-
for warning in get_warnings(environ))
289+
for warning in get_warnings())
289290

290291
cls.__analyzer_checkers = checker_description
291292

@@ -315,6 +316,9 @@ def get_analyzer_config(cls):
315316
"""
316317
Return the analyzer configuration with all checkers enabled.
317318
"""
319+
if not cls.analyzer_binary():
320+
return []
321+
318322
try:
319323
result = subprocess.check_output(
320324
[cls.analyzer_binary(), "-dump-config", "-checks=*"],

analyzer/codechecker_analyzer/analyzers/cppcheck/analyzer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,13 @@ def get_analyzer_checkers(cls):
244244
"""
245245
Return the list of the supported checkers.
246246
"""
247+
if not cls.analyzer_binary():
248+
return []
247249
command = [cls.analyzer_binary(), "--errorlist"]
248-
250+
environ = analyzer_context.get_context().get_env_for_bin(
251+
command[0])
249252
try:
250-
result = subprocess.check_output(command)
253+
result = subprocess.check_output(command, env=environ)
251254
return parse_checkers(result)
252255
except (subprocess.CalledProcessError) as e:
253256
LOG.error(e.stderr)

analyzer/codechecker_analyzer/analyzers/gcc/analyzer.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def construct_analyzer_cmd(self, result_handler):
5555
# unforeseen exceptions where a general catch is justified?
5656
config = self.config_handler
5757

58+
if not Gcc.analyzer_binary():
59+
return None
5860
# We don't want GCC do start linking, but -fsyntax-only stops the
5961
# compilation process too early for proper diagnostics generation.
6062
analyzer_cmd = [Gcc.analyzer_binary(), '-fanalyzer', '-c',
@@ -91,10 +93,14 @@ def get_analyzer_checkers(cls):
9193
Return the list of the supported checkers.
9294
"""
9395
command = [cls.analyzer_binary(), "--help=warning"]
96+
if not cls.analyzer_binary():
97+
return []
98+
environ = analyzer_context.get_context().get_env_for_bin(
99+
command[0])
94100
checker_list = []
95101

96102
try:
97-
output = subprocess.check_output(command)
103+
output = subprocess.check_output(command, env=environ)
98104

99105
# Still contains the help message we need to remove.
100106
for entry in output.decode().split('\n'):

analyzer/codechecker_analyzer/cmd/analyzers.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,22 @@ def main(args):
118118

119119
if args.dump_config:
120120
binary = context.analyzer_binaries.get(args.dump_config)
121+
environ = analyzer_context.get_context().get_env_for_bin(
122+
binary)
121123

122124
if args.dump_config == 'clang-tidy':
123125
subprocess.call([binary, '-dump-config', '-checks=*'],
124-
encoding="utf-8", errors="ignore")
126+
encoding="utf-8", errors="ignore",
127+
env=environ)
125128
elif args.dump_config == 'clangsa':
126129
ret = subprocess.call([binary,
127130
'-cc1',
128131
'-analyzer-checker-option-help',
129132
'-analyzer-checker-option-help-alpha'],
130133
stderr=subprocess.PIPE,
131134
encoding="utf-8",
132-
errors="ignore")
135+
errors="ignore",
136+
env=environ)
133137

134138
if ret:
135139
# This flag is supported from Clang 9.

0 commit comments

Comments
 (0)