Skip to content

Commit 3209f88

Browse files
authored
Merge pull request #33 from Extend-Robotics/ERD-1633_update_colcon_build_helpers
update colcon build helpers
2 parents 5045e96 + d8efe6e commit 3209f88

1 file changed

Lines changed: 61 additions & 18 deletions

File tree

.helper_bash_functions

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,79 @@ Color_Off='\033[0m' # Text Reset
88
CATKIN_WS_PATH="/cortex/.catkin_ws"
99
THIS_SCRIPT_BRANCH="main"
1010
THIS_SCRIPT_URL="https://raw.githubusercontent.com/Extend-Robotics/er_build_tools/refs/heads/${THIS_SCRIPT_BRANCH}/.helper_bash_functions"
11-
1211
# ROS helpers
1312
export ROSCONSOLE_FORMAT='[${severity}](${node}): [${time}] ${message}'
14-
colcon_build() { START_DIR=$(pwd) && \
15-
COLCON_BUILD_COMMAND="colcon build --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF" && \
16-
if [ ! -z "$1" ];
17-
then COLCON_BUILD_COMMAND="${COLCON_BUILD_COMMAND} --packages-up-to $1"
18-
fi && \
19-
cd ${CATKIN_WS_PATH} && \
20-
source /opt/ros/noetic/setup.bash && \
21-
echo -e "${Yellow}Running build command:\n${Green}${COLCON_BUILD_COMMAND}${Color_Off}" && \
22-
${COLCON_BUILD_COMMAND}; RET_VAL=$?;\
23-
source ${CATKIN_WS_PATH}/install/setup.bash; \
24-
cd ${START_DIR}; \
25-
return ${RET_VAL}
13+
colcon_build() {
14+
local COLCON_BUILD_COMMAND="colcon build --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF"
15+
[ -n "$1" ] && COLCON_BUILD_COMMAND+=" --packages-up-to $1"
16+
_colcon_build "$COLCON_BUILD_COMMAND"
17+
return $?
18+
}
19+
colcon_build_no_deps() {
20+
local COLCON_BUILD_COMMAND="colcon build --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF"
21+
[ -n "$1" ] && COLCON_BUILD_COMMAND+=" --packages-select $1"
22+
_colcon_build "$COLCON_BUILD_COMMAND"
23+
return $?
24+
}
25+
colcon_build_sym() {
26+
local COLCON_BUILD_COMMAND="colcon build --packages-skip-cache-valid --symlink-install --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF"
27+
[ -n "$1" ] && COLCON_BUILD_COMMAND+=" --packages-up-to $1"
28+
_colcon_build "$COLCON_BUILD_COMMAND"
29+
return $?
30+
}
31+
_colcon_build() {
32+
local START_DIR="$(pwd)"
33+
local COLCON_BUILD_COMMAND="$1"
34+
cd "$CATKIN_WS_PATH" || return 1
35+
source /opt/ros/noetic/setup.bash
36+
echo -e "${Yellow}Running build command:\n${Green}${COLCON_BUILD_COMMAND}${Color_Off}"
37+
eval "$COLCON_BUILD_COMMAND"
38+
local RET_VAL=$?
39+
source "$CATKIN_WS_PATH/install/setup.bash"
40+
cd "$START_DIR"
41+
return $RET_VAL
2642
}
2743
colcon_build_this() { colcon_build "$(find_cmake_project_names_from_dir .)"; }
44+
colcon_build_er_interface() { colcon_build_no_deps "$(find_cmake_project_names_from_dir ${CATKIN_WS_PATH}/src/er_interface)"; }
45+
colcon_test_er_interface() { colcon_test_this_package "$(find_cmake_project_names_from_dir ${CATKIN_WS_PATH}/src/er_interface)"; }
2846
rosdep_install() { rosdep install --from-paths src --ignore-src -r -y ; }
29-
colcon_test_these_packages() { THIS_DIR=$(pwd)
47+
_show_test_failures() {
48+
python3 - "$@" <<'PYEOF'
49+
import sys, xml.etree.ElementTree as ET
50+
from pathlib import Path
51+
for d in sys.argv[1:]:
52+
for p in sorted(Path(d).rglob("*.xml")):
53+
for tc in ET.parse(p).iter("testcase"):
54+
for f in list(tc.iter("failure")) + list(tc.iter("error")):
55+
tag = "FAIL" if f.tag == "failure" else "ERROR"
56+
print(f"\n {tag}: {tc.get('classname', '')}.{tc.get('name', '')}")
57+
if f.text:
58+
lines = f.text.strip().splitlines()
59+
for l in lines[:20]:
60+
print(f" {l}")
61+
if len(lines) > 20:
62+
print(f" ... ({len(lines) - 20} more lines)")
63+
PYEOF
64+
}
65+
colcon_test_these_packages() { local THIS_DIR=$(pwd)
66+
local VERBOSE_FLAG=""
67+
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
68+
VERBOSE_FLAG="--event-handlers console_direct+"
69+
shift
70+
fi
3071
cd ${CATKIN_WS_PATH}
31-
colcon_build_no_deps $1
72+
colcon_build_no_deps "$1"
3273
source install/setup.bash && \
33-
colcon test --packages-select $1
74+
colcon test --packages-select $1 ${VERBOSE_FLAG}
3475
for pkg in $1; do
35-
colcon test-result --verbose --test-result-base "build/$pkg"
76+
if ! colcon test-result --test-result-base "build/$pkg/test_results"; then
77+
_show_test_failures "build/$pkg/test_results"
78+
fi
3679
done
3780
cd $THIS_DIR
3881

3982
}
40-
colcon_test_this_package() { colcon_test_these_packages "$@"; } # Alias for backwards compatability
83+
colcon_test_this_package() { colcon_test_these_packages "$@"; }
4184
find_cmake_project_names_from_dir() { if [[ -z $1 ]]; then DIR_TO_SEARCH="."; else DIR_TO_SEARCH=$1; fi; wget -qO- https://raw.githubusercontent.com/Extend-Robotics/er_build_tools/refs/heads/main/bin/find_cmake_project_names.py | python3 - $DIR_TO_SEARCH; }
4285

4386
if [ -f /.dockerenv ]; then

0 commit comments

Comments
 (0)