dist: trusty
language: cpp
compiler:
 - g++-6
# - clang-4.0
sudo: false
os:
 - linux
# - osx
osx_image: xcode9
branches:
  only:
    - develop
    - better_optimisation
notifications:
  email:
    recipients:
      - nialldouglas14@gmail.com

addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
#    - george-edison55-precise-backports
#    - george-edison55-cmake-3.x
    - llvm-toolchain-trusty-4.0
    packages:
    - g++-6
    - clang-4.0
    - cmake
    - cmake-data
#    - abi-compliance-checker
    - abi-dumper
    - python3
    - python3-pip

env:
# - __="Code bloat tests"
# - __="ABI stability" NAME=TravisABICheck
# - __="Documentation" NAME=TravisDocumentation
 - __="cmake tests" NAME=TravisLinuxWorker
# - __="cmake tests osx" NAME=TravisOSXWorker
# - __="Installability"
 
#matrix:
#  exclude:
#  - os: osx
#    compiler: g++-6
#  - os: linux
#    compiler: clang-4.0
#    env: __="ABI stability" NAME=TravisABICheck
#  - os: linux
#    compiler: clang-4.0
#    env: __="Documentation" NAME=TravisDocumentation
#  - os: linux
#    env: __="cmake tests osx" NAME=TravisOSXWorker
#  - os: osx
#    env: __="Code bloat tests"
#  - os: osx
#    env: __="ABI stability" NAME=TravisABICheck
#  - os: osx
#    env: __="Documentation" NAME=TravisDocumentation
#  - os: osx
#    env: __="cmake tests" NAME=TravisLinuxWorker
 
cache:
  apt: true
  directories:
    - hugo_bin
    
before_install:
 - git config --global push.default simple
 - git config --global user.name "Jenkins nedprod CI"
 - git config --global user.email "foo@nowhere"
 - if [ ! -f "hugo_bin/hugo" ]; then
     wget -O hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0.52/hugo_0.52_Linux-64bit.tar.gz;
     mkdir hugo_bin;
     tar xf hugo.tar.gz -C hugo_bin;
   fi;
   ls -l hugo_bin;
   export PATH=$PATH:`pwd`/hugo_bin;
   
script:
 -
   if [ "$__" = "Code bloat tests" ]; then
     cd test/constexprs;
     ./compile_and_count.py;
     cat results.posix.xml;
     if grep -q "failure message" results.posix.xml; then
       exit 1;
     fi;
   fi
 -
   if [ "$__" = "ABI stability" ]; then
     pip install ply --user `whoami`;
     if [ "$CXX" = "g++" ]; then export CXX=g++-6; export NAME=TravisABICheck; fi;
     mkdir build;
     cd build;
     cmake .. -DCMAKE_BUILD_TYPE=Release;
     make outcome_hl-pp-abi;
     cd ../abi-compliance;
     sh ./check-abi.sh abi_dumps/Outcome/2.1/binary_only.dump;
   fi
#     sh ./check-api-abi.sh abi_dumps/Outcome/2.1/ABI.dump;
# -
#   if [ "$__" = "cmake tests" ]; then
#     if [ "$CXX" = "g++" ]; then export CXX=g++-6; export NAME=TravisLinuxWorkerGCC; fi;
#     if [ "$CXX" = "clang++" ]; then export CXX=clang++-4.0; export NAME=TravisLinuxWorkerClang; fi;
#     ctest -S .ci.cmake -V;
#   fi
 -
   if [ "$__" = "cmake tests osx" ]; then
     ctest -S .ci.cmake -V;
   fi
 - >
   if [ "$__" = "Documentation" ]; then
     cd doc/html;
     git checkout gh-pages;
     cd ../..;
     CXX=clang++-4.0 ctest -S .docs.cmake -V;
     cd doc/html;
     echo "google-site-verification: google5fc8a1f8de4b73f0.html" > google5fc8a1f8de4b73f0.html;
     git add . || true;
     git commit -a -m "Travis CI updates documentation" || true;
     git push -f https://jenkins-nedprod:$JENKINS_NEDPROD_PASSWORD@github.com/ned14/outcome gh-pages;
     cd ../..;
   fi
 -
   if [ "$__" = "Installability" ]; then
     if [ "$TRAVIS_OS_NAME" = "linux" ]; then
       if [ "$CXX" = "g++" ]; then export CXX=g++-6; export NAME=TravisLinuxWorkerGCC; fi;
       if [ "$CXX" = "clang++" ]; then export CXX=clang++-4.0; export NAME=TravisLinuxWorkerClang; fi;
     fi;
     git clone --depth 1 https://github.com/ned14/quickcpplib.git;
     pip3 install --user gitpython;
     python3 quickcpplib/scripts/test_cpp-pm_install.py conan/test_package/example.cpp quickcpplib quickcpplib::hl https://github.com/ned14/quickcpplib master outcome outcome::hl https://github.com/ned14/outcome master;
     cd test_cpp-pm_install;
     mkdir build;
     cd build;
     cmake .. -DCMAKE_BUILD_TYPE=Release;
     make;
   fi
 
after_success:
 -
   if [ "$__" = "cmake tests" ]; then
     pip install --user gitpython;
     git remote add outcome https://github.com/ned14/outcome;
     git fetch outcome;
     git submodule update --init;
     cd ..;
     git clone https://github.com/boostorg/outcome boost-outcome;
     cd boost-outcome;
     git checkout -b develop origin/develop;
     git checkout master;
     git remote add outcome https://github.com/ned14/outcome;
     git fetch outcome;
     git checkout -b orig-develop outcome/develop;
     git checkout -b orig-master outcome/master;
     git checkout master;
     cd ..;
     git clone --depth 1 https://github.com/ned14/quickcpplib.git;
     python quickcpplib/scripts/boostify_git_repo.py boost-outcome outcome ned14/outcome@;
     cd boost-outcome;
     git checkout master;
     cd doc/src;
     rm -rf ../html;
     HUGO_BOOSTDOCDISABLECOMMONHEADING=1 hugo;
     cd ../html;
     git add . || true;
     cd ../..;
     git commit -a -m "Travis CI regenerates Boost.Outcome docs" || true;
     git checkout develop;
     cd doc/src;
     rm -rf ../html;
     HUGO_BOOSTDOCDISABLECOMMONHEADING=1 hugo;
     cd ../html;
     git add . || true;
     cd ../..;
     git commit -a -m "Travis CI regenerates Boost.Outcome docs" || true;
     git push https://jenkins-nedprod:$JENKINS_NEDPROD_PASSWORD@github.com/boostorg/outcome master || true;
     git push https://jenkins-nedprod:$JENKINS_NEDPROD_PASSWORD@github.com/boostorg/outcome develop || true;
     cd doc;
     rm -rf html;
     git clone -b gh-pages --single-branch https://github.com/boostorg/outcome html;
     cd src;
     hugo;
     cd ../html;
     git add . || true;
     git commit -a -m "Travis CI regenerates Boost.Outcome docs" || true;
     git push -f https://jenkins-nedprod:$JENKINS_NEDPROD_PASSWORD@github.com/boostorg/outcome gh-pages;
     cd ../..;
   fi

after_failure:
