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

CMake builds launch target once per every "${command:cmake.launchTargetXXX}" reference #1487

Closed
dslijepcevic opened this issue Oct 14, 2020 · 6 comments
Assignees
Milestone

Comments

@dslijepcevic
Copy link

dslijepcevic commented Oct 14, 2020

Brief Issue Summary

It seems that ${command:cmake.launchTargetDirectory}, ${command:cmake.launchTargetFilename} and ${command:cmake.launchTargetPath} are evaluated more than once when launching a configuration. When cmake.buildBeforeRun is true these commands will ensure that launch target exists before evaluating its properties, but the unfortunate side-effect is that the target will get built once per each command reference. This means that if you reference all 3 of them in a launch configuration in launch.json and then once again within the preLaunchTask in tasks.json, your launch target will get built 6 (six) times! And all 6 times you get full output text as well as extension pop-ups about compiling.

I guess this may have been implemented like this for simplicity, but I would still optimize this down to building the launch target exactly once when cmake.buildBeforeRun is true. I believe it should be possible since CMake Tools is fully in charge of the build process.

cmake-build-multiple-times

@bobbrow
Copy link
Member

bobbrow commented Oct 14, 2020

Yeah, that's pretty bad. It seems that the underlying cause is simply that a function written with the intent to prepare binaries for debug/launch was reused to get the current launch target. If you need a quick fix before we update the extension, you can patch the main.js file under ~/.vscode/extensions/ms-vscode.cmake-tools-1.4.2/dist.

line 42520 would change from chosen = current; to return current;. This will exit the function early and skip configuration/build which is unnecessary for these commands.

image

@dslijepcevic
Copy link
Author

Hmm, with that modification I think it behaves as if cmake.buildBeforeRun is set to false. Oh, and also, I don't see these 3 commands in question documented in a single place anywhere. Even extension's Feature Contributions are showing %% in place of descriptions:

image

@bobbrow
Copy link
Member

bobbrow commented Oct 14, 2020

Sorry about that. I meant to reply back and say that my suggestion wouldn't work for some cases because this function is called in some other scenarios that I didn't realize. I was working on an alternate fix but got pulled away into a few meetings. You'll want to revert any code changes you made in main.js for now.

@bobbrow
Copy link
Member

bobbrow commented Oct 14, 2020

Regarding documentation, I thought we had documented this, but I'm not finding a specific page for it. I think we should update cmake-settings.md and add all the supported commands. I also see some references in debug-launch.md

The %% showing in the feature contributions is a vscode bug. microsoft/vscode#54111

@dslijepcevic
Copy link
Author

Well, we tried, no worries. But while we're at it, I have a suggestion for a new command: ${command:cmake.buildTargetName}. Should not be too hard to implement I think. It would be useful if you want to perform a build using a task (for example, with cmake.buildTask set to true), but you'd still like to use some of CMake Tools's cool features like active build target. Thanks.

@andreeis
Copy link
Contributor

andreeis commented Nov 5, 2020

This should be fixed in CMake Tools 1.5.0 which was published today.
Let us know if you encounter any issues with this release.

@andreeis andreeis closed this as completed Nov 5, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants