microsoft / microsoft/vscode-cpptools

[bug] launch.json envFile not capable of variable interpolation

Open
#13,781 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted tasks/build/debug
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and version: Windows NT x64 10.0.19045
  • VS Code: 1.99.1
  • C/C++ extension:
  • OS and version of remote machine (if applicable): N/A
  • GDB / LLDB version: N/A
Bug Summary and Steps to Reproduce

Bug Summary:
.env files don't appropriately handle variable substitution in conformance with the dotenv file spec

Initially raised as https://github.com/microsoft/vscode/issues/257570 but advised to move the issue here.
Relates to #9329

Steps to Reproduce:

  1. Create a blank repo and populate it with the following files:
    • launch.json
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(msvc) Launch",
                "type": "cppvsdbg",
                "request": "launch",
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "envFile": "${workspaceFolder}/.env"
            }
        ]
    }
    
    • .env
    USER=admin
    EMAIL=${USER}@example.org
    PATH=~/project:${PATH}
    
  2. Press F5 to trigger launch.json
  3. Observe the following error message:

Invalid variable reference ${USER} in string: ${USER}@example.org.
Invalid variable reference ${PATH} in string: ~/project:${PATH}.

Expected behaviour

  • USER=admin is exported to the environment
  • EMAIL=admin@example.org is exported to the environment
  • PATH=/home/username/project:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (or some approximation thereof) is exported to the environment

Which would be consistent with Interpolation/Variable Substitution in dotenv files

Context

I'm trying to identify a transparent integration with conan for C++ development. One of the considerations for this is being able to update the following environment variables to allow the debugger to correctly resolve the paths to dependent libraries:

  • LD_LIBRARY_PATH
  • DYLD_LIBRARY_PATH
  • PATH

Conan achieves this currently (unrelated to VSCode) by generating a conanrun.{sh,bat,ps1} set of files that updates the environment. The idea is that one does the following:

source build/Debug/generators/conanrun.sh
cmake --presets conan-release
cmake --build conan-release

It doesn't seem like VSCode has the ability to do the first part of this with the existing file formats as part of its application launch cycle. https://github.com/conan-io/conan/issues/11042 proposes the addition of an ability to generate a conanrun.env, which could be consumed by the envFile parameter. However, as discussed in https://github.com/conan-io/conan/issues/11042#issuecomment-3105696577 and https://github.com/conan-io/conan/issues/11042#issuecomment-3109473501, the syntax/features that VSCode expects/supports seems inconsistent to what is understood to be the dotenv file schema

Debugger Configurations
Above
Debugger Logs
Above
Other Extensions

Persists after disabling all other extensions.

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the mentioned launch.json and .env files, then trace how the envFile parameter is processed when F5 starts the cppvsdbg configuration. Done means USER, EMAIL, and PATH substitutions are exported consistently with the stated expected behavior on the relevant platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.