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

CMakePresets error including nested presets files #3959

Closed
pilarArr opened this issue Aug 6, 2024 · 5 comments · Fixed by #3958
Closed

CMakePresets error including nested presets files #3959

pilarArr opened this issue Aug 6, 2024 · 5 comments · Fixed by #3958
Labels
bug a bug in the product Feature: presets regression used to work and no longer does. Regressions are typically high priority

Comments

@pilarArr
Copy link

pilarArr commented Aug 6, 2024

Brief Issue Summary

Nested includes on preset files fail to load, when loaded a second time, the final error on the log is that there are expansion errors on the presets files.
These presets setup works correctly from the command line and CMakeTools successfully validates them with the schema.

My case would be this. I have a project that I need to build on linux and windows platforms. I have the following cmake presets files which I load with includes and presets that have a condition to either hide them or show them.

CMakePresets.json
├── cmake
│   ├── presets
│   │   ├── 00_CMakePresetsBasics.json
│   │   ├── 01_CMakePresets_win.json
│   │   ├── 01_CMakePresets_unix.json

I've stripped the presets files the most I could to generate a MWE

  • CMakePresets.json : root preset file
{
  "version": 7,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 27,
    "patch": 0
  },
  "include": [
    "cmake/presets/01_CMakePresets_win.json",
    "cmake/presets/01_CMakePresets_unix.json"
  ]
}
  • 00_CMakePresetsBasics.json : this file stores common presets for both operating systems that the specific presets inherit. A MWE follows:
{
  "version": 7,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 27,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "base",
      "hidden": true,
      "binaryDir": "${sourceDir}/build/${presetName}",
      "cacheVariables": {
        "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/${presetName}/delivery",
        "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
      }
    },
    {
      "name": "windows_only",
      "hidden": true,
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      }
    },
    {
      "name": "linux_only",
      "hidden": true,
      "condition": {
        "type": "notEquals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "build_base",
      "inheritConfigureEnvironment": true,
    }
  ]
}
  • 01_CMakePresets_win.json : this file holds the presets configurations for windows and it includes the basics presets file
{
  "version": 7,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 27,
    "patch": 0
  },
  "include": ["00_CMakePresetsBasics.json"],
  "configurePresets": [
    {
      "name": "VS2019_x64_config",
      "inherits": ["base"],
      "hidden": true,
      "generator": "Visual Studio 16 2019",
      "toolset": {
        "value": "host=x64",
        "strategy": "set"
      },
      "architecture": {
        "value": "x64",
        "strategy": "set"
      }
    },
    {
      "name": "VS2019_NoTests_config",
      "inherits": ["VS2019_x64_config", "windows_only"],
      "displayName": "VS2019 NoTests"
    }
  ],
  "buildPresets": [
    {
      "name": "VS2019_NoTests_build",
      "configurePreset": "VS2019_NoTests_config",
      "inherits": ["build_base"],
      "displayName": "Release"
    }
  ]
}
  • 01_CMakePresets_unix.json : this file holds the presets configurations for windows and it includes the basics presets file
{
  "version": 7,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 27,
    "patch": 0
  },
  "include": ["00_CMakePresetsBasics.json"],
  "configurePresets": [
    {
      "name": "mai001_NinjaMulti_GCC_13_64bits",
      "inherits": ["base"],
      "cacheVariables": {
        "CMAKE_C_COMPILER": "/usr/local/bin/gcc",
        "CMAKE_CXX_COMPILER": "/usr/local/bin/g++"
      },
      "hidden": true,
      "generator": "Ninja Multi-Config"
    },
    {
      "name": "mai001_NoTests_config",
      "inherits": ["mai001_NinjaMulti_GCC_13_64bits", "linux_only"],
      "displayName": "mai001 NoTests"
    }
  ]
}

This setup does not work. Things I've tried:

  • Removing the include for 01_CMakePresets_unix.json on the root preset makes it all work again.
  • Putting everything on a single presets file also works.
  • Moving the include for 00_CMakePresetsBasics.json to the root preset does not work. this needs to be included on the relevant files.
  • Version 1.18.19 of CMakeTools also works.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.88.0",
  "cmtVersion": "1.19.36",
  "configurations": [
    {
      "folder": "c:\\Users\\my_user\\Desktop\\my_test",
      "cmakeVersion": "3.27.9",
      "configured": false,
      "generator": "",
      "usesPresets": true,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "always",
      "configureOnOpen": false
    }
  ]
}

Debug Log

[proc] Executing command: C:\cae\CMake\bin\cmake.EXE --version
[proc] Executing command: C:\cae\CMake\bin\cmake.EXE -E capabilities
[main] Safe constructing new CMakeProject instance
[variant] Constructing VariantManager
[main] Constructing new CMakeProject instance
[main] Starting CMake Tools second-phase init
[expand] expanded ${workspaceFolder}
[kit] Reading kits file C:\Users\my_user\AppData\Local\CMakeTools\cmake-tools-kits.json
[kit] Successfully loaded 10 kits from C:\Users\my_user\AppData\Local\CMakeTools\cmake-tools-kits.json
[kit] Not reading non-existent kits file: c:\Users\my_user\Desktop\WIP\my_test\.vscode\cmake-kits.json
[presetController] Reading presets file C:\Users\my_user\Desktop\my_test\CMakePresets.json
[presetController] Reading and validating the presets "file C:\Users\my_user\Desktop\my_test\CMakePresets.json"
[presetController] Successfully validated C:\Users\my_user\Desktop\my_test\CMakePresets.json against presets schema
[presetController] Reading presets file C:\Users\my_user\Desktop\my_test\cmake\presets\01_CMakePresets_unix.json
[presetController] Reading and validating the presets "file C:\Users\my_user\Desktop\my_test\cmake\presets\01_CMakePresets_unix.json"
[presetController] Successfully validated C:\Users\my_user\Desktop\my_test\cmake\presets\01_CMakePresets_unix.json against presets schema
[presetController] Reading presets file C:\Users\my_user\Desktop\my_test\cmake\presets\00_CMakePresetsBasics.json
[presetController] Reading and validating the presets "file C:\Users\my_user\Desktop\my_test\cmake\presets\00_CMakePresetsBasics.json"
[presetController] Successfully validated C:\Users\my_user\Desktop\my_test\cmake\presets\00_CMakePresetsBasics.json against presets schema
[presetController] Reading presets file C:\Users\my_user\Desktop\my_test\cmake\presets\01_CMakePresets_win.json
[presetController] Reading and validating the presets "file C:\Users\my_user\Desktop\my_test\cmake\presets\01_CMakePresets_win.json"
[presetController] Successfully validated C:\Users\my_user\Desktop\my_test\cmake\presets\01_CMakePresets_win.json against presets schema
[presetController] Expanding presets file C:\Users\my_user\Desktop\my_test\CMakePresets.json
[preset] Could not find configure preset with name base
[preset] Could not find configure preset with name base
[preset] Could not find configure preset with name windows_only
[preset] Could not find configure preset with name windows_only
[preset] Could not find configure preset with name windows_only
[expand] expanded ${sourceDir}/build/${presetName}
[preset] Configure preset windows_only: No binaryDir specified, using default value "${sourceDir}/out/build/${presetName}"
[expand] expanded ${sourceDir}/out/build/${presetName}
[preset] Configure preset linux_only: No binaryDir specified, using default value "${sourceDir}/out/build/${presetName}"
[expand] expanded ${sourceDir}/out/build/${presetName}
[preset] Configure preset VS2019_x64_config: No binaryDir specified, using default value "${sourceDir}/out/build/${presetName}"
[expand] expanded ${sourceDir}/out/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${hostSystemName}
[expand] expanded ${hostSystemName}
[preset] Configure preset VS2019_NoTests_config: No binaryDir specified, using default value "${sourceDir}/out/build/${presetName}"
[expand] expanded ${sourceDir}/out/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${hostSystemName}
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${hostSystemName}
[preset] Could not find build preset with name build_base
[expand] expanded ${sourceDir}/out/build/${presetName}
[presetController] Expansion errors found in the presets file.
[main] CMakeProject instance initialization complete.
[extension] Attempting to use cache to configure workspace file:///c%3A/Users/my_user/Desktop/my_test
[main] Starting new CMake driver
[main] Starting CMake driver
[cmakefileapi-driver] Creating instance of CMakeFileApiDriver
[driver] Initializing base driver using preset
[main] Unable to configure with existing cache

Additional Information

So currently I'm testing this on windows, I assume the error would be the same on linux.
Anyways I'll update the issue only in the case that I find something different on unix.

These are the versions for my development environment. I work on an offline system so my update cycle is not as good as it could be. I have to install extensions from vsix

Versions:
Visual Studio Code 1.88.0
CMake 3.27.9
Windows Server 2016
CMakeTools 1.19.36
Visual Studio 2019

@github-actions github-actions bot added the triage label Aug 6, 2024
@gcampbell-msft gcampbell-msft linked a pull request Aug 6, 2024 that will close this issue
@gcampbell-msft
Copy link
Collaborator

@pilarArr Thanks for the issue. We are aware of this and have a PR open here: #3958. Addiitonally, you can confirm that the PR fixes your issue by testing out the vsix here: #3956 (comment)

@gcampbell-msft gcampbell-msft added regression used to work and no longer does. Regressions are typically high priority bug a bug in the product Feature: presets and removed triage labels Aug 6, 2024
@pilarArr
Copy link
Author

pilarArr commented Aug 6, 2024

Hello @gcampbell-msft , thanks for the quick reply. I saw that issue but I wasn't sure it was my case as well.
I've tested the vsix you commented and it works on windows.

I've being doing some testing on the unix setup and it does not work. Either of them. But it's another error. It looks like this one #1841. I tried resetting vscode by deleting the folders mentioned there and I still get the same error.

But using CMakeTools 1.18.19 does work. Should I open a new issue or continue with #1841 ?

@gcampbell-msft
Copy link
Collaborator

@pilarArr I think I understand the issue. Essentially, on Linux there is a weird behavior of Fedora where it uses aliasing and environment variables, and because we try to expand all environment variables, it says that there is an error. In the event now that we're being more strict about validation, it fails the configure preset.

I think it'd be worthwhile for you to create a new issue, link the other, and provide a full repro steps and repro project. Thank you for testing on pre-release as well

@gcampbell-msft
Copy link
Collaborator

@pilarArr Thank you very much for your testing, it greatly helps us. Could you try out a quick fix I'm investigating to see if it possibly fixes your issue?
cmake-tools.zip

My understanding is that we should scope our expansion of the environment to the environment variables that are defined in the preset. Please let me know if this fixes the issue on linux and still works on windows. Thanks!

@pilarArr
Copy link
Author

pilarArr commented Aug 7, 2024

@pilarArr Thank you very much for your testing, it greatly helps us. Could you try out a quick fix I'm investigating to see if it possibly fixes your issue? cmake-tools.zip

My understanding is that we should scope our expansion of the environment to the environment variables that are defined in the preset. Please let me know if this fixes the issue on linux and still works on windows. Thanks!

@gcampbell-msft I've tested the vsix (on unix) and it does not work. I've opened a new issue as you suggested. #3961
Thanks for your help.

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 Feature: presets regression used to work and no longer does. Regressions are typically high priority
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

2 participants