Author: Pavel Labath Date: 2020-04-01T11:20:13+02:00 New Revision: 0ec88d031ad5abcd78068a8377494ec84ea6a1e1
URL: https://github.com/llvm/llvm-project/commit/0ec88d031ad5abcd78068a8377494ec84ea6a1e1 DIFF: https://github.com/llvm/llvm-project/commit/0ec88d031ad5abcd78068a8377494ec84ea6a1e1.diff LOG: [lldb] Inherit host environment when running shell commands Summary: On most hosts we were running shell commands with an empty environment. The only exception was windows, which was inheriting the host enviroment mostly by accident. Running the commands in an empty environment does not sound like a sensible default, so this patch changes Host::RunShellCommand to inherit the host environment. This impacts both commands run via SBPlatform::Run (in case of host platforms), as well as the "platform shell" CLI command. Reviewers: jingham, friss Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77123 Added: lldb/test/API/python_api/sbplatform/Makefile lldb/test/API/python_api/sbplatform/TestSBPlatform.py lldb/test/API/python_api/sbplatform/main.cpp Modified: lldb/source/Host/common/Host.cpp Removed: ################################################################################ diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index b2485393cd6a..8a6af3881a0f 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -501,6 +501,8 @@ Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir, launch_info.SetArguments(args, first_arg_is_executable); } + launch_info.GetEnvironment() = Host::GetEnvironment(); + if (working_dir) launch_info.SetWorkingDirectory(working_dir); llvm::SmallString<64> output_file_path; diff --git a/lldb/test/API/python_api/sbplatform/Makefile b/lldb/test/API/python_api/sbplatform/Makefile new file mode 100644 index 000000000000..99998b20bcb0 --- /dev/null +++ b/lldb/test/API/python_api/sbplatform/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py new file mode 100644 index 000000000000..4735f6ea3b49 --- /dev/null +++ b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py @@ -0,0 +1,22 @@ +"""Test the SBPlatform APIs.""" + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + +class SBPlatformAPICase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @add_test_categories(['pyapi']) + def test_run(self): + self.build() + plat = lldb.SBPlatform.GetHostPlatform() + + os.environ["MY_TEST_ENV_VAR"]="SBPlatformAPICase.test_run" + def cleanup(): + del os.environ["MY_TEST_ENV_VAR"] + self.addTearDownHook(cleanup) + cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out")) + self.assertTrue(plat.Run(cmd).Success()) + self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", cmd.GetOutput()) diff --git a/lldb/test/API/python_api/sbplatform/main.cpp b/lldb/test/API/python_api/sbplatform/main.cpp new file mode 100644 index 000000000000..9f2aca26ab8d --- /dev/null +++ b/lldb/test/API/python_api/sbplatform/main.cpp @@ -0,0 +1,8 @@ +#include <cstdlib> +#include <cstdio> + +int main() { + printf("MY_TEST_ENV_VAR=%s\n", getenv("MY_TEST_ENV_VAR")); + + return 0; +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits