sudo: false
dist: trusty
language: cpp
os:
  - linux
  - osx
compiler:
  - clang
  - gcc
osx_image: xcode8.3
jdk:
  - oraclejdk7
cache:
  - ccache
  - apt

addons:
   apt:
      packages: ['zlib1g-dev', 'libbz2-dev', 'libsnappy-dev', 'curl', 'libgflags-dev', 'mingw-w64']
env:
  - TEST_GROUP=platform_dependent # 16-18 minutes
  - TEST_GROUP=1 # 33-35 minutes
  - TEST_GROUP=2 # 30-32 minutes
  # Run java tests
  - JOB_NAME=java_test # 4-11 minutes
  # Build ROCKSDB_LITE
  - JOB_NAME=lite_build # 3-4 minutes
  # Build examples
  - JOB_NAME=examples # 5-7 minutes
  - JOB_NAME=cmake # 3-5 minutes
  - JOB_NAME=cmake-mingw # 3 minutes

matrix:
  exclude:
  - os: osx
    env: TEST_GROUP=1
  - os: osx
    env: TEST_GROUP=2
  - os : osx
    env: JOB_NAME=cmake-mingw
  - os : linux
    compiler: clang
  - os : osx
    compiler: gcc

# https://docs.travis-ci.com/user/caching/#ccache-cache
install:
  - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
  - pwd
  - echo ${DEPS_DIR}
  - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR}
  - echo "${TRAVIS_OS_NAME}"
  - |
    if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
      CMAKE_URL="https://cmake.org/files/v3.6/cmake-3.6.3-Linux-x86_64.tar.gz"
      mkdir cmake && travis_retry wget --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake || travis_terminate 1;
      export "PATH=${DEPS_DIR}/cmake/bin:${PATH}";
    elif [ "${TRAVIS_OS_NAME}" == "osx" ]; then
      #brew install cmake boost python gcc || travis_terminate 1; # 3.8 already availalbe
      brew install ccache || travis_terminate 1;
      PATH=$PATH:/usr/local/opt/ccache/libexec;
    fi
  - cd ${TRAVIS_BUILD_DIR}

before_script:
  # Increase the maximum number of open file descriptors, since some tests use
  # more FDs than the default limit.
  - ulimit -n 8192

script:
  - echo "test group - ${TEST_GROUP}"; echo "job name - ${JOB_NAME}"; echo "--- compiler ---"; ${CXX} --version; echo "--- CMake ---"; cmake --version; export MAKE="make -j4"; 
  - if [ "${TEST_GROUP}" == 'platform_dependent' ]; then OPT=-DTRAVIS V=1 make all && OPT=-DTRAVIS V=1 ROCKSDBTESTS_END=db_block_cache_test $MAKE check_some;
    elif [ "${TEST_GROUP}" == '1' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=db_block_cache_test ROCKSDBTESTS_END=comparator_db_test $MAKE check_some;
    elif [ "${TEST_GROUP}" == '2' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=comparator_db_test $MAKE check_some;
    elif [ "${JOB_NAME}" == 'java_test' ]; then OPT=-DTRAVIS V=1 $MAKE clean jclean &&  $MAKE rocksdbjava jtest;
    elif [ "${JOB_NAME}" == 'lite_build' ]; then OPT="-DTRAVIS -DROCKSDB_LITE" V=1 make -j4 static_lib;
    elif [ "${JOB_NAME}" == 'examples' ]; then OPT=-DTRAVIS V=1 $MAKE static_lib && cd examples && $MAKE;
    elif [ "${JOB_NAME}" == 'cmake' ]; then mkdir build && cd build && cmake .. && $MAKE rocksdb;
    elif [ "${JOB_NAME}" == 'cmake-mingw' ]; then mkdir build && cd build && cmake .. -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows && $MAKE rocksdb;
    fi
notifications:
    email:
      - leveldb@fb.com
    webhooks:
      - https://buildtimetrend.herokuapp.com/travis
