sudo: required
dist: trusty
language: cpp
env:
  global:
    # By default, rho uses its own implementation of tar written in R.
    # It's really slow, so use system tar instead.
    - TAR=/bin/tar
    - R_BUILD_TAR=/bin/tar
    - R_INSTALL_TAR=/bin/tar
    # Use catchsegv to get useful stacktraces on failures.
    - RHO_DEBUGGER=catchsegv
    
matrix:
  include:
    # gcc 4.9
    - compiler: gcc
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - gcc-4.9
            - g++-4.9
            - gfortran-4.9
      env: FC=gfortran-4.9 F77=gfortran-4.9 C_COMPILER=gcc-4.9 CXX_COMPILER=g++-4.9

    # gcc 5.4
    - compiler: gcc
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - gcc-5=5.4.*
            - g++-5=5.4.*
            - gfortran-5=5.4.*
      env: FC=gfortran-5 F77=gfortran-5 C_COMPILER=gcc-5 CXX_COMPILER=g++-5

    # gcc 6.2 with code coverage.
    - compiler: gcc
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - gcc-6=6.2.*
            - g++-6=6.2.*
            - gfortran-6=6.2.*
      env: F77=gfortran-6 FCC=gfortran-6 C_COMPILER=gcc-6 CXX_COMPILER=g++-6 CFLAGS="-g -O1 --coverage" CXXFLAGS="${CFLAGS}" LDFLAGS="${CFLAGS}" COVERAGE=1

    # TODO: work out how to use clang 3.4 on travis.
    # - compiler: clang
    #   addons:
    #     apt:
    #       sources:
    #         - ubuntu-toolchain-r-test
    #       packages:
    #         - gfortran
    #         - libboost-all-dev
    #         - zlib1g-dev
    #         - libbz2-dev
    #         - liblzma-dev
    #         - libpcre3-dev
    #         - libedit-dev
    #         - clang-3.4
    #         - llvm-3.4-dev
    #   env: C_COMPILER=clang CXX_COMPILER=clang++ LLVM_CONFIG=/usr/bin/llvm-config-3.4

    # With address sanitizer enabled.  Use the most recent supported verison
    # of clang, to get the best error detection.
    # TODO: enable initialization order checking.
    - compiler: clang
      addons:
        apt:
          sources:
            - sourceline: "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main"
          packages:
            - gfortran
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - clang-3.8
            - llvm-3.8-dev
      env: C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 LLVM_CONFIG=/usr/bin/llvm-config-3.8 CPPFLAGS="-DNO_CELLPOOLS" CFLAGS="-g -O2 -fsanitize=address" CXXFLAGS="${CFLAGS}" MAIN_LDFLAGS="${CFLAGS}"

    # With undefined behaviour sanitizer enabled.  Use the most recent
    # supported verison of clang, to get the best error detection.
    - compiler: clang
      addons:
        apt:
          sources:
            - sourceline: "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main"
          packages:
            - gfortran
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - clang-3.8
            - llvm-3.8-dev
      env: C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 LLVM_CONFIG=/usr/bin/llvm-config-3.8 UBSAN_OPTIONS="print_stacktrace=1 suppressions=`pwd`/.ubsan_suppressions" CFLAGS="-g -O2 -fsanitize=undefined" CXXFLAGS="${CFLAGS}" MAIN_LDFLAGS="${CFLAGS}"

    - compiler: clang
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - gfortran
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - clang-3.5
            - llvm-3.5-dev
      env: C_COMPILER=clang-3.5 CXX_COMPILER=clang++-3.5 LLVM_CONFIG=/usr/bin/llvm-config-3.5

    - compiler: clang
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - gfortran
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - clang-3.6
            - llvm-3.6-dev
      env: C_COMPILER=clang-3.6 CXX_COMPILER=clang++-3.6 LLVM_CONFIG=/usr/bin/llvm-config-3.6

    - compiler: clang
      addons:
        apt:
          sources:
            - sourceline: "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.7 main"
          packages:
            - gfortran
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - clang-3.7
            - llvm-3.7-dev
      env: C_COMPILER=clang-3.7 CXX_COMPILER=clang++-3.7 LLVM_CONFIG=/usr/bin/llvm-config-3.7

    - compiler: clang
      addons:
        apt:
          sources:
            - sourceline: "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.8 main"
          packages:
            - gfortran
            - libboost-all-dev
            - zlib1g-dev
            - libbz2-dev
            - liblzma-dev
            - libpcre3-dev
            - libedit-dev
            - clang-3.8
            - llvm-3.8-dev
      env: C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 LLVM_CONFIG=/usr/bin/llvm-config-3.8 CPPFLAGS="-UNDEBUG -DCHECKED_SEXP_DOWNCAST -D_FORTIFY_SOURCE=2" CFLAGS="-g -O2 -fstack-protector-strong" CXXFLAGS=${CFLAGS}

  allow_failures:
    # Building with llvm 3.7 currently segfaults.  Needs investigating.
    - env: C_COMPILER=clang-3.7 CXX_COMPILER=clang++-3.7 LLVM_CONFIG=/usr/bin/llvm-config-3.7  
    # Likewise for the ubsan run.
    - env: C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8 LLVM_CONFIG=/usr/bin/llvm-config-3.8 UBSAN_OPTIONS="print_stacktrace=1 suppressions=`pwd`/.ubsan_suppressions" CFLAGS="-g -O2 -fsanitize=undefined" CXXFLAGS="${CFLAGS}" MAIN_LDFLAGS="${CFLAGS}"
    
before_install:
  - pip install --user codecov

script:
        - tools/rsync-recommended
        - ${CXX_COMPILER} --version
        - CC=${C_COMPILER} CXX=${CXX_COMPILER} ./configure
          --enable-werror
          --enable-llvm-jit=yes
          --with-llvm=$LLVM_CONFIG || cat config.log
        - travis_wait 60 make -j 2
        # Needed to prevent asan builds running out of memory.
        - sudo sh -c 'echo 1 > /proc/sys/vm/overcommit_memory'
        # TODO: upgrade to check-devel.
        - travis_wait 60 make -j 2 check
        
after_success:
  - if [ -n "$COVERAGE" ]; then bash <(curl -s https://codecov.io/bash) -x gcov-6 -g src/extra -g tests -X coveragepy ; fi
