Skip to content

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

Closed

Description

@rei-vilo

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!

Activity

  1. sean-mcmanus commented on May 22, 2017

    @sean-mcmanus
    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?

  2. rei-vilo commented on May 22, 2017

    @rei-vilo
    Author

    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?

  3. bobbrow commented on May 22, 2017

    @bobbrow
    Contributor

    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.

  4. changed the title [-]How to get and read VSC variables from makefile?[/-] [+]How to get and read VS Code variables in a makefile?[/+] on May 22, 2017
  5. sean-mcmanus commented on May 22, 2017

    @sean-mcmanus
    Contributor

    Rei Vilo (@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.

  6. rei-vilo commented on May 26, 2017

    @rei-vilo
    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.

  7. rei-vilo commented on Oct 8, 2017

    @rei-vilo
    Author

    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
                    }
                }
            }
        ]
    }
    
  8. 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?[/+] on Oct 8, 2017
  9. rei-vilo commented on Oct 8, 2017

    @rei-vilo
    Author

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

  10. sean-mcmanus commented on Oct 9, 2017

    @sean-mcmanus
    Contributor

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

  11. rei-vilo commented on Oct 9, 2017

    @rei-vilo
    Author

    Ok, thanks, this is a show-stopper.

  12. rei-vilo commented on Mar 7, 2018

    @rei-vilo
    Author

    Chen Zhang (@czgtest)

    Maybe you can help on this issue too.

  13. bobbrow commented on Mar 7, 2018

    @bobbrow
    Contributor
  14. added
    fixedCheck the Milestone for the release in which the fix is or will be available.
    on Mar 8, 2018
  15. removed
    fixedCheck the Milestone for the release in which the fix is or will be available.
    on Apr 24, 2018
  16. rei-vilo commented on Feb 11, 2019

    @rei-vilo
    Author

    Bob Brown (@bobbrow) What do mean by more info needed?

  17. bobbrow commented on Feb 11, 2019

    @bobbrow
    Contributor

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

  18. rei-vilo commented on Aug 14, 2019

    @rei-vilo
    Author

    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.

  19. sean-mcmanus commented on Aug 15, 2019

    @sean-mcmanus
    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.

  20. bobbrow commented on Oct 17, 2019

    @bobbrow
    Contributor

    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}

  21. rei-vilo commented on Oct 18, 2019

    @rei-vilo
    Author

    Thank you!

  22. rei-vilo commented on Oct 19, 2019

    @rei-vilo
    Author

    Bob Brown (@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!

  23. locked and limited conversation to collaborators on Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions