Skip to content

Instantly share code, notes, and snippets.

@xiaodong2077
Created March 11, 2024 07:11
Show Gist options
  • Save xiaodong2077/35c6ea14dd388781bdcd038c7c25cb30 to your computer and use it in GitHub Desktop.
Save xiaodong2077/35c6ea14dd388781bdcd038c7c25cb30 to your computer and use it in GitHub Desktop.
Get a whole compile_commands.json(which is used in cland and sonarlint) file with `catkin_make_isolated` of ROS. You also need to add this option `-DCMAKE_EXPORT_COMPILE_COMMANDS=1` when you run `catkin_make_islodated`
#! /bin/bash
# Merge`build_isolated/*/compile_commands.json` to `build/compile_commands.json`
output_file="build/compile_commands.json"
rm -f "$output_file"
echo "[" > "$output_file"
first_file=true
for file in build_isolated/*/compile_commands.json; do
if [ -f "$file" ]; then
if [ "$first_file" = false ]; then
echo "," >> "$output_file"
fi
sed -n '/\[/,/\]/p' "$file" | sed '1d;$d' >> "$output_file"
echo "Merged $file into $output_file"
first_file=false
fi
done
echo "]" >> "$output_file"
echo "Merge process completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment