-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
implement env vars in settings (#2785) #9116
implement env vars in settings (#2785) #9116
Conversation
std::wstring value(static_cast<size_t>(size), L'\0'); | ||
if (GetEnvironmentVariableW(key.c_str(), value.data(), size) > 0) | ||
{ | ||
// Documentation (https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getenvironmentvariablew) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely, I've missed something here?
Misspellings found, please review:
To accept these changes, run the following commands from this repository on this branch
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbage and it relates to a binary-ish string, please add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
Misspellings found, please review:
To accept these changes, run the following commands from this repository on this branch
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbage and it relates to a binary-ish string, please add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
Any ideas why the CI is failing with:
The solution is building locally fine and I can't find a reference to 'Host.DLL.vcxproj'? |
@christapley You may need to merge main |
Ok, thanks @skyline75489. This will require a force push for the changes in this pr, so apologies in advance for that. |
* use StringMap as a container * recursively resolve ${env:NAME} vars in values in the StringMap or in the process' environment * implement some tests
0439f5b
to
113d873
Compare
I don't think this is quite ready yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry I didn't reply faster. I was in the middle of reviewing the code, but didn't manage to finish. If you are planning on finishing this up, here's the feedback I had so far. It's mostly nits, but might be helpful anyways
@@ -21,6 +21,9 @@ Author(s): | |||
#include "../inc/cppwinrt_utils.h" | |||
#include "JsonUtils.h" | |||
#include <DefaultSettings.h> | |||
#include <winrt/impl/Windows.Foundation.Collections.2.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to include this header directly here - we should be able to get winrt::Windows::Foundation::Collections::StringMap
from the Windows.Foundation.Collections.h
in pch.h
@@ -21,6 +21,9 @@ Author(s): | |||
#include "../inc/cppwinrt_utils.h" | |||
#include "JsonUtils.h" | |||
#include <DefaultSettings.h> | |||
#include <winrt/impl/Windows.Foundation.Collections.2.h> | |||
|
|||
using namespace winrt::Windows::Foundation::Collections; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is gonna sound like a nit, but it's usually best practice to avoid using namespace ...
statements in headers. It results in everyone who includes that header automatically using
that namespace, which can be probelmatic. I know it's annoying that you need to have the whole namespaced name in the property declaration, but ¯\_(ツ)_/¯
#include <winrt/impl/Windows.Foundation.Collections.2.h> | ||
|
||
using namespace winrt::Windows::Foundation::Collections; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same deal in this header
namespace | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think we need an extra namespace here. Declaring the function as static
will keep it internal to this file, and that should be good enough
for (auto it = view.First(); it.HasCurrent(); it.MoveNext()) | ||
{ | ||
const std::wstring key((*it).Key()); | ||
resolvedEnvMap.Insert(key, ResolveEnvironmentVariableValue(key, rawEnvMap, {})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this last parameter is always {}
, and we're never using it after the function is called, should we just remove it from the function signature and declare it internal to the function above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used to detect self or circular references when resolving the environment variables so it needs to be updated and passed in as a parameter (not reference). I can default it in the function declaration so it is not needed to be specified here if that helps?
Thanks for the feedback, I will apply these to the next pr when the feature is more complete. |
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Wrote and ran the unit tests, tested manually to see environment variables were available.