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

launch.json file: cmake.configureEnvironment cannot be used for "environment" #4228

Open
acrfc opened this issue Jan 8, 2025 · 5 comments
Open
Labels
more info needed More info is needed from the community for us to properly triage and investigate.

Comments

@acrfc
Copy link

acrfc commented Jan 8, 2025

Brief Issue Summary

With previous vscode versions, in launch.json we could add "env": "${command:cmake.configureEnvironment}"
Current vscode versions replaced "env" by "environment", but ${command:cmake.configureEnvironment} still expands to a format compatible with only "env" and not "environment".

This means we cannot automatically use cmake presets configure/build environment to run an executable :-(

launh.json file to reproduce:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Essai",
            "type": "cppdbg",
            "request": "launch",
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": "${command:cmake.configureEnvironment}",
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}

In this example, "environment": "${command:cmake.configureEnvironment}" is not recognized.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.96.2",
  "cmtVersion": "1.19.52",
  "configurations": [
    {
      "folder": "c:\\Users\\Flo\\Documents\\Dev\\Project-Template",
      "cmakeVersion": "3.26.3",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": true,
      "compilers": {
        "C": "C:/Qt/Tools/mingw1120_64/bin/gcc.exe",
        "CXX": "C:/Qt/Tools/mingw1120_64/bin/g++.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Release",
    "buildTypesSeen": [
      "Release"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 35,
    "executablesCount": 1,
    "librariesCount": 4,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Debug Log

Additional Information

No response

@Amy-Li03
Copy link
Collaborator

Amy-Li03 commented Jan 9, 2025

Hi @acrfc , Thanks for reporting issue here.
"environment" expects an array of objects, where each object contains name and value properties for environment variables. You need to transform the dictionary returned by ${command:cmake.configureEnvironment} into this new array format.
e.g:

"environment": [
        {
             // add the directory where our target was built to the PATHs
             // it gets resolved by CMake Tools:
               "name": "PATH",
               "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
         }
         {
                "name": "OTHER_VALUE",
                "value": "Something something"
          }
  ]

@Amy-Li03 Amy-Li03 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Jan 9, 2025
@acrfc
Copy link
Author

acrfc commented Jan 9, 2025

Hi @Amy-Li03,
Thank you for this quick answer.
I was aware of the workaround you propose, but it would force me to hardcode in the launch.json file an environment that is already set in my CMake Preset file, and as you know hardcoding twice the same data is not good practise in big projects.

I work with a multiplatform CI/CD toolchain heavily driven by a CMake Preset file. To launch the windows version of the executable, I have to add paths to several external dll libs in the environment. I'm new to VSCode, but it seems it was possible with "env" in previous versions. Wouldn't it be possible to fix this regression with introduced by the new "environment" key?

As a side note: on other IDEs like QtCreator, using cmake configure/build/test environment to launch an executable is performed seamlessly.

@Amy-Li03
Copy link
Collaborator

Hi @gcampbell-msft , do you have any thoughts on @acrfc 's requirements?

@gcampbell-msft
Copy link
Collaborator

@acrfc It looks like you're correct that the cppdbg debug type, coming from the cpptools extension (@sean-mcmanus @Colengms), only supports the environment block.

I'm not actually even seeing a command that we support with the cmake.configureEnvironment id. Could you show a gif of what you're project is doing?

Either way, I'm thinking that the main thing that we could do is implement a different version of the command that gives the right format. We'd be happy to take an OSS contribution from you. Thanks!

@FlyinCow
Copy link

Same issue here, ${command:cmake.configureEnvironment} is not a available command int launch.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed More info is needed from the community for us to properly triage and investigate.
Projects
Status: Blocked
Development

No branches or pull requests

4 participants