language: cpp
sudo: true
cache: apt
dist: trusty
group: deprecated-2017Q3
addons:
  apt:
    sources: &apt_sources
      - ubuntu-toolchain-r-test
      - sourceline: 'ppa:kalakris/cmake' # cmake 2.8 for precise
      - sourceline: 'ppa:adrozdoff/cmake' # cmake 3 for trusty
      - sourceline: 'ppa:h-rayflood/llvm'
      - sourceline: ppa:hvr/z3   # z3 for the smt interface package
    packages: &default_packages
      - cmake
      - libgmp-dev
      - libgoogle-perftools-dev
      - g++-4.9
      - clang-3.4

matrix:
  include:
   - os: linux
     dist: precise
     env:
       CMAKE_CXX_COMPILER=g++-4.9
       CMAKE_BUILD_TYPE=Release
       UPLOAD=ON
       STATIC=ON
       FIRST=1

   - os: linux
     env:
       CMAKE_CXX_COMPILER=clang++-3.4
       CMAKE_BUILD_TYPE=Release
       LEAN_EXTRA_MAKE_OPTS=-t0
       TCMALLOC=ON

   - os: linux
     addons: &gcc6_addons
       apt:
         sources: *apt_sources
         packages:
           - *default_packages
           - g++-6
           - gcc-6
     env:
       CMAKE_CXX_COMPILER=g++-6
       CMAKE_BUILD_TYPE=Release
       TCMALLOC=ON

   - os: linux
     addons: *gcc6_addons
     env:
       CMAKE_CXX_COMPILER=g++-6
       CMAKE_BUILD_TYPE=Release
       TESTCOV=ON

   - os: linux
     addons: *gcc6_addons
     env:
       CMAKE_CXX_COMPILER=g++-6
       CMAKE_BUILD_TYPE=Release
       MULTI_THREAD=OFF

   - os: linux
     addons:
       apt:
         sources: *apt_sources
         packages:
           - *default_packages
           - z3
     env:
       CMAKE_CXX_COMPILER=g++-4.9
       CMAKE_BUILD_TYPE=Release
       TEST=OFF
       TEST_LEANPKG_REGISTRY=ON

   - os: linux
     env:
       CMAKE_CXX_COMPILER=clang++-3.4
       CMAKE_BUILD_TYPE=Debug
       TCMALLOC=ON

   - os: linux
     dist: precise
     env:
       CMAKE_CXX_COMPILER=g++-4.9
       CMAKE_BUILD_TYPE=Debug

   - os: osx
     env:
       CMAKE_CXX_COMPILER=clang++
       CMAKE_BUILD_TYPE=Release
       UPLOAD=ON
       TEST_LEANPKG_REGISTRY=ON

   - os: osx
     env:
       CMAKE_CXX_COMPILER=g++
       CMAKE_BUILD_TYPE=Debug

before_install:
  - |
    if [[ $TRAVIS_OS_NAME == osx ]]; then
      brew update &&
      (brew install gcc || brew link --overwrite gcc) &&
      brew install gmp &&
      # workaround for https://github.com/travis-ci/travis-ci/issues/6307
      command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
      rvm get head || true
    fi

script:
  - set -e
  - mkdir -p build
  - cd build
  - if [[ $TESTCOV != ON ]]; then TESTCOV=OFF; fi
  - if [[ $TCMALLOC != ON ]]; then TCMALLOC=OFF; fi
  - if [[ $STATIC != ON ]]; then STATIC=OFF; fi
  - if [[ $MULTI_THREAD != OFF ]]; then MULTI_THREAD=ON; fi
  - OPTIONS=""
  - |
    if [[ $TRAVIS_EVENT_TYPE == cron ]]
    then
      # trigger AppVeyor build from first Travis job because they can't be bothered to let us set up a cron build
      [[ -n $FIRST ]] && curl -H "Authorization: Bearer $APPVEYOR_TOKEN" -H "Content-Type: application/json" https://ci.appveyor.com/api/builds -d '{"accountName": "leodemoura", "projectSlug": "lean", "branch": "master", "environmentVariables": {"APPVEYOR_SCHEDULED_BUILD": "True"}}'
      git fetch --unshallow --tags origin
      . ../script/setup_nightly.sh
    fi
  - cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE
          -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER
          -DTESTCOV=$TESTCOV
          -DTCMALLOC=$TCMALLOC
          -DMULTI_THREAD=$MULTI_THREAD
          -DSTATIC=$STATIC
          -DLEAN_EXTRA_MAKE_OPTS=$LEAN_EXTRA_MAKE_OPTS
          $OPTIONS
          ../src
  - make -j2
  - if [[ $TEST != OFF ]]; then yes "A" | travis_wait 60 ctest -j2 --output-on-failure; fi
  # - |
  #   # don't test packages when building nightly
  #   if [[ $TEST_LEANPKG_REGISTRY == ON && -z $LEAN_VERSION_STRING ]]; then
  #     (cd ../packages
  #      if [[ $TRAVIS_OS_NAME == linux ]]; then ../bin/leanpkg add "https://github.com/leanprover/smt2_interface"; fi
  #      ../bin/leanpkg configure
  #      for d in _target/deps/*; do (cd $d; ../../../../bin/leanpkg test); done)
  #   fi
  - if [[ $UPLOAD == ON ]]; then cpack; fi
  - if [[ $UPLOAD == ON && $GH_TOKEN && $TRAVIS_PULL_REQUEST == false && $TRAVIS_BRANCH == master ]]; then (cd ..; bash script/deploy_nightly.sh build/lean-*); fi
  - cd ..

after_script:
  - if [[ $TESTCOV == ON ]]; then bash <(curl -s https://codecov.io/bash) -x gcov-6; fi

notifications:
  email:
    recipients:
     - lean-build@googlegroups.com
    on_success: change
    on_failure: always

deploy:
  provider: releases
  api_key: $GH_TOKEN
  file_glob: true
  file: build/lean-*
  skip_cleanup: true
  overwrite: true
  on:
    condition: $UPLOAD = ON && $GH_TOKEN
    repo: leanprover/lean
    tags: true
