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 executable cannot be a script #4037

Open
JVApen opened this issue Sep 2, 2024 · 15 comments · May be fixed by #4044
Open

CMake executable cannot be a script #4037

JVApen opened this issue Sep 2, 2024 · 15 comments · May be fixed by #4044
Assignees
Labels
bug a bug in the product
Milestone

Comments

@JVApen
Copy link

JVApen commented Sep 2, 2024

Brief Issue Summary

The option "cmake.cmakePath" cannot refer to a script.
For example: (cmake.bat)

C:\path\to\cmake.exe $*

(In the real case, this is more complex as this triggers some remote execution)

Output:

[cmakeExecutable] CMake executable not found in cache. Checking again.
[proc] Executing command: C:/path/to/cmake.cmd --version
[proc] Executing command: C:/path/to/cmake.cmd -E capabilities

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

I already did some reverse engineering on the code.
proc.ts has a method called execute which accepts some options. If options.shell is set to true, it should enable the shell option as described in https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows
However cmakeExecutable.ts in the method getCMakeExecutableInformation doesn't pass this option. const execOpt: proc.ExecutionOptions = { showOutputOnError: true };

@emmenlau
Copy link

emmenlau commented Sep 4, 2024

This is a relevant issue for us too, and a regression over some previous version (unsure which version).

@gcampbell-msft
Copy link
Collaborator

@JVApen @emmenlau If you could provide some more information about this issue, that would be great. For example, repro steps to reproduce this, or a small exacmple of a script you're using.

Looking at the code, nothing between version 1.18.44 and 1.19.50 was changed when checking the cmake.exe, so I wouldn't expect that it's causing an issue. Therefore, more investigation may be needed and any repro steps can help with that. Thanks!

@JVApen
Copy link
Author

JVApen commented Sep 5, 2024

@gcampbell-msft : see my first event, simple CMD file with c:\path\to\cmake.exe $* should be sufficient to reproduce

@emmenlau
Copy link

emmenlau commented Sep 5, 2024

Dear @gcampbell-msft ,
indeded, @JVApen is correct. A reproducer can be achieved with a simple CMD script like:

@ECHO OFF

REM We do other steps here as required, for example modify cmake settings, or change PATH, or change directory, ...
REM Then execute cmake:

C:\path\to\cmake.exe %*

@gcampbell-msft
Copy link
Collaborator

@JVApen When trying to reproduce with these steps: #4037 (comment), I notice that the "Bad CMake executable" popup appears in 1.18.44 as well. Do you also see this?

@gcampbell-msft
Copy link
Collaborator

@emmenlau @JVApen I actually see this issue as far back as 1.14.34. Is there something I'm missing in the repro? Or is this correct?

@emmenlau
Copy link

emmenlau commented Sep 5, 2024

Dear @gcampbell-msft , sadly I can not say which version worked for me before. We have an isolated system that is not updated too frequently. I would think that the last working version was from about 6 months ago (both VSCode and all extensions), but I may be off a bit there.

In case that helps, we're using the same scripting "trick" on Linus and MacOS every day, and there it works flawless. These systems are updated very frequently, and used more than our Windows environment. So the problem is Windows-only, and I would think it has to do with not allowing nodejs to spawn bat files. I can only say this worked at some point, for at least a few months, maybe the better part of a year.

Does the suggestion from @JVApen help, about https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows?

@gcampbell-msft
Copy link
Collaborator

@JVApen @emmenlau I've tracked the issue down. This didn't come from a CMake Tools update, but rather a VS Code update. In July, VS Code updated to 1.92 which now uses Node 20. This contains a breaking change for spawn, which we weren't aware of.

Could you please test the vsix (after modifying the file extension from .zip to .vsix) from here?
#4044 (comment)

@emmenlau
Copy link

emmenlau commented Sep 5, 2024

Dear @gcampbell-msft , awesome!!! This indeed fixes the issue!!!

Just to confirm, the linked extension will identify itself as v1.13.0 (pre-release) which is a bit surprising because VSCode will complain that a newer version was already installed. But aside from this small detail, the linked cmake tools extension works and successfully executes by wrapper bat script on Windows!

Regression fixed!

@gcampbell-msft gcampbell-msft linked a pull request Sep 5, 2024 that will close this issue
@Yingzi1234 Yingzi1234 added bug a bug in the product and removed triage labels Sep 6, 2024
@kuch3n
Copy link

kuch3n commented Sep 10, 2024

This fix would allow converting windows paths to cygwins posix paths, too: #4038 Or even load shells for Cygwin, MSys etc.

@dbaeumer
Copy link
Member

Small hint in case it help. There was a breaking change in NodeJS that it requires to pass shell: true if you want to execute a command script. If not pass the execution fails.

@emmenlau
Copy link

Small hint in case it help. There was a breaking change in NodeJS that it requires to pass shell: true if you want to execute a command script. If not pass the execution fails.

Thanks @dbaeumer for the hint! However the regression has already been fixed. Do you think that the fix requires more attention?

@dbaeumer
Copy link
Member

@emmenlauif it works you are fine. The shell: true results in an exception which you would be able to observe.

@emmenlau
Copy link

Dear @dbaeumer , so just to be double sure: You are saying that the fix is fine as it is, and nothing else needs to be done, correct?

@dbaeumer
Copy link
Member

Correct.

@gcampbell-msft gcampbell-msft added this to the 1.20 milestone Oct 1, 2024
@gcampbell-msft gcampbell-msft self-assigned this Oct 1, 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
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

6 participants