I am writing a new build task for compiling C++ in VS Code. The task involves compiling the code inside of a Docker container. For example
docker exec -it my_container make
Here is what I have in my task.json file
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "docker",
"args": [
"exec",
"-it",
"my_container",
"make"
],
"group": "build",
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": {
"base": "$gcc",
"fileLocation": "absolute"
}
}
]
}
I'm able to run the task, and everything compiles correctly. However, VS Code cannot find the files that have build errors in them. That is because the output for an looks something like this:
/host/my_project/src/my_file.cpp:105:46: error: passing 'const SomeClass' as 'this' argument discards qualifiers [-fpermissive]
The path that is listed is the absolute path to the file in the Docker container. When you click on one of the files in the Problems tab, it tries to jump to /host/my_project/src/my_file.cpp, but it doesn't exist. Instead, the file lives in /home/me/projects/my_project/src/my_file.cpp.
I've tried a few things to fix this, none of which seem to work. I tried changing the problemMatcher to the one outlined in the documentation and trying to use a different regex that would remove the absolute part of the path (e.g. convert /host/my_project/src/my_file.cpp to /src/my_file.cpp, and set the fileLocation to relative). However I'm not well-versed enough in regex to get it right. Referencing some regex from here, I came up with this
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^[^/]/[^/]*/[^/]*/(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
I also tried the other options in that answer, but none of them work. Another thing I tried was creating a symlink between the folders by running ln -s /host ~/projects. This also did not work, and still tried to open the file in the Docker container
Does anyone have any suggestions?