vscode-catkin-tools icon indicating copy to clipboard operation
vscode-catkin-tools copied to clipboard

Feature: Add option to emit combined compile_commands.json file

Open betwo opened this issue 5 years ago • 10 comments

Add an option to emit a combined compile_commands.json file to a central place. This can then be used by other extensions / tools like clangd.

betwo avatar Mar 11 '21 17:03 betwo

@betwo Not sure if I'm misconfiguring something but I can't get this work. I have in settings.json (user)

"catkin_tools.mergedCompileCommandsJsonPath": "${workspaceFolder}/compile_commands.json"

however the combined json is never generated.

pclay614 avatar Oct 11 '21 17:10 pclay614

Hey @pclay614, thanks for the info. I'll take a look at this soon

betwo avatar Oct 14 '21 18:10 betwo

So I just tried to reproduce with your settings, but running the command Reload / Merge compile commands works in my test workspaces:

  1. the merged file is created
  2. the status bar shows the following: Screenshot from 2021-10-15 21-44-01

To find out why it doesn't work for you, could you please provide some more context? Are there any compile_commands.json files generated by catkin in the first place? Do you get any errors in the console log?

betwo avatar Oct 15 '21 19:10 betwo

Ok, so that works. I guess I was under the impression that it would automatically happen after performing a build or that I could use it as a Task.

My current workflow is that I chain two tasks together: the build and the merge. Current my merge looks like: jq -s 'map(.[])' ${CATKIN_BUILD_DIR}/**/compile_commands.json > ${workspaceFolder}/compile_commands.json

Note that it uses jq which has to be installed.

pclay614 avatar Oct 20 '21 18:10 pclay614

We could add an option to automatically run the merge when one of the compile_commands.json files changes. Do you think that could work instead of your current workflow?

betwo avatar Oct 27 '21 20:10 betwo

That should be fine. That would also help in the case where if someone wants to do a shell task to build, it should rebuild the compile_commands.json as well.

pclay614 avatar Oct 29 '21 15:10 pclay614

Ok, now that's strange:

I just wanted to add a new option, but then I remembered that this effectively already exists: If mergedCompileCommandsJsonPath is defined, merging should already be automatic.

In my setup that also works with the current version. I tested by running catkin build manually on the command line, the merged file was emitted.

I just release a new patch version (3.3.5) that should log this more specifically. Could you please check the debug log for "Writing merged database" when you are running a catkin command?

betwo avatar Oct 30 '21 09:10 betwo

I tried both these in settings.json

  1. "catkin_tools.mergedCompileCommandsJsonPath": "${workspaceFolder}/compile_commands.json"
  2. "catkin_tools.mergedCompileCommandsJsonPath": "${workspaceFolder}"

(1) gave me this output: "${workspaceFolder}/compile_commands.json" could not be found. 'includePath' from c_cpp_properties.json in folder <my project folder> will be used instead. (2) gave no output (i believe there is an if statement for this in the extension source that does something if it's just ${workspaceFolder}

Neither gave me a compile_commands.json in the workspace Folder. Note: I did use catkin build --this in a package folder. But that should generate one as well. I'll try a full build later today.

pclay614 avatar Nov 01 '21 16:11 pclay614

Sorry for taking so long, I didn't find time the last days.

"catkin_tools.mergedCompileCommandsJsonPath": "${workspaceFolder}/compile_commands.json" Neither gave me a compile_commands.json in the workspace Folder. Note: I did use catkin build --this in a package folder. But that should generate one as well.

You're right, (1) should have given you a compile_commands.json file in the workspace folder with any catkin command.

Did you find anything in the debug log like this: image Either with or without the "writing merged..."?

"${workspaceFolder}/compile_commands.json" could not be found. 'includePath' from c_cpp_properties.json in folder will be used instead.

That actually looks like a problem with the c++ extension, Did you set ${workspaceFolder}/compile_commands.json in your c_cpp_properties.json file manually? If that's the case, you might try to use the automatic mode like this:

{
    "configurations": [
        {
            "name": "ROS",
            "cppStandard": "c++20",
            "cStandard": "c11",
            "configurationProvider": "b2.catkin_tools"
        }
    ],
    "version": 4
}

I'll try a full build later today.

Any luck with that?


Also, do you have multiple folders opened in your workspace, or just a single one?

betwo avatar Nov 10 '21 17:11 betwo

sorry, i haven't had a chance to check recently. I'll try this week.

pclay614 avatar Nov 16 '21 21:11 pclay614