Skip to content

Using an 'input' selection from launch.json to be used in a preLaunchTask #95158

@EmbeddedBacon

Description

@EmbeddedBacon

In a project there are a number of helper utilities. In the launch and tasks json files they are configured to allow the user to select the particular utility to build or debug. What I would like to do is have the selection from launch to be passed to the tasks and the task use that selection. The launch.json configuration file looks like:

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug: <Utility App>",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/apps/${input:utility}/${input:utility}",
            "args": ["--notimeout", "--pit"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/apps/${input:utility}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask": "make utility",
        },
    "inputs": [
        {
          "type": "pickString",
          "id": "utility",
          "description": "Which utility app do you want to run?",
          "options": [
            "utility_1",
            "utility_2",
            "utility_3",
            "utility_4",
          ]
        },
    ]
}

The tasks.json configuration file looks like:

tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make utility",
            "type": "process",
            "command": "make",
            "args": [ "${input:BuildUtility}" ],
            "group": "build",
            "problemMatcher": "$gcc"
        },
    ],
    "inputs": [
        {
            "type": "pickString",
            "id": "BuildUtility",
            "description": "Which utility do you want to build?",
            "options": [
                "utility_1",
                "utility_2",
                "utility_3",
                "utility_4",
            ]
        }
    ]
}

I would like to pass the selection made from launch via preLaunchTask so the task uses that selection, effectively overriding "${input:BuildUtility}" so the user wouldn't be promoted to make a selection for the "args" field. Bonus would be having the tasks still ask for a selection if nothing was passed to it. Thanks.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions