Skip to content

Fix empty vs. unset environment variables on Windows.#1997

Open
BillyONeal wants to merge 4 commits intomicrosoft:mainfrom
BillyONeal:audit-environment-variables
Open

Fix empty vs. unset environment variables on Windows.#1997
BillyONeal wants to merge 4 commits intomicrosoft:mainfrom
BillyONeal:audit-environment-variables

Conversation

@BillyONeal
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal commented Apr 15, 2026

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.

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.
Copilot AI review requested due to automatic review settings April 15, 2026 00:19
@BillyONeal BillyONeal changed the title Fix empty vs. nonexistent environment variables on Windows. Fix empty vs. unset environment variables on Windows. Apr 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 "" vs nullopt and 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().

BillyONeal and others added 2 commits April 14, 2026 17:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 15, 2026 01:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants