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

How to pass VSC variables from c_cpp_properties.json to a Task? #742

Closed
rei-vilo opened this issue May 20, 2017 · 18 comments
Closed

How to pass VSC variables from c_cpp_properties.json to a Task? #742

rei-vilo opened this issue May 20, 2017 · 18 comments

Comments

@rei-vilo
Copy link

I'm running a makefile with the C/C++ for Visual Studio Code extension and I've defined some configurations in c_cpp_properties.json.

How to read and get the configurations values from the makefile?

Thanks!

@sean-mcmanus
Copy link
Contributor

You have to manually open the makefile and modify the includePath/defines settings in c_cpp_properties.json accordingly. Does that work for you?

@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state labels May 22, 2017
@rei-vilo
Copy link
Author

rei-vilo commented May 22, 2017

Editing the make-file works for me, but the idea was to have a better integration. Leveraging Visual Studio Code interface to set parameters and retrieving those parameters from the makefile.

Is there something like export VARIABLE=VALUE available?

@bobbrow
Copy link
Member

bobbrow commented May 22, 2017

Which VS Code variables are you trying to read? Our extension does not set any environment variables. The contents of c_cpp_properties.json is not exported to the environment.

@bobbrow bobbrow changed the title How to get and read VSC variables from makefile? How to get and read VS Code variables in a makefile? May 22, 2017
@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented May 22, 2017

@rei-vilo I assume you mean editing the "c_cpp_properties.json"? You shouldn't need to edit the makefile. Are you asking for cpptools to read the makefile and set the includePath and defines ourselves? Visual Studio 2017 does that for cmake, but we haven't implemented that yet. Theoretically, anyone could write a VS Code extension (or any script) that read makefiles or other build settings and read/modified our c_cpp_properties.json to correctly set the includePath/defines.

@rei-vilo
Copy link
Author

I've modified c_cpp_properties.json to define different configurations with tool-chains and SDK instead of the OSes.

{
    "configurations": [
        {
            "name": "LaunchPad MSP432",
            "includePath": [
                "~/Library/Energia15/packages/energia/hardware/msp432r",
                "~/Library/Energia15/packages/energia/tools/arm-none-eabi-gcc"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "~/Library/Energia15/packages/energia/hardware/msp432r",
                    "~/Library/Energia15/packages/energia/tools/arm-none-eabi-gcc"
                ]
            }
        },
       {
            "name": "LaunchPad LM4F120",
            "includePath": [
                "~/Library/Energia15/packages/energia/hardware/tivac",
                "~/Library/Energia15/packages/energia/tools/arm-none-eabi-gcc"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "~/Library/Energia15/packages/energia/hardware/tivac",
                    "~/Library/Energia15/packages/energia/tools/arm-none-eabi-gcc"
                ]
            }
        }
    ]
}

I need to get the "name" field so the main makefile can switch to the appropriate secondary one. Similarly, I’d like to add other fields and read them from the main makefile.

@rei-vilo
Copy link
Author

rei-vilo commented Oct 8, 2017

Once a configuration is selected, e.g. LaunchPad MSP432 as per #742 (comment), how to get that value and pass it to the task Build, i.e. {{name}}?

{
    "version": "0.1.0",
    "isShellCommand": true,
    "tasks": [
        {
            "taskName": "Build",
            "isBuildCommand": true,
            "showOutput": "always",
            "command": "make",
            "args": ["build", {{name}}],
            "suppressTaskName": true,
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

@rei-vilo rei-vilo changed the title How to get and read VS Code variables in a makefile? How to pass VSC variables from c_cpp_properties.json to a Task? Oct 8, 2017
@rei-vilo
Copy link
Author

rei-vilo commented Oct 8, 2017

Title How to pass VSC variables from c_cpp_properties.json to a Task? seems more appropriate.

@sean-mcmanus
Copy link
Contributor

@rei-vilo There is currently no way to automatically get the value of the cpptools configuration name.

@rei-vilo
Copy link
Author

rei-vilo commented Oct 9, 2017

Ok, thanks, this is a show-stopper.

@rei-vilo
Copy link
Author

rei-vilo commented Mar 7, 2018

@czgtest

Maybe you can help on this issue too.

@rei-vilo rei-vilo reopened this Mar 7, 2018
@bobbrow
Copy link
Member

bobbrow commented Mar 7, 2018

microsoft/vscode#43782

@bobbrow bobbrow added the fixed Check the Milestone for the release in which the fix is or will be available. label Mar 8, 2018
@bobbrow bobbrow removed the fixed Check the Milestone for the release in which the fix is or will be available. label Apr 24, 2018
@bobbrow bobbrow added Feature Request and removed more info needed The issue report is not actionable in its current state labels Feb 4, 2019
@rei-vilo
Copy link
Author

@bobbrow What do mean by more info needed?

@bobbrow
Copy link
Member

bobbrow commented Feb 11, 2019

I removed that tag while doing some issue cleanup last week. It was set a long time ago before we understood the issue.

@rei-vilo
Copy link
Author

rei-vilo commented Aug 14, 2019

From c_cpp_properties.json reference | Configuration properties

defines A list of preprocessor definitions for the IntelliSense engine to use while parsing files. Optionally, use = to set a value, for example VERSION=1.

Why not provide a similar logic for definitions tasks.json may read and use from c_cpp_properties.json?

Integrate with External Tools via Tasks | Variable substitution details Predefined variables, Environment variables and Configuration variables, but is mum about variables defined in c_cpp_properties.json configurations.

@sean-mcmanus
Copy link
Contributor

VS Code itself controls the execution of tasks.json and there's no way for us to get them to use c_cpp_properties.json info.

@bobbrow
Copy link
Member

bobbrow commented Oct 17, 2019

Sorry, I should have resolved this issue a long time ago. VS Code added a feature that lets us do this and we added a command to get the active configuration name that you can use in your tasks.json.

${command:cpptools.activeConfigName}

@bobbrow bobbrow closed this as completed Oct 17, 2019
@rei-vilo
Copy link
Author

Thank you!

@rei-vilo
Copy link
Author

@bobbrow It works fine.

Where can I find the documentation related to this feature? Pages Customizing default settings and c_cpp_properties.json reference for the C++ extension, and page Integrate with External Tools via Tasks for Tasks, do not mention cpptools.activeConfigName.

Thank you!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants