-
Notifications
You must be signed in to change notification settings - Fork 6
/
ros2_build.sh
executable file
·58 lines (49 loc) · 2.18 KB
/
ros2_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -xe
# install dependencies
sudo apt-get update && sudo apt-get install -y python3 python3-pip lcov cmake && rosdep update
sudo apt-get update && sudo apt-get install -y python3-rosinstall python3-colcon-common-extensions && sudo -H pip3 install -U setuptools coverage pytest
apt list --upgradable 2>/dev/null | awk {'print $1'} | sed 's/\/.*//g' | grep ${ROS_DISTRO} | xargs sudo apt-get install -y
# NOTE: Workaround for setuptools 50.0.* (see https://github.com/pypa/setuptools/issues/2352)
export SETUPTOOLS_USE_DISTUTILS=stdlib
REPO_NAME=$(basename -- ${TRAVIS_BUILD_DIR})
echo "repo: ${REPO_NAME} branch: ${TRAVIS_BRANCH}"
. "/opt/ros/${ROS_DISTRO}/setup.sh"
cd "/${ROS_DISTRO}_ws/"
if [ "${TRAVIS_BRANCH}" == "master" ] && [ -f "./src/${REPO_NAME}/.rosinstall.master" ]; then
mkdir dep
cd "/${ROS_DISTRO}_ws/dep"
ln -s "../src/${REPO_NAME}/.rosinstall.master" .rosinstall
rosws update
cd "/${ROS_DISTRO}_ws/"
rosdep install --from-paths src dep --ignore-src --rosdistro "${ROS_DISTRO}" -r -y
else
rosdep install --from-paths src --ignore-src --rosdistro "${ROS_DISTRO}" -r -y
fi
# use colcon as build tool to build the package, and optionally build tests
colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage' -DCMAKE_C_FLAGS='-fprofile-arcs -ftest-coverage'
# run unit tests
if [ -z "${NO_TEST}" ]; then
. ./install/setup.sh
if [ "${TRAVIS_BRANCH}" == "master" ] && [ -d "./dep" ]; then
touch dep/COLCON_IGNORE
fi
set +e
colcon test --pytest-args --cov=. --cov-report=xml
set -e
colcon test-result --all --verbose
# get unit test code coverage result
case ${PACKAGE_LANG} in
"cpp")
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --list coverage.info
cd "/${ROS_DISTRO}_ws/"
sudo cp coverage.info /shared/
;;
"python")
# this doesn't actually support multiple packages
sudo cp src/${REPO_NAME}/${PACKAGE_NAMES}/coverage.xml /shared/coverage.info
;;
esac
fi