Fix empty vs. unset environment variables on Windows.#1997
Open
BillyONeal wants to merge 4 commits intomicrosoft:mainfrom
Open
Fix empty vs. unset environment variables on Windows.#1997BillyONeal wants to merge 4 commits intomicrosoft:mainfrom
BillyONeal wants to merge 4 commits intomicrosoft:mainfrom
Conversation
This is a followup to microsoft#1988 where I observe that the same type of defect applies to the "normal" way vcpkg gets environment variables. Ensure that this is preserved correctly, enable use of the small string optimization for wstring, and audit all callers.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes Windows environment-variable handling to distinguish empty values from missing variables, improves the Win32 read path to better leverage std::wstring small-string optimization, and updates call sites accordingly.
Changes:
- Reworked Windows
get_environment_variable()to correctly return""vsnulloptand avoid extra Win32 API calls in common cases. - Added
get_environment_variable_nonempty()and updated selected callers to treat empty-as-missing where appropriate. - Added/adjusted tests to validate env-var roundtrips and SSO-sized reads.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vcpkg/visualstudio.cpp | Treat empty COMNTOOLS as absent and move the string into Path. |
| src/vcpkg/vcpkgcmdarguments.cpp | Adjust env-var retrieval for recursive JSON state parsing. |
| src/vcpkg/commands.integrate.cpp | Switch several uses of $HOME / XDG vars to “nonempty” semantics. |
| src/vcpkg/commands.edit.cpp | Treat empty editor/AppData vars as absent and move strings into paths. |
| src/vcpkg/commands.build.cpp | Refactor env-var lookups; use nonempty proxy env vars. |
| src/vcpkg/binarycaching.cpp | Use nonempty default cache path; tighten GitHub env-var handling. |
| src/vcpkg/base/system.cpp | Implement correct empty vs missing on Windows; add get_environment_variable_nonempty(); update path helpers. |
| src/vcpkg/base/files.cpp | Require nonempty PATH and TMPDIR where used. |
| src/vcpkg-test/util.cpp | Use the new nonempty env-var helper for TEMP. |
| src/vcpkg-test/system.cpp | Add env-var roundtrip tests; tweak test naming. |
| include/vcpkg/base/system.h | Declare get_environment_variable_nonempty(). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
This is a followup to #1988 where I observe that the same type of defect applies to the "normal" way vcpkg gets environment variables.
Ensure that empty vs. unset is preserved correctly, enable use of the small string optimization for wstring, and audit all callers.