Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 442
Troskyvs Avatar asked Oct 05 '16 16:10

Troskyvs


2 Answers

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.

like image 172
Johannes Jendersie Avatar answered Sep 28 '22 09:09

Johannes Jendersie


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.

like image 39
mat Avatar answered Sep 28 '22 07:09

mat