microsoft / microsoft/vscode-cmake-tools
Environment variables not being picked up during preset configuration
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
### Brief Issue Summary
When configuring a project with a configuration preset, `$env{}` is not picking up environment variables defined in extension setting `cmake.environment`. Same result when setting `cmake.configureEnvironment`. In the reproducer, I would expect the output of `message(${CACHE_VARIABLE_FROM_PRESET})` to be `hello/preset`, but it just becomes `/preset`. Is this a bug or expected behavior? From https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html:
> $env{}
Environment variable with name . The variable name may not be an empty string. If the variable is defined in the environment field, that value is used instead of the value from the parent environment. If the environment variable is not defined, this evaluates as an empty string.
I would expect the extension setting `cmake.environment` in this case to define the "parent" environment of the preset execution, as the environment field mentioned in the quote above is referencing to the `environment` field within the preset itself (the environment variables defined in the `environment` field in the preset file are being picked up correctly by the way). Since when I run `AN_ENV_VARIABLE=hello cmake --preset ninja` directly from CLI, behavior is as expected (output of message is `hello/preset`).
VSCode version: 1.96.4
Extension version: 1.19.52
CMake version: 3.26.4
This may be a duplicate of the issue partially described in #4218
Attached small vscode workspace reproducer:
[cmake-preset-bug.zip](https://github.com/user-attachments/files/18534820/cmake-preset-bug.zip)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached VS Code workspace reproducer and compare the extension's preset execution using cmake.environment or cmake.configureEnvironment with direct `AN_ENV_VARIABLE=hello cmake --preset ninja`. Read the handling of CMake preset environment variables and review related issue #4218. Done means `$env{AN_ENV_VARIABLE}` expands to `hello` through the extension, matching the CLI result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100