Skip to content

[Swift REPL] Inherit the environment for the Swift REPL #9859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,18 @@ lldb::REPLSP SwiftREPL::CreateInstanceFromDebugger(Status &err,
// breakpoint above, it better
// say it is internal

lldb_private::ProcessLaunchInfo launch_info;
llvm::StringRef target_settings_argv0 = target_sp->GetArg0();

if (target_sp->GetDisableASLR())
launch_info.GetFlags().Set(eLaunchFlagDisableASLR);

if (target_sp->GetDisableSTDIO())
launch_info.GetFlags().Set(eLaunchFlagDisableSTDIO);
lldb_private::ProcessLaunchInfo launch_info =
target_sp->GetProcessLaunchInfo();

// FIXME: Why is this necessary? Document or change once we know the answer.
llvm::StringRef target_settings_argv0 = target_sp->GetArg0();
if (!target_settings_argv0.empty()) {
launch_info.GetArguments().AppendArgument(target_settings_argv0);
launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), false);
} else {
launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
}

launch_info.GetEnvironment() = target_sp->GetTargetEnvironment();
debugger.SetAsyncExecution(false);
err = target_sp->Launch(launch_info, nullptr);
debugger.SetAsyncExecution(true);
Expand Down
10 changes: 10 additions & 0 deletions lldb/test/Shell/SwiftREPL/EnvVars.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test inheriting environment variables in the REPL.
// REQUIRES: system-darwin
// REQUIRES: swift

// RUN: FOO=foo %lldb --repl -O 'settings set target.inherit-env true' < %s 2>&1 \
// RUN: | FileCheck %s

import Foundation
ProcessInfo.processInfo.environment["FOO"]
// CHECK: $R0: String? = "foo"