# Copyright (C) 2016 Daniel James.
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

# Use Trusty to get a reasonably recent version of Boost.
sudo: required
dist: trusty

language: c++

addons:
    apt:
        packages:
            - libxml2-utils
            - g++-multilib

matrix:
    include:
      - compiler: gcc
        env: |
            label="gcc C++03/11";
            user_config="using gcc : : g++-4.8 --coverage -fsanitize=address ;"
            enable_coverage=1
            CXXSTD=03,11
      - compiler: gcc
        env: |
            label="gcc 32 bit C++11";
            user_config="using gcc : : g++-4.8 -m32 -fsanitize=address ;"
            CXXSTD=11
      - compiler: clang
        env: |
            label="clang C++11/17";
            user_config="using clang : : clang++ -fsanitize=address ;"
            CXXSTD=11,17
        # sanitized=address not available for 32-bit clang on travis.
      - compiler: clang
        env: |
            label="clang 32 bit";
            user_config="using clang : : clang++ -m32 ;"
            CXXSTD=03

before_install:
    - if [ -n $enable_coverage ]; then pip install --user cpp-coveralls; fi

before_script:
    - export BOOST_VERSION=1.67.0
    - export BOOST_FILENAME=boost_1_67_0
    - export BOOST_ROOT=${HOME}/boost
    - cd ${TRAVIS_BUILD_DIR}
    - touch Jamroot.jam
    - cd $HOME
    - echo $user_config > ~/user-config.jam
    - cat ~/user-config.jam
    - |
        # Pick snapshot to use
        if [ "$TRAVIS_EVENT_TYPE" == "cron" ]
        then
            if [ "$TRAVIS_BRANCH" == "master" ]
            then
                snapshot=master
            else
                snapshot=develop
            fi
        else
            #snapshot=stable
            snapshot=master
        fi

        # Download and extract snapshot
        echo "Downloading ${download_url}"
        mkdir $HOME/download
        cd $HOME/download
        python ${TRAVIS_BUILD_DIR}/ci/download-boost-snapshot.py $snapshot
        mv * ${BOOST_ROOT}
    - rm -r ${BOOST_ROOT}/boost/unordered
    - cd ${BOOST_ROOT}/tools/build
    - mkdir ${HOME}/opt
    - bash bootstrap.sh
    - ./b2 install --prefix=$HOME/opt

after_success:
    if [ -n $enable_coverage ]; then coveralls -r ${TRAVIS_BUILD_DIR} -b ${TRAVIS_BUILD_DIR}/test --gcov-options '\-lp' --include include/boost/unordered/ ; fi

script:
    - cd ${TRAVIS_BUILD_DIR}/test
    - ${HOME}/opt/bin/b2 -j 3 cxxstd=$CXXSTD -q include=${BOOST_ROOT} include=${TRAVIS_BUILD_DIR}/include
    - xmllint --noout ${TRAVIS_BUILD_DIR}/doc/ref.xml
