@@ -4,7 +4,7 @@ shopt -s globstar nullglob
44
55WS_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../.." & > /dev/null && pwd ) " # workspace directory
66
7- # colcon has a very weird cli so instead we manually concatenate all the logs in the event of a faliure .
7+ # colcon has a very weird cli so instead we manually concatenate all the logs in the event of a failure .
88# This results in a much more readable output.
99function print_stderr_logs () {
1010 for file in $WS_DIR /log/latest/** /stderr.log;
@@ -20,21 +20,50 @@ function print_stderr_logs () {
2020 done
2121}
2222
23- # clean up generated urdf before building. Sometimes when building the urdf is not properly generated if the file already exists.
24- # This workaround forces the urdf to freshly generated each build
25- rm -f " ${WS_DIR} " /src/uirover_description/urdf/* .urdf
23+ # Auto detect and install mandatory colcon packages if not already installed
24+ UPDATED=false
25+ if dpkg-query -W python3-colcon-common-extensions & > /dev/null; then
26+ echo " colcon-common-extensions is already installed"
27+ else
28+ echo " Installing colcon-common-extensions"
29+
30+ if [ " $UPDATED " = false ]; then
31+ sudo apt update
32+ UPDATED=true
33+ fi
34+ sudo apt install -y python3-colcon-common-extensions
35+ fi
36+ if dpkg-query -W python3-colcon-mixin & > /dev/null; then
37+ echo " colcon-mixin is already installed"
38+ else
39+ echo " Installing colcon-mixin"
40+
41+ if [ " $UPDATED " = false ]; then
42+ sudo apt update
43+ UPDATED=true
44+ fi
45+ sudo apt install -y python3-colcon-mixin
46+ fi
47+ MIXIN_URL=" https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml"
48+ if ! colcon mixin list 2> /dev/null | grep -q " $MIXIN_URL " ; then
49+ colcon mixin add default " $MIXIN_URL "
50+ fi
2651
2752# desktop_notification- console_stderr- disable annoying features of colcon
28- (cd $WS_DIR && colcon build \
53+ # --continue-on-error continues building other packages even if one fails
54+ # --parallel-workers 0 uses all available CPU cores
55+ # --symlink-install symlinks files so we don't have to rebuild after every change
56+ # --mixin compile-commands generates WS_DIR/build/compile_commands.json for vscode and other IDEs
57+ COLCON_ARGS=" --mixin compile-commands \
2958--continue-on-error \
30- --cmake-args \
31- -DCMAKE_BUILD_TYPE=Debug \
3259--parallel-workers 0 \
3360--symlink-install \
34- --event-handlers desktop_notification- console_stderr- || print_stderr_logs)
61+ --event-handlers desktop_notification- console_stderr-"
3562
36- echo " export RCUTILS_COLORIZED_OUTPUT=1 " >> " ${WS_DIR} /install/setup.bash "
63+ (cd $WS_DIR && colcon build $COLCON_ARGS || print_stderr_logs)
3764
65+ # Enable colored output for ROS2 command line tools
66+ echo " export RCUTILS_COLORIZED_OUTPUT=1" >> " ${WS_DIR} /install/setup.bash"
3867
3968# Ideally we would automatically source the setup.bash file after building, but this is causing bash tab completion to completetly crash gnome-terminal.
4069# Not sure why, but in case this ever gets fixed, here is the line to do it:
0 commit comments