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 455 forks source link

CMakePresets fail to load on RedHat. Error on Output: Invalid variable reference ${which_declare} #3961

Closed pilarArr closed 3 months ago

pilarArr commented 3 months ago

Brief Issue Summary

Issue Related to #1841

I'm not able to produce an example repo. But I'll try to layout a MWE. Since it's the presets loading that fails. I don't think the rest of the project does matter.

My project layout would be somethin like this

(root)
├── CMakePresets.json
├── CMakeLists.txt
├── scr
│   ├── hello_world.c
├── include
│   ├── hello_world.h

This would be my CMakePresets.json file:

{
  "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"
      }
    },
    {
      "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"
    },
    {
      "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"
    }
  ],
  "buildPresets": [
    {
      "name": "build_base",
      "inheritConfigureEnvironment": true
    },
    {
      "name": "VS2019_NoTests_build",
      "configurePreset": "VS2019_NoTests_config",
      "inherits": ["build_base"],
      "displayName": "Release"
    }
  ]
}

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.88.0",
  "cmtVersion": "1.19.36",
  "configurations": [
    {
      "folder": "/my_folder/test_example",
      "cmakeVersion": "3.27.7",
      "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: /opt/cmake-3.27.7-linux-x86_64/bin/cmake --version
[proc] Executing command: /opt/cmake-3.27.7-linux-x86_64/bin/cmake -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 /home/user/.local/share/CMakeTools/cmake-tools-kits.json
[kit] Successfully loaded 4 kits from /home/user/.local/share/CMakeTools/cmake-tools-kits.json
[kit] Not reading non-existent kits file: /myfolder/test_example/.vscode/cmake-kits.json
[presetController] Reading presets file /myfolder/test_example/CMakePresets.json
[presetController] Reading and validating the presets "file /myfolder/test_example/CMakePresets.json"
[presetController] Successfully validated /myfolder/test_example/CMakePresets.json against presets schema
[presetController] Expanding presets file /myfolder/test_example/CMakePresets.json
[proc] Executing command: uname -s
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[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}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${hostSystemName}
[expand] expanded ${hostSystemName}
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${hostSystemName}
[expand] expanded ${hostSystemName}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded ${sourceDir}/build/${presetName}
[expand] expanded ${sourceDir}/build/${presetName}/delivery
[expand] expanded ${hostSystemName}
[expand] Invalid variable reference ${which_declare} in string: () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[expand] expanded () {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
[presetController] Expansion errors found in the presets file.
[main] CMakeProject instance initialization complete.
[extension] Attempting to use cache to configure workspace file:///myfolder/test_example
[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

Using CMakeTools 1.18.19 works.

Visual Studio Code v1.88.0
CMakeTools 1.19.36
OS information
NAME="Red Hat Enterprise Linux"
VERSION="9.0 (Plow)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="9.0"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Red Hat Enterprise Linux 9.0 (Plow)"

EDIT: pressed enter before finishing issue.

pilarArr commented 3 months ago

Tested the vsix provided on #3959 (comment) and it does not solve the problem. Same error.

gcampbell-msft commented 3 months ago

@pilarArr I'm curious if you have some answers that might help investigate.

Where is this ${which_declare} defined? Is it defined as an environment variable itself?

pilarArr commented 3 months ago

@gcampbell-msft I found these mentions to which_declare on the env, but I haven't touched that, I believe that is just how it is out of the box.

BASH_FUNC_which%%=() {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
which_declare=typeset -f
gcampbell-msft commented 3 months ago

Is this defined in the environment variables for the linux installs?

pilarArr commented 3 months ago

that would be the default environment on login

Yingzi1234 commented 3 months ago

@pilarArr Based on the file information you provided for CMakePresets.json, we are unable to surface your issue on Linux platform and we can Configure success. In order to better solve your problem, could you provide me your reproduction file and reproduction steps? Thank you in advance! image