Upgrading TravisCI Build Scripts

If you’ve been running any TravisCI builds lately, you might have noticed the little yellow warning This job ran on our legacy infrastructure. Please read our docs on how to upgrade. Initially the upgrade they mention is pretty straight forward until one needs a specific version of a certain package, such as g++–4.8 or even installing Google’s GTest which is quite a hassle without sudo.

One of the main reasons for upgrading would be the increased performance and faster build times. My builds usually startup only a few seconds after my git push, which is remarkable compared to the 45 second wait times I’ve become accustomed to.

Original .travis.yml

My original travis file required sudo to run the apt-get installs and also to build and bind the gtest libraries.

language: cpp
sudo: required
compiler: gcc
before_install:
    - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
    - sudo apt-get update

install:
    - sudo apt-get install clang-3.4
    - sudo apt-get install g++-4.8
    - sudo apt-get install libgtest-dev
    - cd /usr/src/gtest
    - sudo cmake .
    - sudo make
    - sudo mv libg* /usr/local/lib/
    - cd -
    - sudo apt-get install libboost-all-dev
    - sudo apt-get install valgrind
    - sudo apt-get install doxygen

before_script:
    - uname -a
    - printenv
    - clang++ --version 2>&1 | grep clang
    - g++-4.8 --version 2>&1 | grep g++-4.8
    - dpkg -l libgtest-dev | grep libgtest
    - gcov-4.6 --version | grep gcov
    - gcov-4.8 --version | grep gcov
    - valgrind --version
    - grep "#define BOOST_VERSION " /usr/include/boost/version.hpp
    - doxygen --version

script:
    - date
    - ls -al
    - make Collatz.log
    - make collatz-tests
    - ls -al
    - make html
    - ls -al
    - make test
    - make clean
    - make test CXX=clang++
    - ls -al
    - make check

So for the new infrastructure we need to remove sudo and start installing packages via addons.apt.packages and addons.apt.sources.

Updated .travis.yml

language: cpp
compiler: gcc
sudo: false
addons:
  apt: 
   sources: 
      - ubuntu-toolchain-r-test
   packages:
      - gcc-4.8 
      - g++-4.8
      - gcov-4.6
      - clang
      - doxygen
      - valgrind
      - libgtest-dev
      - libboost-dev

before_script:
    - uname -a
    - printenv
    - clang++ --version 2>&1 | grep clang
    - g++ --version 2>&1 | grep g++
    - gcov --version | grep gcov
    - valgrind --version
    - grep "#define BOOST_VERSION " /usr/include/boost/version.hpp
    - doxygen --version

install: 
    # Install gtest without sudo 
    - mkdir ~/gtest && cd ~/gtest
    - export LIBRARY_PATH=$(pwd)
    - cp -r /usr/src/gtest/* ./
    - cmake -D CMAKE_INSTALL_PREFIX:PATH=./ ./
    - make
    - cd -

script:
    - ls -al
    - make Collatz.log
    - make collatz-tests
    - ls -al
    - make html
    - ls -al
    - make test
    - make clean
    - make test CXX=clang++
    - ls -al
    - make check

So we replaced the sudo required with sudo: false. We also had to find a source repository where to install g++–4.8 from… because by default the container comes with g++ version 4.6 which doesn’t support -std=c++11. So where to install it from is quite a mystery if you’re not familiar with apt-get. Apt-get has a bunch of repositories that contain these packages and TravisCI has whitelisted a good couple. But the main one we need is ubuntu-toolchain-r-test and so we add it as a source.

Then for the most part we are free to add any packages from that source .

We also installed gtest without sudo. This requires installing the package as one would normally, through apt-get. But when it comes to the compiling step we need to add a build path. cmake -D CMAKE_INSTALL_PREFIX:PATH=./ ./
which builds the dynamic libraries in the current folder.

I also converted our Python 3 scripts, but those were a little more straight forward and didn’t require too many changes.

language: python
python:
- “3.4”
sudo: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- python-numpy

before_script:
- uname -a
- set
- pip -V
- pip freeze
- python -V
- coverage3 help | grep version
- python -c “import numpy; print(numpy.version)”

script:
- make collatz-tests
- make Collatz.html
- make Collatz.log
- make test
- make check
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s