microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.48k stars 454 forks source link

cmakeExecutable doesn't check condition #4178

Open JVApen opened 1 week ago

JVApen commented 1 week ago

Brief Issue Summary

{
    "version": 6,
    "configurePresets": [
        {
            "name": "Windows",
            "cmakeExecutable": "C:/Program Files/cmake/3.30.2/bin/cmake.exe",
            "condition": {
                "type": "equals",
                "lhs": "${hostSystemName}",
                "rhs": "Windows"
            }
        },
        {
            "name": "Linux",
            "cmakeExecutable": "/opt/cmake/3.30.2/bin/cmake.exe",
            "condition": {
                "type": "equals",
                "lhs": "${hostSystemName}",
                "rhs": "Linux"
            }
        }
    ]
}

When using 1 CMakePresets.json with the above content in it, 1 of the systems fails to use the right cmake executable.

In this case, I'm using a windows machine to remote SSH into a linux device.

CMake Tools Diagnostics

`
{
  "os": "linux",
  "vscodeVersion": "1.95.3",
  "cmtVersion": "1.19.52",
  "configurations": [
    {
      "folder": "/home/project/main",
      "cmakeVersion": "unknown",
      "configured": false,
      "generator": "unknown",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}
``

Debug Log

`
[cmakeExecutable] CMake executable not found in cache. Checking again.
[proc] Executing command: C:\Program Files\cmake\3.30.2\bin\cmake.exe --version
[proc] The command: C:\Program Files\cmake\3.30.2\bin\cmake.exe --version failed with error: Error: spawn C:\Program Files\cmake\3.30.2\bin\cmake.exe ENOENT
[proc] Executing command: C:\Program Files\cmake\3.30.2\bin\cmake.exe -E capabilities
[proc] The command: C:\Program Files\cmake\3.30.2\bin\cmake.exe -E capabilities failed with error: Error: spawn C:\Program Files\cmake\3.30.2\bin\cmake.exe ENOENT
...
`

Additional Information

It looks like the parsing of the presets takes the first occurrence of cmakeExecutable it finds without considering the condition.

Yingzi1234 commented 5 days ago

@gcampbell-msft When there are Windows and Linux options in the CMakePresets.json file, typing the command cmake: select configure preset will only bring up one option: Linux and the Windows option will not appear We cannot reproduce this problem. Could you provide us with some help?

@JVApen Could you give us some additional information? For example, screenshots or reproduced items that will facilitate our investigation of your issue. Thank you very much for your help, please let us know if you have any concerns!

JVApen commented 5 days ago

@Yingzi1234 : In the real use-case, I am making use of includes. I'll see if I can create a working reproduction. I do have holidays coming up, so it might take a while before I have this.

gcampbell-msft commented 3 days ago

@Yingzi1234 You are correct, and this is expected, only those presets that are available on the machine that is being used should be populated. In order to repro with certain presets, the condition should be made to be true, either by opening the project on the correct OS, or by removing the condition as a way to test