Skip to content
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

Reload environment variables by default; add setting to disable #14999

Merged
merged 11 commits into from
Mar 17, 2023

Conversation

ianjoneill
Copy link
Contributor

@ianjoneill ianjoneill commented Mar 16, 2023

Summary of the Pull Request

Adds a global setting compatibility.reloadEnvironmentVariables with a default value of true. When set, during connection creation a new environment block will be generated to ensure it has the latest environment variables.

Validation Steps Performed

Manually tested - see video in the first second comment.

PR Checklist

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Task It's a feature request, but it doesn't really need a major design. Area-User Interface Issues pertaining to the user interface of the Console or Terminal Product-Terminal The new Windows Terminal. labels Mar 16, 2023
@github-actions

This comment has been minimized.

@ianjoneill
Copy link
Contributor Author

ReloadEnvironmentVariables.mp4

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow you're right that was easy.

My tiny nit is that we've been discussing internally on re-aligning some of the experimental settings we have as compatibility flags instead. That's not something you'd have possibly known, and I'm pretty sure my initial writeup called for experimental. too.

Honestly this is gonna be such goodness that I want to just hit ✅ anyways

src/cascadia/TerminalSettingsModel/MTSMSettings.h Outdated Show resolved Hide resolved
doc/cascadia/profiles.schema.json Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/IControlSettings.idl Outdated Show resolved Hide resolved
@ianjoneill
Copy link
Contributor Author

ianjoneill commented Mar 16, 2023

Umm why am I getting static analysis failures on code I haven't touched?

Edit: I see #15002 has been opened to address this.

@ianjoneill
Copy link
Contributor Author

Now the build's failing due to #14581.

{
envMap.Insert(key, value);
}
}
envMap.Insert(L"WT_PROFILE_ID", guidWString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the simplicity of this, but I am a little bit concerned about what happens after we hand this environment block off.

We produce a new env block here, painstakingly inserting it into envMap... and then ConptyConnection uses EnvironmentVariableMapW to generate a new map based on the current process environment and inserts the contents of envMap from here into it.

In brief... what we will get is a hybrid of Terminal's spawning environment and the current environment. As well, we will probably end up parsing the entire env twice.

Should we move this down to ConptyConnection (worm the boolean down in through the valueset for all I mind, ha) and make sure we do not call UpdateEnvironmentMapW?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 16, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 17, 2023
@zadjii-msft
Copy link
Member

Huh, moving that down to connection made audit run on env.h, which it does not like. If you don't want to fix them now, I'm okay with that, there's a way to disable audit mode from yelling about an include. You could add that around the include and then we could just fix that in post.

Probably like this, with a push/pop

// Some of the interactivity classes pulled in by ServiceLocator.hpp are not
// yet audit-safe, so for now we'll need to disable a bunch of warnings.
#pragma warning(disable : 26432)
#pragma warning(disable : 26440)
#pragma warning(disable : 26455)

// We end up including ApiMessage.h somehow, which uses nameless unions
#pragma warning(disable : 4201)

Or you could fix the warnings now :P

    35>C:\a\_work\1\s\src\inc\til\env.h(346): error C26490: Don't use reinterpret_cast (type.1). 
    35>C:\a\_work\1\s\src\inc\til\env.h(352): error C26490: Don't use reinterpret_cast (type.1). 
    35>C:\a\_work\1\s\src\inc\til\env.h(489): error C26440: Function 'til::env::is_path_var' can be declared 'noexcept' (f.6). 
    35>C:\a\_work\1\s\src\inc\til\env.h(521): error C26481: Don't use pointer arithmetic. Use span instead (bounds.1). 
    35>C:\a\_work\1\s\src\inc\til\env.h(506): error C26481: Don't use pointer arithmetic. Use span instead (bounds.1). 
    35>C:\a\_work\1\s\src\inc\til\env.h(526): error C26455: Default constructor should not throw. Declare it 'noexcept' (f.6). 
    35>C:\a\_work\1\s\src\inc\til\env.h(574): error C26440: Function 'til::env::as_map' can be declared 'noexcept' (f.6). 
    35>C:\a\_work\1\s\src\cascadia\TerminalConnection\ConptyConnection.cpp(106): error C26478: Don't use std::move on constant variables. (es.56). 

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful. thanks for the quick patch!

@DHowett
Copy link
Member

DHowett commented Mar 17, 2023

Hey @lhecker, would you be willing to fix the audit failures on-branch so we can quick merge Ian's work?

@github-actions

This comment has been minimized.

@lhecker
Copy link
Member

lhecker commented Mar 17, 2023

I've fixed the audit mode issues, as well as some others. I've also made some further improvements to til::env along the way.

However now that I understand how til::env was intended to be used, I have to confess that I'd be happier with a solution like ConEmu's. Theirs is clearly superior as it's simpler and more performant. It only reloads on WM_SETTINGCHANGE, just like the feature request asked. Because of this I'm not sure if the exact feature request of #1125 is solved with this PR just yet. Alternatively we should create a followup issue to address this, as the code that til::env runs is rather heavy and there's almost never any reason to run it. (After all, how often do environment variables change anyways?)

@zadjii-msft
Copy link
Member

In the name of incremental progress - merge now, and fast-follow with a PR for "cache a static 'base' env block and only reload it on WM_SETTINGCHANGE"?

@ianjoneill
Copy link
Contributor Author

I had actually fixed some of the audit issues this morning - rather than just ignoring them :)

@DHowett
Copy link
Member

DHowett commented Mar 17, 2023

Ah, sorry to override/duplicate your effort @ianjoneill!

@DHowett DHowett changed the title Add a setting to reload environment variables Reload environment variables by default; add setting to disable Mar 17, 2023
@DHowett DHowett merged commit 5166148 into microsoft:main Mar 17, 2023
@Ares9323
Copy link

Ares9323 commented Sep 7, 2023

ReloadEnvironmentVariables.mp4

I've tried to look for "experimental.reloadEnviromentVariables": true, or similar names both in the regular windows terminal and in the preview version but I wasn't able to find anything, has it been implemented differently or elsewhere?

@zadjii-msft
Copy link
Member

What are you trying to accomplish exactly? The setting added as compatibility.reloadEnvironmentVariables, in the globals, but it's also enabled by default in 1.18.

@Ares9323
Copy link

Ares9323 commented Sep 8, 2023

What are you trying to accomplish exactly? The setting added as compatibility.reloadEnvironmentVariables, in the globals, but it's also enabled by default in 1.18.

Thank you for your answer, I tried looking for both experimental.reloadEnviromentVariables and compatibility.reloadEnvironmentVariables in the settings.json but nothing was showing up in the autocompletion, so I wrongly assumed that the option was missing (Screenshot from WT preview 1.18.14):
image

The default terminal was obviously not working because it hasn't been updated to 1.18 yet:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
5 participants