Skip to content

Commit

Permalink
Fix the execution environment initialization
Browse files Browse the repository at this point in the history
:
The execution environment must be package internal
for internal binaries and original for external binaries
  • Loading branch information
dkrupp committed Jan 22, 2025
1 parent 7be4952 commit a60cdec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
15 changes: 11 additions & 4 deletions analyzer/codechecker_analyzer/analyzers/analyzer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,15 @@ def construct_result_handler(self, buildaction, report_output,
def analyze(self, analyzer_cmd, res_handler, proc_callback=None, env=None):
"""
Run the analyzer.
Don't specify the env unless really needed!
The package internal or original env will be selected
based on the location of the called binary.
"""
LOG.debug('Running analyzer ...')

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

if not env:
env = analyzer_context.get_context().get_env_for_bin(
analyzer_cmd[0])

res_handler.analyzer_cmd = analyzer_cmd
try:
ret_code, stdout, stderr \
Expand Down Expand Up @@ -149,6 +148,10 @@ def run_proc(command, cwd=None, proc_callback=None, env=None):
"""
Just run the given command and return the return code
and the stdout and stderr outputs of the process.
Don't specify the env unless really needed!
The package internal or original env will be selected
based on the location of the called binary.
"""

def signal_handler(signum, _):
Expand All @@ -161,6 +164,10 @@ def signal_handler(signum, _):

signal.signal(signal.SIGINT, signal_handler)

if not env:
env = analyzer_context.get_context().get_env_for_bin(
command[0])

LOG.debug('\nexecuting:%s\n', command)
LOG.debug('\nENV:\n')
LOG.debug(env)
Expand Down
8 changes: 8 additions & 0 deletions analyzer/tests/unit/test_env_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from codechecker_analyzer import analyzer_context
from codechecker_analyzer.analyzers.gcc.analyzer import Gcc
from codechecker_analyzer.analyzers.analyzer_base import SourceAnalyzer
from codechecker_analyzer.buildlog import log_parser


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

# env is an external binary (/usr/bin/env),
# so the internal_package_lib must not be in the
# LD_LIBRARY_PATH.
(_, out_txt, _) = SourceAnalyzer.run_proc("env")
self.assertTrue(out_txt.find("internal_package_lib") == -1)
self.assertTrue(out_txt.find("usr/bin") != -1)

os.remove(layout_cfg_file)
os.remove(packaged_clang_file)
os.rmdir(cc_bin_dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import sqlalchemy as sa



# Revision identifiers, used by Alembic.
revision = 'f59dfe4623fa'
down_revision = '00099e8bc212'
Expand All @@ -23,5 +22,6 @@
def upgrade():
op.execute("DELETE FROM auth_sessions WHERE can_expire")


def downgrade():
pass

0 comments on commit a60cdec

Please sign in to comment.