Fix env vars not injected on WSL / remote targets (GoLand)#261
Open
sedovserge wants to merge 1 commit into
Open
Fix env vars not injected on WSL / remote targets (GoLand)#261sedovserge wants to merge 1 commit into
sedovserge wants to merge 1 commit into
Conversation
Runs on a target (WSL, SSH remote) go through the Targets API and build a TargetedCommandLine, bypassing the legacy patchCommandLine(GeneralCommandLine) hook EnvFile relied on - so no variables reached the process. Inject the variables in the executor-level patchExecutor hook, which does fire for target runs, via GoExecutor#withUserDefinedEnvironment. Only the delta over the parent (host) environment is added, so host-only variables (PATH, ProgramFiles, ...) are not leaked into the target. The local path is unchanged. Fixes ashald#258
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #258. On WSL (and other remote targets) EnvFile variables never reach the Go process.
Root cause
For a local run GoLand builds a
GeneralCommandLineand calls the legacyGoRunConfigurationExtension.patchCommandLine(..., GeneralCommandLine, ...)hook that EnvFileoverrides. For a target run (WSL, SSH remote) GoLand goes through the Targets API and builds a
TargetedCommandLineBuilderinstead — the legacy hook is never invoked, so EnvFile injects nothing.Verified on GoLand 2025.2.6.1: with logging in all three
GoRunConfigurationExtensionhooks, a WSL runfires only
patchExecutorand the targetpatchCommandLine(TargetedCommandLineBuilder, ...); the legacypatchCommandLine(GeneralCommandLine, ...)does not fire.Fix
Override the executor-level
patchExecutorhook (which fires for both local and target runs) and inject theresolved variables via
GoExecutor#withUserDefinedEnvironment— the same channel the native run-configEnvironment field uses, which is known to reach the target.
To avoid leaking host-only variables (
PATH,ProgramFiles,windir, ...) into the target environment(e.g. Linux under WSL, where a Windows
PATHwould be harmful), only the delta over the parent/hostenvironment is injected. Injection is limited to
CommandLineType.RUN.The local path is left untouched: the legacy
patchCommandLine(GeneralCommandLine)still runs and, on localruns, overwrites the command-line environment as before — so local behaviour is unchanged.
Scope
This addresses the GoLand module only. #258 also reports the same class of problem for PyCharm over SSH;
that would need an analogous change in the respective product module and is out of scope here.
Testing
.env: variables now reach the process andthe service starts; injected set contains the service variables and none of the Windows host variables.