Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 61 additions & 18 deletions .helper_bash_functions
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,79 @@ Color_Off='\033[0m' # Text Reset
CATKIN_WS_PATH="/cortex/.catkin_ws"
THIS_SCRIPT_BRANCH="main"
THIS_SCRIPT_URL="https://raw.githubusercontent.com/Extend-Robotics/er_build_tools/refs/heads/${THIS_SCRIPT_BRANCH}/.helper_bash_functions"

# ROS helpers
export ROSCONSOLE_FORMAT='[${severity}](${node}): [${time}] ${message}'
colcon_build() { START_DIR=$(pwd) && \
COLCON_BUILD_COMMAND="colcon build --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF" && \
if [ ! -z "$1" ];
then COLCON_BUILD_COMMAND="${COLCON_BUILD_COMMAND} --packages-up-to $1"
fi && \
cd ${CATKIN_WS_PATH} && \
source /opt/ros/noetic/setup.bash && \
echo -e "${Yellow}Running build command:\n${Green}${COLCON_BUILD_COMMAND}${Color_Off}" && \
${COLCON_BUILD_COMMAND}; RET_VAL=$?;\
source ${CATKIN_WS_PATH}/install/setup.bash; \
cd ${START_DIR}; \
return ${RET_VAL}
colcon_build() {
local COLCON_BUILD_COMMAND="colcon build --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF"
[ -n "$1" ] && COLCON_BUILD_COMMAND+=" --packages-up-to $1"
_colcon_build "$COLCON_BUILD_COMMAND"
return $?
}
colcon_build_no_deps() {
local COLCON_BUILD_COMMAND="colcon build --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF"
[ -n "$1" ] && COLCON_BUILD_COMMAND+=" --packages-select $1"
_colcon_build "$COLCON_BUILD_COMMAND"
return $?
}
colcon_build_sym() {
local COLCON_BUILD_COMMAND="colcon build --packages-skip-cache-valid --symlink-install --cmake-args -DSETUPTOOLS_DEB_LAYOUT=OFF"
[ -n "$1" ] && COLCON_BUILD_COMMAND+=" --packages-up-to $1"
_colcon_build "$COLCON_BUILD_COMMAND"
return $?
}
_colcon_build() {
local START_DIR="$(pwd)"
local COLCON_BUILD_COMMAND="$1"
cd "$CATKIN_WS_PATH" || return 1
source /opt/ros/noetic/setup.bash
echo -e "${Yellow}Running build command:\n${Green}${COLCON_BUILD_COMMAND}${Color_Off}"
eval "$COLCON_BUILD_COMMAND"
local RET_VAL=$?
source "$CATKIN_WS_PATH/install/setup.bash"
cd "$START_DIR"
return $RET_VAL
}
colcon_build_this() { colcon_build "$(find_cmake_project_names_from_dir .)"; }
colcon_build_er_interface() { colcon_build_no_deps "$(find_cmake_project_names_from_dir ${CATKIN_WS_PATH}/src/er_interface)"; }
colcon_test_er_interface() { colcon_test_this_package "$(find_cmake_project_names_from_dir ${CATKIN_WS_PATH}/src/er_interface)"; }
rosdep_install() { rosdep install --from-paths src --ignore-src -r -y ; }
colcon_test_these_packages() { THIS_DIR=$(pwd)
_show_test_failures() {
python3 - "$@" <<'PYEOF'
import sys, xml.etree.ElementTree as ET
from pathlib import Path
for d in sys.argv[1:]:
for p in sorted(Path(d).rglob("*.xml")):
for tc in ET.parse(p).iter("testcase"):
for f in list(tc.iter("failure")) + list(tc.iter("error")):
tag = "FAIL" if f.tag == "failure" else "ERROR"
print(f"\n {tag}: {tc.get('classname', '')}.{tc.get('name', '')}")
if f.text:
lines = f.text.strip().splitlines()
for l in lines[:20]:
print(f" {l}")
if len(lines) > 20:
print(f" ... ({len(lines) - 20} more lines)")
PYEOF
}
colcon_test_these_packages() { local THIS_DIR=$(pwd)
local VERBOSE_FLAG=""
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
VERBOSE_FLAG="--event-handlers console_direct+"
shift
fi
cd ${CATKIN_WS_PATH}
colcon_build_no_deps $1
colcon_build_no_deps "$1"
source install/setup.bash && \
colcon test --packages-select $1
colcon test --packages-select $1 ${VERBOSE_FLAG}
for pkg in $1; do
colcon test-result --verbose --test-result-base "build/$pkg"
if ! colcon test-result --test-result-base "build/$pkg/test_results"; then
_show_test_failures "build/$pkg/test_results"
fi
done
cd $THIS_DIR

}
colcon_test_this_package() { colcon_test_these_packages "$@"; } # Alias for backwards compatability
colcon_test_this_package() { colcon_test_these_packages "$@"; }
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; }

if [ -f /.dockerenv ]; then
Expand Down