Skip to content

Commit de11c90

Browse files
committed
Adding environment dependent handling of the anlayzer version detection
1 parent 99fcaf4 commit de11c90

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

analyzer/codechecker_analyzer/analyzers/analyzer_types.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def check_supported_analyzers(analyzers):
159159
"""
160160

161161
context = analyzer_context.get_context()
162-
check_env = context.cc_env
163162

164163
analyzer_binaries = context.analyzer_binaries
165164

@@ -182,7 +181,8 @@ def check_supported_analyzers(analyzers):
182181
elif not os.path.isabs(analyzer_bin):
183182
# If the analyzer is not in an absolute path, try to find it...
184183
found_bin = supported_analyzers[analyzer_name].\
185-
resolve_missing_binary(analyzer_bin, check_env)
184+
resolve_missing_binary(analyzer_bin,
185+
context.get_analyzer_env(analyzer_name))
186186

187187
# found_bin is an absolute path, an executable in one of the
188188
# PATH folders.
@@ -201,7 +201,8 @@ def check_supported_analyzers(analyzers):
201201
# Check version compatibility of the analyzer binary.
202202
if analyzer_bin:
203203
analyzer = supported_analyzers[analyzer_name]
204-
error = analyzer.is_binary_version_incompatible(check_env)
204+
error = analyzer.is_binary_version_incompatible(
205+
context.get_analyzer_env(analyzer_name))
205206
if error:
206207
failed_analyzers.add((analyzer_name,
207208
f"Incompatible version: {error} "
@@ -211,7 +212,9 @@ def check_supported_analyzers(analyzers):
211212
available_analyzer = False
212213

213214
if not analyzer_bin or \
214-
not host_check.check_analyzer(analyzer_bin, check_env):
215+
not host_check.check_analyzer(analyzer_bin,
216+
context.
217+
get_analyzer_env(analyzer_name)):
215218
# Analyzers unavailable under absolute paths are deliberately a
216219
# configuration problem.
217220
failed_analyzers.add((analyzer_name,

analyzer/codechecker_analyzer/analyzers/clangsa/ctu_manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from yaml import Dumper
2121

2222
from codechecker_common.logger import get_logger
23+
from codechecker_analyzer import analyzer_context
24+
2325

2426
from codechecker_merge_clang_extdef_mappings.merge_clang_extdef_mappings \
2527
import merge
@@ -127,10 +129,15 @@ def generate_ast(triple_arch, action, source, config):
127129
except OSError:
128130
pass
129131

132+
context = analyzer_context.get_context()
133+
env = context.get_analyzer_env("clangsa")
130134
cmdstr = ' '.join(cmd)
131135
LOG.debug_analyzer("Generating AST using '%s'", cmdstr)
136+
LOG.debug_analyzer("ENV:")
137+
LOG.debug_analyzer(env)
132138
ret_code, _, err = \
133-
analyzer_base.SourceAnalyzer.run_proc(cmd, action.directory)
139+
analyzer_base.SourceAnalyzer.run_proc(cmd, action.directory, None,
140+
env)
134141

135142
if ret_code != 0:
136143
LOG.error("Error generating AST.\n\ncommand:\n\n%s\n\nstderr:\n\n%s",

analyzer/codechecker_analyzer/host_check.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,22 @@ def check_analyzer(compiler_bin, env):
2828
clang_version_cmd = [compiler_bin, '--version']
2929
LOG.debug_analyzer(' '.join(clang_version_cmd))
3030
try:
31-
res = subprocess.call(
31+
proc = subprocess.Popen(
3232
clang_version_cmd,
3333
env=env,
3434
stdout=subprocess.PIPE,
3535
stderr=subprocess.PIPE,
3636
encoding="utf-8",
3737
errors="ignore")
38-
if not res:
38+
out, err = proc.communicate()
39+
LOG.debug_analyzer("return code %d", proc.returncode)
40+
if not proc.returncode:
3941
return True
40-
42+
LOG.debug_analyzer("ENV:")
43+
LOG.debug_analyzer(env)
4144
LOG.debug_analyzer('Failed to run: "%s"', ' '.join(clang_version_cmd))
45+
LOG.debug_analyzer('stdout: %s', out)
46+
LOG.debug_analyzer('stderr: %s', err)
4247
return False
4348

4449
except OSError as oerr:

0 commit comments

Comments
 (0)