martiege / bin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bin

symlink_catkin_packages.py

A script for adding / updating a catkin workspace for use with a clangd language server.

Requirements

For this script, you will need some version of python3 (/usr/bin/python3 is used) with the glob, argparse, os and typing libraries available. Also install clangd, and an extension to your favourite IDE (e.g. vscode).

Getting started

I recommend adding this script to the path in your ~/.bashrc file:

export PATH=$PATH:(path to this folder)
# in my case, it was in my home folder: 
export PATH=$PATH:$HOME/bin

In the catkin workspace, execute these commands:

$ catkin config --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1
$ symlink_catkin_packages.py

clangd requires a compile_commands.json file for each package with a CMakeLists.txt file. The file is automatically generated by adding the -DCMAKE_EXPORT_COMPILE_COMMANDS=1 argument to the cmake command. This can be added to a catkin workspace by executing the command catkin config --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1.

This script adds a symlink to these compile_commands.json files from each corresponding folder with a corresponding CMakeLists.txt file.

Note

For this script to work, the ros package name and folder name must be the same. That is, the folder with the CMakeLists.txt file must be called the same as the cmake project name (usually found on line 2 of the CMakeLists.txt file) and the <name> ... </name> tag in the package.xml file. A warning should be printed by the script if a package in the build folder can't be found (recursively) in the src folder.

About


Languages

Language:Python 100.0%