Troskyvs
Troskyvs

Reputation: 8047

How to config visual studio code to compile scons?

I'm on ubuntu and installed vsc, python, scons. I've also installed grammar plugin for python and related tools. I'm editing SConstruct file, I hope when I press 'F5', it will bring up scons to execute my project file.

How to config that?

Upvotes: 8

Views: 11325

Answers (3)

Johannes Jendersie
Johannes Jendersie

Reputation: 1010

I got two working solutions. The first one is based on mat's solution:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "SCons BuildVSDebug",
            "command": "scons",
            "type": "shell",
            "group": "build",
            "problemMatcher": "$msCompile" // Important to catch the status
        }
    ]
}

where I use the task as preLaunchTask. By default VSCode does not launch the executable if a problemMatcher reported some problems. Of course the problemMatcher must fit the output (in my case the visual studio compiler cl.exe). However, it is possible to define custom matchers which can explicitly check the status of SCons using Regex for scons messages like "scons: build terminated because of errors". It is also possible to use multiple output matchers...


My second solution targets to debug the SCons build scripts themself. It will not run the compiled output, but allow to debug the build system on F5.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Scons Build System",
            "type": "python",
            "request": "launch",
            "pythonPath": "<python 2.7 path>/python",
            "program": "<python 2.7 path>/Scripts/scons.py",
            "cwd": "${workspaceRoot}",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ],
            ...
        },
        ...
    ]
}

The trick is to launch the SCons script.py from the package installation. It is NOT possible to simply write program: "scons" - it will not be recognized like on the shell. Note that I did not specify a SConstruct file. It is found implicitly by setting the execution directory cwd.

Upvotes: 6

mat
mat

Reputation: 1717

I have created a tasks.json file with the following content:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Build wit SCons",
            "command": "scons",
            "type": "shell",
            "group": "build"
        }
    ]
}

It does a fair integration, as I can start the build task using Shift-Ctrl-B. Unfortunately, it is not a great solution, as I have not yet found a way to display the output status (succeeded/error) in VS Code.

Upvotes: 4

peterphonic
peterphonic

Reputation: 1039

This is something I am planning to do soon for my project, but never did it before. I will start looking the scons doc for MSVSProject() , env.MSVSProject() and MSVSSolution() , env.MSVSSolution().

Upvotes: 0

Related Questions