catkin / catkin_tools

Command line tools for working with catkin
Apache License 2.0
163 stars 146 forks source link

Catkin Build Command Line - Success Return Value ? #675

Closed rwbot closed 3 years ago

rwbot commented 3 years ago

Within my workflow, I use a few aliases to speed up building and running a C++ node:

alias cb="catkin build"
alias swss="source ~/shuttle_ws/devel/setup.bash"
alias rlp="roslaunch package example.launch"
alias bsr="cb; swss; rlp" # All 3 aliases: Build -> Source -> Run

After making changes to a C++ file, I'll save, switch to terminal and type bsr. When it builds successfully, it works perfectly. However, when catkin build fails, the alias continues along sourcing the workspace and launching the node and I have to quickly cancel it.

I'd like to convert the bsr alias into a bash function to evaluate if the build succeeded before attempting to source and run. But I'm unable to determine if and how catkin build returns some sort of boolean upon completion indicating whether the build failed or succeeded.

Does anyone know if and how catkin build returns a boolean or any type of env variable upon completion indicating whether the build failed or succeeded ? If so, how do I access it?

timonegk commented 3 years ago

catkin build returns an exit code of 1 when the build was not successful. It can be used in aliases or shell functions. To use it in your alias, replace ; with &&. && only executes the next command if the previous command was successful, ; always executes the next command. If you want to know more about that, search for “shell control operators“ on the internet.