Skip to content

Commit

Permalink
Refactor .travis.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Jul 14, 2018
1 parent af27e91 commit 8fb6468
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 100 deletions.
159 changes: 59 additions & 100 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

language: cpp
dist: trusty
sudo: required
sudo: false

os:
- linux
Expand All @@ -20,29 +20,34 @@ matrix:

env:
global:
# avoid ALSA errors
- SDL_AUDIODRIVER=dummy
# YCM cache
- YCM_VER=0.8.1
- YCM_CACHE_DIR=~/.ycm
# YARP cache
- YARP_VER=2.3.72
- YARP_CACHE_DIR=~/.yarp
- SDL_AUDIODRIVER=dummy # avoid ALSA errors
- CACHE_DIR=~/cached-deps # common cache location
matrix:
- YARP_CHECKOUT=master
- YARP_CHECKOUT=v2.3.72.1
- YARP_CHECKOUT=v2.3.70.2

cache:
directories:
- $YCM_CACHE_DIR
- $YARP_CACHE_DIR
directories: $CACHE_DIR

addons:
apt:
packages:
- libjpeg-dev
- libsdl2-dev
- libsdl2-image-dev
- libsdl2-mixer-dev
- libsdl2-ttf-dev
- libzbar-dev
- libgtest-dev
- lcov
- doxygen

branches:
except:
- /^.*appveyor.*$/

before_install:
# ubuntu dependencies
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq update; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -y --no-install-recommends install libace-dev libjpeg-dev libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libzbar-dev libgtest-dev; fi

# OS X dependencies
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export XQUARTZ_VERSION=2.7.6;fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then curl -L -O http://xquartz.macosforge.org/downloads/SL/XQuartz-${XQUARTZ_VERSION}.dmg; fi
Expand All @@ -55,85 +60,48 @@ before_install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew tap homebrew/science; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install opencv; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install --with-qt3support qt; fi
#use the same set of cmake options used in the dashboard build
# - source ./admin/scripts/generate-cmake-options.sh # no special cmake options for now.

# prepare CMake options for YARP builds
- export YARP_CMAKE_OPTIONS="-DCREATE_OPTIONAL_CARRIERS:BOOL=ON -DENABLE_yarpcar_mjpeg:BOOL=ON"

# print system info
- cmake --version
#-- Code coverage
- if [ "$CXX" = "g++" ]; then gem install coveralls-lcov; fi

install:
# clone and build YCM if not in cache
- >-
if [ ! "$(ls -A "$YCM_CACHE_DIR")" ] || [ ! -f "$YCM_CACHE_DIR/.version" ] || [ ! $(cat "$YCM_CACHE_DIR/.version") = "$YCM_VER" ]; then
echo "YCM not in cache or wrong version"
rm -rf "$YCM_CACHE_DIR"/*
cd
wget -qO- "https://github.com/robotology/ycm/archive/v$YCM_VER.tar.gz" | tar xz
mkdir -p "ycm-$YCM_VER/build" && cd "$_"
cmake .. -DCMAKE_INSTALL_PREFIX:PATH="$YCM_CACHE_DIR"
make -j2 install
echo "$YCM_VER" > "$YCM_CACHE_DIR/.version"
else
echo "YCM directory found in cache (version $(cat "$YCM_CACHE_DIR/.version"))"
fi
# make installed YCM discoverable by CMake's find_package() command
- export YCM_DIR=$YCM_CACHE_DIR/share/YCM/cmake

# clone and build YARP if not in cache
- >-
if [ "$TRAVIS_EVENT_TYPE" = cron ]; then
echo "Cloning YARP's devel branch"
cd
git clone --depth=1 --branch=devel https://github.com/robotology/yarp
mkdir -p yarp/build && cd "$_"
cmake .. $YARP_CMAKE_OPTIONS
sudo make -j2 install
elif [ ! "$(ls -A "$YARP_CACHE_DIR")" ] || [ ! -f "$YARP_CACHE_DIR/.version" ] || [ ! $(cat "$YARP_CACHE_DIR/.version") = "$YARP_VER" ]; then
echo "YARP not in cache or wrong version"
rm -rf "$YARP_CACHE_DIR"/*
cd
wget -qO- "https://github.com/robotology/yarp/archive/v$YARP_VER.tar.gz" | tar xz
mkdir -p "yarp-$YARP_VER/build" && cd "$_"
cmake .. -DCMAKE_INSTALL_PREFIX:PATH="$YARP_CACHE_DIR" $YARP_CMAKE_OPTIONS
make -j2 install
echo "$YARP_VER" > "$YARP_CACHE_DIR/.version"
else
echo "YARP directory found in cache (version $(cat "$YARP_CACHE_DIR/.version"))"
fi
# make installed YARP discoverable by CMake's find_package() command
- if [ ! "$TRAVIS_EVENT_TYPE" = cron ]; then export YARP_DIR=$YARP_CACHE_DIR/lib/cmake/YARP; fi

# clone and build color-debug
- cd
- git clone https://github.com/roboticslab-uc3m/color-debug
- mkdir -p color-debug/build && cd "$_"
- cmake ..
- sudo make -j2 install

# clone and build yarp-devices
- cd
- git clone https://github.com/asrob-uc3m/yarp-devices
- mkdir -p yarp-devices/build && cd "$_"
- cmake ..
- sudo make -j2 install

# see http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/
- cd
- if [ "$CXX" = "g++" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz; fi
- if [ "$CXX" = "g++" ]; then tar xf lcov_1.11.orig.tar.gz; fi
- if [ "$CXX" = "g++" ]; then sudo make -C lcov-1.11/ install; fi
- if [ "$CXX" = "g++" ]; then gem install coveralls-lcov; fi
#-- Install YCM
- >
source "$TRAVIS_BUILD_DIR/scripts/travis/git-cache-dependency.sh"
--package-name YCM
--repo-url https://github.com/robotology/ycm
--repo-checkout "${ROBOTOLOGY_CHECKOUT:-${YCM_CHECKOUT:-master}}"
#-- Install YARP
- >
source "$TRAVIS_BUILD_DIR/scripts/travis/git-cache-dependency.sh"
--package-name YARP
--repo-url https://github.com/robotology/yarp
--repo-checkout "${ROBOTOLOGY_CHECKOUT:-$YARP_CHECKOUT}"
--additional-cmake-options "-DSKIP_ACE:BOOL=ON -DCREATE_OPTIONAL_CARRIERS:BOOL=ON -DENABLE_yarpcar_mjpeg:BOOL=ON"
--prepend-to-linker-path lib
--additional-export-paths "YARP_DATA_DIRS;share/yarp"
#-- Install color-debug
- >
source "$TRAVIS_BUILD_DIR/scripts/travis/git-cache-dependency.sh"
--package-name COLOR_DEBUG
--repo-url https://github.com/roboticslab-uc3m/color-debug
--repo-checkout master
#-- Install yarp-devices
- >
source "$TRAVIS_BUILD_DIR/scripts/travis/git-cache-dependency.sh"
--package-name ROBOTICSLAB_YARP_DEVICES
--repo-url https://github.com/asrob-uc3m/yarp-devices
--repo-checkout develop
--additional-export-paths "YARP_DATA_DIRS;share/asrob-yarp-devices"
before_script:
- mkdir -p "$TRAVIS_BUILD_DIR/build" && cd "$_"
- cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$PWD/install -DENABLE_coverage:BOOL=ON
- cmake .. -DCMAKE_INSTALL_PREFIX:PATH="$PWD/install" -DENABLE_coverage:BOOL=ON
- cmake --build . --target install
- export YARP_DATA_DIRS=$YARP_DATA_DIRS:$PWD/install/share/rd
- export YARP_DATA_DIRS=$PWD/install/share/rd:$YARP_DATA_DIRS

# SDL stuff
- "export DISPLAY=:99.0"
Expand All @@ -156,19 +124,10 @@ script:
- bin/testRobotDevastation

after_success:
# capture coverage info
- if [ "$CXX" = "g++" ]; then lcov --directory . --capture --output-file coverage.info; fi
# filter out system and test code
- if [ "$CXX" = "g++" ]; then lcov --remove coverage.info '/usr/*' 'test/*' --output-file coverage.info; fi
# debug before upload
- if [ "$CXX" = "g++" ]; then lcov --list coverage.info; fi
# uploads to coveralls
#- if [ "$CXX" = "g++" ]; then coveralls-lcov --source-encoding=ISO-8859-1 --repo-token InWqFy6VWMrEUzr2Rn8XV0cGqv3wXWo2d coverage.info; fi
- if [ "$CXX" = "g++" ]; then coveralls-lcov --source-encoding=ISO-8859-1 coverage.info; fi
#-- Code coverage
- if [ "$CXX" = "g++" ]; then source "$TRAVIS_BUILD_DIR/scripts/travis/coverage.sh"; fi

before_deploy:
# install again, now with generated documentation
- sudo apt-get -y --no-install-recommends install doxygen
- cmake .. -DGENERATE_doc_html:BOOL=ON
- cmake --build . --target dox
- cmake --build . --target install
Expand All @@ -179,7 +138,7 @@ deploy:
provider: releases
api_key:
secure: DORjZTWdhauq/l3s+pQj0ywjtkKxb00YNy9Tj3RH5+4I8/aRF2u6nFP61tnLUEEzz6GcEDp/lyIOtbuOI+hKO2M4Nq2stI++8FNvPjA8sdmNGXm3w2yIQFY+wFwZyLcn9y3l/7I8FeiQnfFk47/vHfy5DrdsqOr3Z6Ub7xINpKM=
file_glob: true
file_glob: true
file: '*.tar.gz'
skip_cleanup: true
on:
Expand Down
17 changes: 17 additions & 0 deletions scripts/travis/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set +e

# see http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/

#-- Capture coverage info
lcov --directory . --capture --output-file coverage.info

#-- Filter out system and test code
lcov --remove coverage.info '/usr/*' 'tests/*' --output-file coverage.info

#-- Debug before upload
lcov --list coverage.info

#-- Upload to coveralls
coveralls-lcov --source-encoding=ISO-8859-1 coverage.info
139 changes: 139 additions & 0 deletions scripts/travis/git-cache-dependency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env bash

set -e

#-- Initialize variables
package_name=
repo_url=
repo_checkout=
clone_only_branches="master devel develop production"
cmake_home_dir=
additional_cmake_options=
prepend_to_linker_path=
prepend_to_standard_path=
additional_export_paths=

#-- Available getopt long option names
#-- https://gist.github.com/magnetikonline/22c1eb412daa350eeceee76c97519da8
ARGUMENT_LIST=(
"package-name"
"repo-url"
"repo-checkout"
"clone-only-branches"
"cmake-home-dir"
"additional-cmake-options"
"prepend-to-linker-path"
"prepend-to-standard-path"
"additional-export-paths"
)

#-- Read arguments
opts=$(getopt \
--longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "${BASH_SOURCE[0]}")" \
--options "" \
-- "$@"
)

eval set -- $opts

#-- Parse options
while [ "$#" -gt 1 ]; do
in=$(echo "$1" | sed -e 's/^--//')
for v in "${ARGUMENT_LIST[@]}"; do
if [ "$v" = "$in" ]; then
declare "$(echo "$v" | tr '-' '_')"="$2"
break
fi
done
shift 2
done

#-- Check required arguments
if [ -z "$package_name" ] || [ -z "$repo_url" ] || [ -z "$repo_checkout" ]; then
echo "Missing required options. Traceback:"
for v in "${ARGUMENT_LIST[@]}"; do
v_param=$(echo $v | tr '-' '_')
echo " --$v=${!v_param}"
done
return 1
fi

#-- Configure paths
repo_source_dir=~/"$package_name-$repo_checkout"
repo_build_dir="$repo_source_dir/build"
repo_cache_dir="$CACHE_DIR/$package_name-$repo_checkout"
cmake_home_dir="$repo_source_dir/$cmake_home_dir"

#-- Configure CMake command line options
repo_cmake_options="$additional_cmake_options -DCMAKE_INSTALL_PREFIX:PATH=$repo_cache_dir"

is_clone_only_branch=false

for branch in $clone_only_branches; do
if [ "$repo_checkout" = "$branch" ]; then
is_clone_only_branch=true
break
fi
done

if $is_clone_only_branch; then

#-- Clone, build and store in cache

echo "Cloning $package_name's $repo_checkout branch"
git clone --depth=1 --branch="$repo_checkout" "$repo_url" "$repo_source_dir"
last_commit_sha=$(git -C "$repo_source_dir" rev-parse HEAD)

if [ ! -d "$repo_cache_dir" ] || \
[ ! -f "$repo_cache_dir/.last_commit_sha" ] || \
[ ! "$(cat $repo_cache_dir/.last_commit_sha)" = "$last_commit_sha" ];
then
echo "$package_name not in cache or not the latest commit of $repo_checkout branch"
rm -rf "$repo_cache_dir"/*
cmake -H"$cmake_home_dir" -B"$repo_build_dir" $repo_cmake_options
make -C "$repo_build_dir" -j$(nproc) install
echo "$last_commit_sha" > "$repo_cache_dir/.last_commit_sha"
else
echo "$package_name found in cache ($(cat $repo_cache_dir/.last_commit_sha))"
fi

else

#-- Download zipped file from archive, build and store in cache

if [ ! -d "$repo_cache_dir" ]; then
echo "Downloading $package_name $repo_checkout from archive"
wget -q "$repo_url/archive/$repo_checkout.tar.gz" -P "$repo_source_dir"
tar xzf "$repo_source_dir/$repo_checkout.tar.gz" -C "$repo_source_dir" --strip-components=1
cmake -H"$cmake_home_dir" -B"$repo_build_dir" $repo_cmake_options
make -C "$repo_build_dir" -j$(nproc) install
else
echo "$package_name $repo_checkout already in cache"
fi

fi

#-- Make installed package discoverable by CMake's find_package() command
export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH:$repo_cache_dir"

#-- Miscellanea, prepends stuff to LD_LIBRARY_PATH and PATH

if [ ! -z "$prepend_to_linker_path" ]; then
export LD_LIBRARY_PATH="$repo_cache_dir/$prepend_to_linker_path:$LD_LIBRARY_PATH"
fi

if [ ! -z "$prepend_to_standard_path" ]; then
export PATH="$repo_cache_dir/$prepend_to_standard_path:$PATH"
fi

#-- Expands lists of values of the form 'VAR1;val1;VAR2;val2;...' to:
#-- export VAR1=val1
#-- export VAR2=val2
#-- ...
if [ ! -z "$additional_export_paths" ]; then
IFS=';' read -ra ITEMS <<< "$additional_export_paths"
for (( count=0; count<"${#ITEMS[@]}"; count+=2 )); do
export "${ITEMS[$count]}"="$repo_cache_dir/${ITEMS[$(( $count+1 ))]}:${!ITEMS[$count]}"
done
fi

0 comments on commit 8fb6468

Please sign in to comment.