diff --git a/analyzer/tools/build-logger/src/ldlogger-hooks.c b/analyzer/tools/build-logger/src/ldlogger-hooks.c index f735638e3d..430a259422 100644 --- a/analyzer/tools/build-logger/src/ldlogger-hooks.c +++ b/analyzer/tools/build-logger/src/ldlogger-hooks.c @@ -46,19 +46,12 @@ the program to execute, so we're not reusing CC_LOGGER_CALL_EXEC. \ */ \ tryLog(path, argv); \ - /* \ - Note that envp is not passed through (which would be the environment that \ - that the process will be spawned it), but is replaced by environ, which is \ - a global variable that stores our environment. We added quite a few \ - variables into it, and for some reason, they are not present in envp. \ - */ \ - (void)envp; \ CALL_ORIGINAL_FN(funName_, \ (pid_t *restrict, const char *restrict, \ const posix_spawn_file_actions_t *restrict, \ const posix_spawnattr_t *restrict, char *const[restrict], \ char *const[restrict]), \ - pid, path, file_actions, attrp, argv, environ) + pid, path, file_actions, attrp, argv, envp) // FIXME: What does this function do? Does it do anything? Does it *need* to do // the thing we are not sure it does? diff --git a/analyzer/tools/build-logger/tests/unit/test_paths.py b/analyzer/tools/build-logger/tests/unit/test_paths.py index 5cfa9c5ae8..bd16d5f4bc 100644 --- a/analyzer/tools/build-logger/tests/unit/test_paths.py +++ b/analyzer/tools/build-logger/tests/unit/test_paths.py @@ -3,6 +3,7 @@ import glob import os import shutil +import subprocess import tempfile from typing import Mapping from . import BasicLoggerTest, empty_env, REPO_ROOT @@ -78,19 +79,47 @@ def test_compiler_path2(self): actual_json = self.read_actual_json() self.assertEqual(actual_json, "[\n]") + def test_envp_forwarding(self): + """ + Test if environment variables are forwarded by make command properly + while logging. + """ + self.tearDown() # Cleanup the previous iteration. + self.setUp() + + # This test project has an exported environment variable defined in the + # Makefile. This should keep its values even during the build of + # submodules: make -C . + test_proj = \ + os.path.join(os.path.dirname(__file__), 'makefile_test_proj') + + logger_env = self.get_envvars() + logger_env["CC_LOGGER_GCC_LIKE"] = "gcc" + + subprocess.Popen( + ['make'], + env=logger_env, + cwd=test_proj).communicate() + + self.assert_json( + command=f"gcc main.c -o /dev/null -DHELLO=world", + file="main.c", + directory=os.path.join(test_proj, 'dir') + ) + def test_simple(self): """The most simple case: just compile a single file.""" logger_env = self.get_envvars() file = self.source_file binary = self.binary_file self.assume_successful_command( - ["g++", file, "-Werror", "-o", binary], logger_env + ["gcc", file, "-Werror", "-o", binary], logger_env ) self.assume_successful_command( [binary], env=empty_env, outs="--VARIABLE--" ) self.assert_json( - command=f"g++ {file} -Werror -o {binary}", + command=f"gcc {file} -Werror -o {binary}", file=file, )