Created
October 14, 2019 15:21
-
-
Save DeanKH/7a37cbc1d4d8b277535033b91424db28 to your computer and use it in GitHub Desktop.
colcon (ROS2) workspaceのC++プロジェクトにcompile_commands.jsonのシンボリックリンクを貼る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
(){ | |
# 必要なパスと環境変数の読込&設定 | |
source /opt/ros/dashing/setup.zsh | |
export COLCON_HOME=$HOME"/.colcon/" | |
export COLCON_LOG_PATH=$COLCON_HOME"log/" | |
# パッケージ一覧の取得 | |
_c_paths=$(colcon list -p) | |
echo $_c_paths | while read _c_path | |
do | |
_cmakelists_path=$_c_path"/CMakeLists.txt" | |
if [[ -e $_cmakelists_path ]]; then # パッケージ内のCMakeLists.txtの有無の確認 | |
# CMakeLists.txtにあるproject(${project_name})を検索/取得 | |
project_name=$(echo $(cat $_cmakelists_path | grep "^project") | sed -e "s/^.*(\(.*\)).*$/\1/") | |
if [ -n "$project_name" ]; then | |
num=$(echo $_cmakelists_path | sed -e "s/^\///" | sed -e "s/\//\n/g" | wc -l) | |
for i in {$num..2} | |
do | |
cand_path=$(echo $_cmakelists_path | cut -d "/" -f1-$i)"/build" | |
if [[ -e $cand_path"/.built_by" ]]; then #colcon workspaceのトップディレクトリの判定 | |
origin_ccj_path=$cand_path"/"$project_name"/compile_commands.json" | |
if [[ -e $origin_ccj_path ]]; then | |
ln -s $origin_ccj_path $_c_path"/" # シンボリックリンクの生成 | |
fi | |
fi | |
done | |
fi | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment