Allow inheriting env vars from wt again and other env var changes too#15897
Allow inheriting env vars from wt again and other env var changes too#15897zadjii-msft merged 17 commits intomainfrom
wt again and other env var changes too#15897Conversation
It doesn't actually use it though, unless `reloadEnvVars` isn't set. But now we can _potentially_ use the env vars of the calling WT rather than our own.
| args.AppendCommandLine(_appendCommandLineOption); | ||
| } | ||
|
|
||
| bool inheritEnv = hasCommandline; |
There was a problem hiding this comment.
of interest: default to inherit if we do have a commandline. If the user passed the arg in manually, then use the arg.
| _WindowProperties.VirtualWorkingDirectory(originalVirtualCwd); | ||
| }); | ||
|
|
||
| // Literally the same thing with env vars too |
There was a problem hiding this comment.
All this is exactly the same way VirtualWorkingDirectory (above this) works
| profile.Guid()); | ||
|
|
||
| valueSet.Insert(L"passthroughMode", Windows::Foundation::PropertyValue::CreateBoolean(settings.VtPassthrough())); | ||
| valueSet.Insert(L"reloadEnvironmentVariables", |
There was a problem hiding this comment.
Promoted this to be a proper param to CreateSettings
| _reloadEnvironmentVariables); | ||
| _profileGuid = winrt::unbox_value_or<winrt::guid>(settings.TryLookup(L"profileGuid").try_as<Windows::Foundation::IPropertyValue>(), _profileGuid); | ||
|
|
||
| const auto& initialEnvironment{ winrt::unbox_value_or<winrt::hstring>(settings.TryLookup(L"initialEnvironment").try_as<Windows::Foundation::IPropertyValue>(), L"") }; |
There was a problem hiding this comment.
interesting: get the serialized env block here, and use it to make a til::env that this connection will use as it's basis.
| } | ||
| } | ||
|
|
||
| if (!userSettings.globals->LegacyReloadEnvironmentVariables()) |
There was a problem hiding this comment.
migration logic is here. This seemed like the right place?
There was a problem hiding this comment.
But wait, won't this set Reload to false when in globals it was set to true??
There was a problem hiding this comment.
for example, it's set to true in the constructor. doesn't that mean that everybody's base layer profile will get it set to false???
There was a problem hiding this comment.
Yeah I think we should put all our migration code into this place (if possible).
I think it should be if (globals->HasLegacyReloadEnvironmentVariables()) and then set it to base->ReloadEnvironmentVariables(globals->LegacyReloadEnvironmentVariables()) right?
There was a problem hiding this comment.
Hmm see, I was thinking that the old setting defaulted to true, so the only thing we'd want to migrate is a false. Similarly, the _legacyReloadEnvironmentVariables defaults to true, so the only time we write a false in is if we found a false.
There was a problem hiding this comment.
I added a SerializationTests::DontRoundtripNoReloadEnvVars for a test case 😜
There was a problem hiding this comment.
oh I see. since it's 2-state you're just checking the set value instead of Has. It's an unexpected technique, but it'll do. Thanks.
| const uint32_t showWindow = WI_IsFlagSet(si.dwFlags, STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOW; | ||
|
|
||
| Remoting::CommandlineArgs eventArgs{ { args }, { cwd }, showWindow }; | ||
| const auto currentEnv{ til::env::from_current_environment() }; |
There was a problem hiding this comment.
Yep, it's this easy to package up the calling wt's env vars into a string that we can move around easily.
There was a problem hiding this comment.
this takes care of the embedded null bytes? wow
|
How did this compile in the selfhost build but not in the CI build? |
| vs.Insert(L"commandline", Windows::Foundation::PropertyValue::CreateString(cmdline)); | ||
| vs.Insert(L"startingDirectory", Windows::Foundation::PropertyValue::CreateString(startingDirectory)); | ||
| vs.Insert(L"startingTitle", Windows::Foundation::PropertyValue::CreateString(startingTitle)); | ||
| vs.Insert(L"reloadEnvironmentVariables", Windows::Foundation::PropertyValue::CreateBoolean(reloadEnvironmentVariables)); |
There was a problem hiding this comment.
I can't figure out where this guy is used. The ValueSet is an internal contract between ConptyConnection and ConptyConnection, so I expected to see it in ConptyConnection.
There was a problem hiding this comment.
It's in ConptyConnection::Initialize. That isn't part of the diff because it was already there, I'm just moving the setting into ConptyConnection. Setting it outside, in TerminalPage, is wack.
| } | ||
| } | ||
|
|
||
| if (!userSettings.globals->LegacyReloadEnvironmentVariables()) |
| } | ||
| } | ||
|
|
||
| if (!userSettings.globals->LegacyReloadEnvironmentVariables()) |
There was a problem hiding this comment.
But wait, won't this set Reload to false when in globals it was set to true??
| } | ||
| } | ||
|
|
||
| if (!userSettings.globals->LegacyReloadEnvironmentVariables()) |
There was a problem hiding this comment.
for example, it's set to true in the constructor. doesn't that mean that everybody's base layer profile will get it set to false???
| INHERITABLE_SETTING(Model::TerminalSettings, bool, RightClickContextMenu, false); | ||
| INHERITABLE_SETTING(Model::TerminalSettings, bool, RepositionCursorWithMouse, false); | ||
|
|
||
| INHERITABLE_SETTING(Model::TerminalSettings, bool, ReloadEnvironmentVariables, true); |
There was a problem hiding this comment.
qq: why does the control need to know about this?
There was a problem hiding this comment.
Control doesn't, but the page does. This is in the same weird case as Elevate. It's not a Control setting, but it is a per-control setting.
| const uint32_t showWindow = WI_IsFlagSet(si.dwFlags, STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOW; | ||
|
|
||
| Remoting::CommandlineArgs eventArgs{ { args }, { cwd }, showWindow }; | ||
| const auto currentEnv{ til::env::from_current_environment() }; |
There was a problem hiding this comment.
this takes care of the embedded null bytes? wow
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| T unbox_prop_or(const Windows::Foundation::Collections::ValueSet& blob, std::wstring_view key, T defaultValue) | ||
| { | ||
| return winrt::unbox_value_or<T>(blob.TryLookup(key).try_as<Windows::Foundation::IPropertyValue>(), defaultValue); | ||
| } |
…oo (#15897) This PR is a few things: * part the first: Convert the `compatibility.reloadEnvironmentVariables` setting to a per-profile one. * The settings should migrate it from the user's old global place to the new one. * We also added it to "Profile>Advanced" while I was here. * Adds a new pair of commandline flags to `new-tab` and `split-pane`: `--inheritEnvironment` / `--reloadEnvironment` * On `wt` launch, bundle the entire environment that `wt` was spawned with, and put it into the `Remoting.CommandlineArgs`, and give them to the monarch (and ultimately, down to `TerminalPage` with the `AppCommandlineArgs`). DO THIS ALWAYS. * As a part of this, we’ll default to _reloading_ if there’s no explicit commandline set, and _inheriting_ if there is. * For example, `wt -- cmd` would inherit, and `wt -p “Command Prompt”` would reload.[^1] * This is a little wacky, but we’re trying to separate out the intentions here: * `wt -- cmd` feels like “I want to run cmd.exe (in a terminal tab)”. That feels like the user would _like_ environment variables from the calling process. They’re doing something more manual, so they get more refined control over it. * `wt` (or `wt -p “Command Prompt”`) is more like, “I want to run the Terminal (or, my Command Prompt profile) using whatever the Terminal would normally do”. So that feels more like a situation where it should just reload by default. (Of course, this will respect their settings here) #15496 (comment) has more notes. This is so VERY much plumbing. I'll try to leave comments in the interesting parts. - [x] This is not _all_ of #15496. We're also going to do a `-E foo=bar` arg on top of this. - [x] Tests added/passed - [x] Schema updated [^1]: In both these cases, plus the `environment` setting, of course. (cherry picked from commit 59248de) Service-Card-Id: 90383402 Service-Version: 1.18
This PR is a few things:
compatibility.reloadEnvironmentVariablessetting to a per-profile one.new-tabandsplit-pane:--inheritEnvironment/--reloadEnvironmentwtlaunch, bundle the entire environment thatwtwas spawned with, and put it into theRemoting.CommandlineArgs, and give them to the monarch (and ultimately, down toTerminalPagewith theAppCommandlineArgs). DO THIS ALWAYS.wt -- cmdwould inherit, andwt -p “Command Prompt”would reload.1wt -- cmdfeels like “I want to run cmd.exe (in a terminal tab)”. That feels like the user would like environment variables from the calling process. They’re doing something more manual, so they get more refined control over it.wt(orwt -p “Command Prompt”) is more like, “I want to run the Terminal (or, my Command Prompt profile) using whatever the Terminal would normally do”. So that feels more like a situation where it should just reload by default. (Of course, this will respect their settings here)References and Relevant Issues
#15496 (comment) has more notes.
Detailed Description of the Pull Request / Additional comments
This is so VERY much plumbing. I'll try to leave comments in the interesting parts.
PR Checklist
-E foo=bararg on top of this.Footnotes
In both these cases, plus the
environmentsetting, of course. ↩