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

Incorrect schema version constraint applied to CMakeUserPresets.json #2897

Closed
craigscott-crascit opened this issue Dec 13, 2022 · 3 comments
Closed
Assignees
Labels
bug a bug in the product
Projects
Milestone

Comments

@craigscott-crascit
Copy link

Brief Issue Summary

If a user preset defined in CMakeUserPresets.json inherits from a base preset defined in CMakePresets.json, VS Code incorrectly requires the version field in CMakeUserPresets.json to be no older than the version needed for the base preset.

To reproduce the bug:

  • In CMakePresets.json, set version to 3.
  • In CMakePresets.json, define a configure preset and add the toolchainFile field (this requires schema version 3 or later).
  • In CMakeUserPresets.json, set version to 2.
  • In CMakeUserPresets.json, define a configure preset that inherits from the one defined above. Don't add anything to this new configure preset, it just needs to inherit from the other one.

CMake itself accepts the above arrangement, which you can verify using cmake --list-presets. However, VS Code complains that the toolchainFile field requires version 3 and refuses to accept it. But that version constraint is satisfied in the context where toolchainFile is used (CMakePresets.json). The CMakeUserPresets.json file is not required to also be version 3 in order to inherit the base preset which does use something from a version 3 schema.

Potentially related: https://gitlab.kitware.com/cmake/cmake/-/issues/22428

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

@elahehrashedi elahehrashedi added the more info needed More info is needed from the community for us to properly triage and investigate. label Dec 20, 2022
@elahehrashedi
Copy link
Contributor

using cmake --list-presets, I see that CMake doesn't accept the above arrangement either.
Can you share your preset settings, and the results of cmake --list-presets ?

@craigscott-crascit
Copy link
Author

I can confirm that CMake does accept it. Here are some minimal files that you can use. I confirmed that cmake --list-presets works with both the latest CMake release (3.25.1) and an older feature release 3.23.3 which still supports presets version 3.

CMakePresets.json
{
  "version": 3,
  "configurePresets": [
    {
      "name": "default",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build",
      "toolchainFile": "${sourceDir}/toolchain.cmake"
    }
  ]
}
CMakeUserPresets.json
{
  "version": 2,
  "configurePresets": [
    {
      "name": "my_thing",
      "inherits": "default"
    }
  ]
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(vscode_bug_2897 LANGUAGES NONE)

toolchain.cmake is just an empty file.

With the above minimal set of files, cmake --list-presets outputs the following:

Available configure presets:

  "my_thing"
  "default"

If I try to get vscode to open the folder, it fails with the following message in the "CMake/Build" output panel:

[variant] Loaded new set of variants
[kit] Successfully loaded 1 kits from /Users/craig/.local/share/CMakeTools/cmake-tools-kits.json
[presetController] Successfully validated presets in /Users/craig/Projects/vscode-bug-2897/CMakePresets.json
[presetController] Successfully validated presets in /Users/craig/Projects/vscode-bug-2897/CMakeUserPresets.json
[proc] Executing command: /Applications/CMake.app/Contents/bin/cmake --version
[preset] Configure preset my_thing: Property "toolchainFile" is unsupported in presets v2
[main] Failed to resolve configure preset: my_thing
[main] "configurePreset" is not set in build preset: __defaultBuildPreset__

@elahehrashedi
Copy link
Contributor

I could repro this issue. It looks like CMake allows this setting.

We check for version compatibility after expanding the preset, maybe we should check them before expansion:

if (preset.__file && preset.__file.version <= 2) {
// toolchainFile and installDir added in presets v3
if (preset.toolchainFile) {
log.error(localize('property.unsupported.v2', 'Configure preset {0}: Property {1} is unsupported in presets v2', preset.name, '"toolchainFile"'));
return null;

@elahehrashedi elahehrashedi added bug a bug in the product and removed more info needed More info is needed from the community for us to properly triage and investigate. labels Jan 19, 2023
@elahehrashedi elahehrashedi added this to Triage in 1.14 via automation Jan 19, 2023
@benmcmorran benmcmorran added this to Triage in 1.15 via automation Apr 20, 2023
@benmcmorran benmcmorran removed this from Triage in 1.14 Apr 20, 2023
@gcampbell-msft gcampbell-msft moved this from Triage to To do in 1.15 Jul 5, 2023
@gcampbell-msft gcampbell-msft added this to the 1.15 milestone Jul 5, 2023
1.15 automation moved this from To do to Done Jul 19, 2023
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
No open projects
1.15
Done
Development

No branches or pull requests

4 participants