Skip to content

CMake executable cannot be a script #4037

Closed

Description

@JVApen

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 };

Activity

  1. emmenlau commented on Sep 4, 2024

    @emmenlau

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

  2. gcampbell-msft commented on Sep 4, 2024

    @gcampbell-msft
    Collaborator

    JVApen Mario Emmenlauer (@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!

  3. JVApen commented on Sep 5, 2024

    @JVApen
    Author

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

  4. emmenlau commented on Sep 5, 2024

    @emmenlau

    Dear Garrett Campbell (@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 %*
    
  5. gcampbell-msft commented on Sep 5, 2024

    @gcampbell-msft
    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?

  6. gcampbell-msft commented on Sep 5, 2024

    @gcampbell-msft
    Collaborator

    Mario Emmenlauer (@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?

  7. emmenlau commented on Sep 5, 2024

    @emmenlau

    Dear Garrett Campbell (@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?

  8. gcampbell-msft commented on Sep 5, 2024

    @gcampbell-msft
    Collaborator

    JVApen Mario Emmenlauer (@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)

  9. emmenlau commented on Sep 5, 2024

    @emmenlau

    Dear Garrett Campbell (@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!

  10. kuch3n commented on Sep 10, 2024

    @kuch3n

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

  11. dbaeumer commented on Sep 13, 2024

    @dbaeumer
    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.

  12. emmenlau commented on Sep 13, 2024

    @emmenlau

    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 Dirk BÃĪumer (@dbaeumer) for the hint! However the regression has already been fixed. Do you think that the fix requires more attention?

  13. dbaeumer commented on Sep 16, 2024

    @dbaeumer
    Member

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

  14. emmenlau commented on Sep 16, 2024

    @emmenlau

    Dear Dirk BÃĪumer (@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?

  15. dbaeumer commented on Sep 16, 2024

    @dbaeumer
    Member

    Correct.

  16. moved this from To Do to In Progress in CMake Toolson Oct 1, 2024
  17. moved this from In Progress to Completed in CMake Toolson Oct 10, 2024
  18. Yingzi1234 commented on Feb 21, 2025

    @Yingzi1234

    This issue has been fixed on CMake Tools version 1.20.50(pre-release), you can get the details below. Thank you!

    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buga bug in the product

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions