Skip to content
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

Customize the environment variables when launch the target in the terminal #3478

Closed
1m188 opened this issue Dec 2, 2023 · 7 comments
Closed
Assignees
Labels
bug a bug in the product Feature: debug/launch suggested Temporary label for internal tracking for suggested bugs to pick up in spare time.
Milestone

Comments

@1m188
Copy link

1m188 commented Dec 2, 2023

Brief Issue Summary

When using the launch target feature of the cmake plugin, the cmake plugin will start a terminal and then run the target directly.

But I'd like to be able to plug in some custom configurations after launching the terminal like environment variables, etc. (because there may be multiple environment variables with the same key in different projects, and I don't want them to pollute the global environment variables).

Admittedly, we can manually add environment variables to the terminal and reuse that terminal afterward, but the problem is that the terminal needs to be manually configured after each launch of vscode, which is tedious. (In my personal case, in order to run the Qt program, I need to temporarily add the corresponding bin directory to the system path in the terminal every time I start the terminal, which is troublesome)

I didn't find the relevant settings to fix this, I hope to be able to add this feature in the subsequent updates of the cmake plugin, thanks.

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

@github-actions github-actions bot added the triage label Dec 2, 2023
@gcampbell-msft
Copy link
Collaborator

Thanks for the suggestion, marking this as a request and putting it on our backlog. Thanks!

@gcampbell-msft gcampbell-msft added enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: debug/launch and removed triage labels Dec 4, 2023
@github-project-automation github-project-automation bot moved this to Triage Needed in CMake Tools Dec 4, 2023
@gcampbell-msft gcampbell-msft moved this from Triage Needed to Pending Prioritization in CMake Tools Dec 4, 2023
@gcampbell-msft gcampbell-msft added this to the Backlog milestone Dec 4, 2023
@vakokako
Copy link

vakokako commented Dec 6, 2023

Seconding this, would be much appreciated!

@AlMar-Devel
Copy link

Finally found, thanks to this question and answer, that this feature is not enabled!

I've been stumbling for a couple of days trying to give my executable a chance to use a specific project environment in Launch mode, without any success. Please take into account that this is an essential feature when the program uses 3rd party DLLs: the PATH (Windows) or LD_LIBRARY_PATH (Linux) must be set accordingly for the program execution.

According to the documentation (https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-settings.md), "cmake.environment" in settings.json should be used for running also, but the fact is that it is only applied when debugging.
Curiously, "cmake.debugConfig" is applied for both cases (at least "args" are used for Launch and Debug modes).

@gcampbell-msft
Copy link
Collaborator

@AlMar-Devel Do you have a repro project? I have tested this for a similar issue #3687 and I wasn't able to reproduce the issue. We add the configure environment, which for presets and for kits should include the cmake.environment setting.

@mcwindy
Copy link

mcwindy commented Apr 25, 2024

I can reproduce that cmake.environment & cmake.debugConfig.environment & cmake.testEnvironment all apply to debugging projects and does not apply to launching projects from terminal. In my case, i'm going to set QT_QPA_PLATFORM=xcb. Is it intended?

@gcampbell-msft gcampbell-msft added bug a bug in the product and removed enhancement an enhancement to the product that is either not present or an improvement to an existing feature labels May 13, 2024
@gcampbell-msft gcampbell-msft modified the milestones: Backlog, On Deck May 13, 2024
@gcampbell-msft gcampbell-msft added the suggested Temporary label for internal tracking for suggested bugs to pick up in spare time. label May 13, 2024
@gcampbell-msft gcampbell-msft modified the milestones: On Deck, 1.19 Jun 25, 2024
@gcampbell-msft gcampbell-msft moved this from Pending Prioritization to Ready to be Assigned in CMake Tools Jun 26, 2024
@jophippe jophippe moved this from Ready to be Assigned to To Do in CMake Tools Jul 8, 2024
@jophippe jophippe moved this from To Do to In Progress in CMake Tools Jul 15, 2024
@jophippe
Copy link
Contributor

Hi @1m188 @AlMar-Devel @mcwindy,
As indicated by the mentioned PR, I think the root cause of this issue is how we re-use the same terminal for multiple launches, which means changes to the environment are not applied in the re-used terminal. Just to confirm that is the issue, I attached a vsix of cmake-tools with this change included. If one of you can install this vsix by renaming the .zip extension to .vsix and running the "Install from VSIX" command in the Extensions Pane, then testing that either cmake.Environment or cmake.debugConfig.environment variables are applied during a Terminal Launch, that would be great.
Thanks!

cmake-tools.zip

@jophippe
Copy link
Contributor

I completed the PR, so the fix should be available in the next release. Please open a new issue if the problem persists. Thanks!

@github-project-automation github-project-automation bot moved this from In Progress to Completed in CMake Tools Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product Feature: debug/launch suggested Temporary label for internal tracking for suggested bugs to pick up in spare time.
Projects
Status: Completed
Development

No branches or pull requests

6 participants