Open rhklite opened 5 years ago
there was a bug in my work around python script, i made edits to the script and got it working.
Is there a better way to do this? to generate a compile_commands.json
without needing a pythonc script?
I agree, it would be great if catkin build -DCMAKE_EXPORT_COMPILE_COMMANDS=1
did this.
Based on your python script I made my own shell script that does the same:
#!/bin/sh
cd `catkin locate --workspace $(pwd)`
concatenated="build/compile_commands.json"
echo "[" > $concatenated
first=1
for d in build/*
do
f="$d/compile_commands.json"
if test -f "$f"; then
if [ $first -eq 0 ]; then
echo "," >> $concatenated
fi
cat $f | sed '1d;$d' >> $concatenated
fi
first=0
done
echo "]" >> $concatenated
If you happen to use YouCompleteMe with vim, you can use this plugin so you don't have to generate the merged compile_commands.json file. Just run catkin config --cmake-args='-DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
, install the plugin to vim, and everything will just work when you're inside the catkin workspace. Alternatively, you can place the .ycm_extra_conf.py file form that repo in the root of your catkin workspace.
It generates multiple compile commands instead of one merged file as you are working with multiple projects inside. Merging the compile commands sounds like breaking the separation between multiple projects.
So while i understand why you/we/i would want this, it does not sound like something catkin tools should ever do.
edit: catkin_make works since it mushes everything together resulting in packages that seem to work but break if used without the other parts in your workspace (or if build with catkin tools).
@ndepal @rhklite
My way to merge all compile_commands.json together, using the jq tool to simplify integration with other tools.
sudo apt install jq
jq -s 'map(.[])' build_folder/**/compile_commands.json > compile_commands.json
@LeroyR I agree, catkin_tools should keep compile commands split as it is a split workflow.
I am doing something similar. It isn't pretty, but it doesn't require an extra tool:
printf '[' > compile_commands.json
find ./build_isolated -type f -name 'compile_commands.json' -exec sh -c "cat {} | tail -n+2 | head -n-1 && printf ','" >> compile_commands.json \;
sed -i '$s/.$//' compile_commands.json
printf '\n]\n' >> compile_commands.json
Interestingly, colcon does this: https://github.com/colcon/colcon-cmake/pull/69
I used @AlexisTM 's comment and come up with a script
System Info
Python 2.7.12
git version 2.7.4
kinetic
Build / Run Issue
catkin_make
catkin_make_isolated --merge
catkin build
catkin build -p1
read this
Expected Behavior
catkin build -DCMAKE_EXPORT_COMPILE_COMMANDS=1
should generate acompile_commands.json
file insidecatkin_ws/build
that's for the entire workspace. I'm using this file for the cquery linterActual Behavior
compile_commands.json
output withcatkin build
, the same file that you would get when you usecakin_make
catkin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1
would generate acompile_commands.json
insidecatkin_ws/build
which is a nice file that works for the entire workspace.catkin build -DCMAKE_EXPORT_COMPILE_COMMANDS=1
doesn't generate a nice file for the entire workspace, but rather individualcompile_commands.json
for each package. I tried to do a work around by using a python file to concatenate all thecompile_commands.json
in each subfolder in thebuild
folder. However the generatedcompile_commands.json
doesn't recognise#include <message_header>.h
, where as thecompile_commands.json
generated through catkin_make does.Is there a way to properly generate a
compile_commands.json
for the entire catkin workspace usingcatkin build
?python script here:
Steps to Reproduce the Issue
Edit: Made the python script work anywhere in the catkin workspace