Skip to content
Snippets Groups Projects
custom_before_install 6.47 KiB
Newer Older
#!/bin/bash

rm -rf "$build_dir" "$install_dir"

. `dirname $0`/common.sh

# Set debug mode
set -x
set -v

# Add robotpkg
sudo sh -c "echo \"deb [arch=amd64] http://robotpkg.openrobots.org/packages/debian/pub $(lsb_release -cs) robotpkg\" >> /etc/apt/sources.list "
curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -

# show memory usage before install
sudo free -m -t

# Setup environment variables.
export APT_DEPENDENCIES="doxygen libboost-system-dev libboost-test-dev libboost-filesystem-dev libboost-program-options-dev libeigen3-dev liburdfdom-dev texlive-font-utils"
# Add Python dependency
export APT_DEPENDENCIES=$APT_DEPENDENCIES" libboost-python-dev robotpkg-py27-eigenpy python2.7-dev python-numpy gfortran libblas-dev liblapack-dev"

# Add Geometry dependencies
if [[ $BUILD_WITH_COLLISION_SUPPORT -eq ON ]]; then 
  export APT_DEPENDENCIES=$APT_DEPENDENCIES" robotpkg-hpp-fcl"
fi 

##############################
#  --  Helper functions  --  #
##############################

_linux_setup_package_source()
{
  # Speed up apt
  ${SUDO_CMD} sh -c "echo \"force-unsafe-io\" > /etc/dpkg/dpkg.cfg.d/02apt-speedup"
  # Update the apt local cache.
  ${SUDO_CMD} apt-get update -qq
}

_osx_setup_package_source()
{
  # Update homebrew
  brew update
}

# setup_package_source
# ---------------------
#
# Setup the package source (e.g. homebrew on osx, apt on debian-like systems)
setup_package_source()
{
  if [[ ${CI_OS_NAME} = linux ]]; then
    _linux_setup_package_source
  fi
  if [[ ${CI_OS_NAME} = osx ]]; then
    _osx_setup_package_source
  fi
}

# setup_pbuilder
# --------------
#
# Setup a pbuilder environment
setup_pbuilder()
{
  if `test x${DIST} = x`; then
      echo "distribution is not set, skipping this build"
      exit 0
  fi
  echo "Target distribution: ${DIST}"

  # If we are, we install Debian package development tools and
  # create a sid pbuilder. Package dependencies will be installed
  # automatically.
  ${SUDO_CMD} apt-get install -qq        		\
      debootstrap devscripts			\
      git-buildpackage debian-archive-keyring \
      pkg-kde-tools dput eatmydata ccache

  # Fix ccache use in pbuilder
  ${SUDO_CMD} addgroup --system --gid 1234 ccache
  ${SUDO_CMD} adduser --quiet --system --uid 1234 --ingroup ccache \
      --home /var/cache/pbuilder --no-create-home pbuilder
  ${SUDO_CMD} mkdir -p /var/cache/pbuilder/ccache
  ${SUDO_CMD} chown -R pbuilder:ccache /var/cache/pbuilder/ccache
  ${SUDO_CMD} chmod -R g+ws /var/cache/pbuilder/ccache

  # Remove previous sandbox.
  ${SUDO_CMD} rm -rf /var/cache/pbuilder/base-${DIST}.cow || true

  # Create a pbuilder sandbox.
  cp -f `dirname $0`/pbuilderrc $HOME/.pbuilderrc
  sed -i "s|@DIST@|${DIST}|g" $HOME/.pbuilderrc

  git-pbuilder create

  # Speed up pbuilder.
  echo "echo \"force-unsafe-io\" > /etc/dpkg/dpkg.cfg.d/02apt-speedup" | \
      git-pbuilder login --save-after-exec

  # Add additional PPAs
  for ppa in ${DEBIAN_PPA}; do
      echo "apt-add-repository ppa:${ppa}" | \
          git-pbuilder login --save-after-exec
  done

  # Retrieve PPA package list.
  git-pbuilder update

  # FIXME There is something fishy here...
  # ccache is not necessary in our case and may cause permission
  # issues.
  echo "apt-get -y remove ccache" |        		\
      git-pbuilder login --save-after-exec
}

# catkin_git_dependency
# --------------------
#
# Clone catkin package into the workspace
# See arguments of build_git_dependency
# Branch defaults to $ROS_DISTRO instead of master
catkin_git_dependency()
{
  git_dependency_parsing $1 $ROS_DISTRO
  echo "--> Getting $git_dep (branch $git_dep_branch)"
  CATKIN_DEP_WORKSPACE=/tmp/_ci/catkin_dep_ws
  cd $CATKIN_DEP_WORKSPACE/src
  $git_clone -b $git_dep_branch "$git_dep_uri" "$git_dep"
}

# catkin_build_workspace
# ----------------------
#
# Build catkin workspace
catkin_build_workspace()
{
  CATKIN_DEP_WORKSPACE=/tmp/_ci/catkin_dep_ws
  cd $CATKIN_DEP_WORKSPACE
  catkin_make
}

# build_git_dependency
# --------------------
#
# Build a dependency directly from the Git development tree.
# First argument: repository's GitHub URL or repository's URI + optional branch
# For example: "jrl-umi3218/jrl-travis" or "jrl-umi3218/jrl-travis#dev"
# Or: user@host:path/to/repo or git@github.com:organization/repo#branch
build_git_dependency()
{
  git_dependency_parsing $1
  echo "--> Compiling $git_dep (branch $git_dep_branch)"
  cd "$build_dir"
  mkdir -p "$git_dep"
  $git_clone -b $git_dep_branch "$git_dep_uri" "$git_dep"
  cd "$git_dep"
  mkdir -p build
  cd build
  cmake .. -DCMAKE_INSTALL_PREFIX:STRING="$install_dir" \
          -DDISABLE_TESTS:BOOL=ON ${CMAKE_ADDITIONAL_OPTIONS}
  make install || make
}

_osx_install_dependencies()
{
  # Install user-specified packages
  brew install cppcheck ${HOMEBREW_DEPENDENCIES}
}

_linux_install_dependencies()
{
  # Add additional PPAs
  for ppa in ${MASTER_PPA}; do
    ${SUDO_CMD} add-apt-repository -y ppa:${ppa}
  done
  ${SUDO_CMD} apt-get update -qq

  ${SUDO_CMD} apt-get install -qq curl cppcheck ${APT_DEPENDENCIES}

  # Install lcov from github 
  cd "$build_dir"
  wget https://github.com/linux-test-project/lcov/releases/download/v1.12/lcov-1.12.tar.gz
  tar zxvf lcov-1.12.tar.gz
  cd lcov-1.12
  # Reset lcov to release 1.12
  ${SUDO_CMD} make install

  gem install coveralls-lcov
}

install_dependencies()
{
  if [[ ${CI_OS_NAME} = linux ]]; then
    _linux_install_dependencies
  fi
  if [[ ${CI_OS_NAME} = osx ]]; then
    _osx_install_dependencies
  fi
  # and we build directly dependencies from the Git repository
  for package in ${ROS_GIT_DEPENDENCIES}; do
    catkin_git_dependency "$package"
  done
  if `test "x${ROS_GIT_DEPENDENCIES}" != x`; then
    catkin_build_workspace
  fi

  for package in ${GIT_DEPENDENCIES}; do
    build_git_dependency "$package"
  done
}

#########################
#  --  Main script  --  #
#########################

# Print Git version
git --version

# Setup Git identity.
git config --global user.name "JRL/IDH Continuous Integration Tool"
git config --global user.email "jrl-idh+ci@gmail.com"

# Retrieve the submodules.
git submodule update --quiet --init --recursive

# Fetch tags to compute the distance between the last release tag
# and us.
git fetch --quiet --tags

# Shortcuts.
git_clone="git clone --quiet --recursive"

# Display environment
echo "Environment:"
env


setup_package_source

# Check if we are in a debian branch...
if [ -d debian ]; then
  setup_pbuilder
else
  if [ ! x${DIST} = x ]; then
    echo "skipping this build"
    exit 0
  fi
  install_dependencies
fi

# End debug mode
set +v
set +x