# Use, modification, and distribution are
# subject to 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)
#
# Copyright Antony Polukhin 2014.

#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
# and how it can be used with Boost libraries.
#

language: cpp

branches:
  only:
    - master

env:
    - CXX_STANDARD=c++17 BRANCH_TO_TEST=master
    - CXX_STANDARD=c++14 BRANCH_TO_TEST=master
    - CXX_STANDARD=c++11 BRANCH_TO_TEST=master
    - CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.58.0
    - CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.59.0
    - CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.67.0

compiler:
  - clang
  - gcc

addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    - llvm-toolchain-precise
    packages:
    - gcc-5
    - g++-5
    - clang-5.0
    - lld-5.0
    - xsltproc
    - docbook-xsl
    - docbook-xml

before_install:
    - DOCBOOK_XSL_DIR=/usr/share/xml/docbook/stylesheet/docbook-xsl
    - DOCBOOK_DTD_DIR=/usr/share/xml/docbook/schema/dtd/4.2

    - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
    - gcc --version

    # Set this to the name of your Boost library
    # Autodetect library name by using the following code: - PROJECT_TO_TEST=$(basename $(pwd))
    - PROJECT_TO_TEST=$(basename $(pwd))

    # Files, which coverage results must be ignored (files from other projects). Example: - IGNORE_COVERAGE='*/boost/progress.hpp */filesystem/src/path.cpp'
    - IGNORE_COVERAGE='*/boost-local/*'

    # From this point and below code is same for all the Boost libs
    # Cloning Boost libraries (fast nondeep cloning)
    - PROJECT_DIR=`pwd`
    - git --version
    - BOOST=$HOME/boost-local
    - git clone -b $BRANCH_TO_TEST https://github.com/boostorg/boost.git $BOOST
    - cd $BOOST
    - git submodule update --init --merge
    - ./bootstrap.sh
    - ./b2 headers

script:
    - cd $PROJECT_DIR/build
    - export BOOST_ROOT=$BOOST
    # `--coverage` flags required to generate coverage info for Coveralls
    - ./build.sh --toolset=$CC "cxxflags=-std=$CXX_STANDARD -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations --coverage" "linkflags=--coverage" -j3
    - cd $BOOST && ./b2 --with-test --with-thread --with-chrono --with-system --with-atomic --with-date_time -a -j3 # Build required libs
    - mkdir $PROJECT_DIR/__build && cd $PROJECT_DIR/__build
    - export CXXFLAGS="-std=$CXX_STANDARD"
    - cmake .. -DCMAKE_BUILD_TYPE=Debug
    - cmake --build . --config Debug -- -j3
    - ctest --output-on-failure --build-config Debug

after_success:
    - COVERALS_DIR=$PROJECT_DIR/coverals

    # Copying Coveralls data to a separate folder
    - mkdir -p $COVERALS_DIR
    - find $PROJECT_DIR/test/bin/ -name "*.gcda" -exec cp "{}" $COVERALS_DIR/ \;
    - find $PROJECT_DIR/test/bin/ -name "*.gcno" -exec cp "{}" $COVERALS_DIR/ \;

    # Preparing Coveralls data by
    # ... installing the tools
    - sudo apt-get install -qq python-yaml lcov
    # ... changing data format to a readable one
    - lcov --directory $COVERALS_DIR --base-directory $PROJECT_DIR/test --capture --output-file $COVERALS_DIR/coverage.info

    # ... erasing /test/ /example/ folder data
    - lcov --remove $COVERALS_DIR/coverage.info "/usr*" "/test/*" $IGNORE_COVERAGE "tests/*" "*/doc/examples/*" -o $COVERALS_DIR/coverage.info
    # Output what was collected
    - lcov --list $COVERALS_DIR/coverage.info

    # Sending data to Coveralls
    - cd $PROJECT_DIR
    - gem install coveralls-lcov
    - coveralls-lcov $COVERALS_DIR/coverage.info
