Sarcasm / compdb

The compilation database Swiss army knife
MIT License
292 stars 23 forks source link

Recommended steps for working with ROS workspaces #23

Closed rickstaa closed 2 years ago

rickstaa commented 2 years ago

I am currently using compdb to create a compile_commands.json file that works with clang-tidy. I, however, have multiple packages in my ROS workspace that export acomile_commands.jsonfile (i.e. have theCMAKE_EXPORT_COMPILE_COMMANDSoption set). Therefore, I wondered if there is a way to represent all the compilation databases of the packages contained in my ROS workspace into onecompile_commands.json` output file.

Related to https://github.com/Sarcasm/compdb/issues/2#issuecomment-338475035.

Sarcasm commented 2 years ago

I'm not sure what is the best way to handle this but I guess it's not compdb.

I never implemented the JSON file concatenation to merge multiple database into one but that maybe there are tools that do that already (e.g.jq ?).

Or maybe the clang-tidy wrapper could take a list of database, e.g.:

my-clang-tidy build/*/compile_commands.json
rickstaa commented 2 years ago

@Sarcasm Ah, thanks a lot for your answer. I think you are right; creating a small wrapper package that uses compdb to create a merged output compile_commands.json file would make more sense. This package can then search whether subfolders in a catkin build workspace contain a compile_commands.json file and merge them (e.g. catkin_compdb). If frequently run into this issue, I will create such a package. For now, I will use the following syntax to merge multiple databases:

compdb -p ../build/package_1 list >> compile_commands.json
compdb -p ../build/package_2 list >> compile_commands.json
Sarcasm commented 2 years ago

I just realized compdb supports multiple -p. So I guess you can do something like:

compdb \
    -p ../build/package_1 \
    -p ../build/package_2 \
    list > compile_commands.json
rickstaa commented 2 years ago

Ah, great. Thanks for the tip.

rickstaa commented 2 years ago

For future reference, I found another way to use clang-tidy in a catkin workspace. Vscode has the clang-tidy and catkin-tools vscode extensions. The catkin-tools does does something similar to compdb. More information about the setup can be found here.