-
Notifications
You must be signed in to change notification settings - Fork 462
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
Environment variables not being picked up during preset configuration #4253
Comments
@TSonono Thanks for the issue. The story is primarily that the design of the extension, as well as CMake Presets, officially supports the "environment" block within the CMakePresets.json configure preset. Therefore, it is much better if you update the "environment" block of the Preset. If the reason you aren't doing this is because you don't want to share this change with other developers, you can utilize a CMakeUserPresets.json file. Secondarily, this does sound like it could be an oversight in our design of the various environment settings provided through VS Code when used with presets. However, those settings were originally created for use with Kits. We primarily are focused on supporting Presets, so we simply made those settings such that they temporarily add to the environment before invoking commands when presets are being used. In short:
Please let me know if you have any other questions or if I can help in any way. Thanks! |
@gcampbell-msft Thanks for your response
I think one could argue that the way I'm using preset follows the standards given the quote I copied earlier from the CMake docs:
and given how the CLI invocation produced the expected behavior. Regarding using CMakeUserPresets.json, while this is the work-around I'm currently employing, it's not super effective depending on how the CMakePresets.json file is constructed. Take an example where you have a base preset that is referencing an |
@TSonono I completely agree, you are using the preset following the standards regarding the use of $env{} variable. However the settings we provide like "and given how the CLI invocation produced the expected behavior". What do you mean by this? The CLI outside of VS Code won't know about the You make a good point regarding the Presets set up. Would an alternative set up work, where you create a CMakeUserPresets.json that inherits the base, and then all of the child presets inherit the CMakeUserPresets.json preset? This would mitigate all of the duplicates and allow you to essentially have a new base (that also inherits the base from CMakePresets.json). However, I do think this is something that we could investigate addressing, so I'll put it on our backlog. Thanks! |
Yes, this is outside of VS Code, I'm just trying to highlight that when using
If I understand you correctly here, you are suggesting that the child presets from CMakePresets.json inherit the preset that I create in CMakeUserPresets.json (the new base) that has inherited the base from CMakePresets.json. This wouldn't work as (from CMake docs) "Presets in CMakePresets.json may not inherit from presets in CMakeUserPresets.json". Or if you are saying that the child presets that should inherit the new base are also in CMakeUserPresets.json, they would still become dupes since they already exist in CMakePresets.json.
Thanks! |
Brief Issue Summary
When configuring a project with a configuration preset,
$env{<environment-variable>}
is not picking up environment variables defined in extension settingcmake.environment
. Same result when settingcmake.configureEnvironment
. In the reproducer, I would expect the output ofmessage(${CACHE_VARIABLE_FROM_PRESET})
to behello/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: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 theenvironment
field within the preset itself (the environment variables defined in theenvironment
field in the preset file are being picked up correctly by the way). Since when I runAN_ENV_VARIABLE=hello cmake --preset ninja
directly from CLI, behavior is as expected (output of message ishello/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
The text was updated successfully, but these errors were encountered: