Skip to content

Commit 0af12f1

Browse files
committed
The execution environment must be package internal for internal binaries and original for external binaries
1 parent b7ab4af commit 0af12f1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

analyzer/codechecker_analyzer/analyzers/analyzer_base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,15 @@ def construct_result_handler(self, buildaction, report_output,
105105
def analyze(self, analyzer_cmd, res_handler, proc_callback=None, env=None):
106106
"""
107107
Run the analyzer.
108+
Don't specify the env unless really needed!
109+
The package internal or original env will be selected
110+
based on the location of the called binary.
108111
"""
109112
LOG.debug('Running analyzer ...')
110113

111114
LOG.debug_analyzer('\n%s',
112115
' '.join([shlex.quote(x) for x in analyzer_cmd]))
113116

114-
if not env:
115-
env = analyzer_context.get_context().get_env_for_bin(
116-
analyzer_cmd[0])
117-
118117
res_handler.analyzer_cmd = analyzer_cmd
119118
try:
120119
ret_code, stdout, stderr \
@@ -149,6 +148,10 @@ def run_proc(command, cwd=None, proc_callback=None, env=None):
149148
"""
150149
Just run the given command and return the return code
151150
and the stdout and stderr outputs of the process.
151+
152+
Don't specify the env unless really needed!
153+
The package internal or original env will be selected
154+
based on the location of the called binary.
152155
"""
153156

154157
def signal_handler(signum, _):
@@ -161,6 +164,10 @@ def signal_handler(signum, _):
161164

162165
signal.signal(signal.SIGINT, signal_handler)
163166

167+
if not env:
168+
env = analyzer_context.get_context().get_env_for_bin(
169+
command[0])
170+
164171
LOG.debug('\nexecuting:%s\n', command)
165172
LOG.debug('\nENV:\n')
166173
LOG.debug(env)

analyzer/tests/unit/test_env_var.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from codechecker_analyzer import analyzer_context
1919
from codechecker_analyzer.analyzers.gcc.analyzer import Gcc
20+
from codechecker_analyzer.analyzers.analyzer_base import SourceAnalyzer
2021
from codechecker_analyzer.buildlog import log_parser
2122

2223

@@ -156,6 +157,13 @@ def test_cc_analyzer_internal_env(self):
156157
env_txt = str(clang_env)
157158
self.assertTrue(env_txt.find("internal_package_lib") == -1)
158159

160+
#env is an external binary (/usr/bin/env),
161+
#so the internal_package_lib must not be in the
162+
#LD_LIBRARY_PATH.
163+
(_, out_txt, _) = SourceAnalyzer.run_proc("env")
164+
self.assertTrue(out_txt.find("internal_package_lib") == -1)
165+
self.assertTrue(out_txt.find("usr/bin") != -1)
166+
159167
os.remove(layout_cfg_file)
160168
os.remove(packaged_clang_file)
161169
os.rmdir(cc_bin_dir)

0 commit comments

Comments
 (0)