language: cpp
sudo: false
os:
  - linux
  - osx
addons:
  apt:
    sources:
    - llvm-toolchain-precise
    - llvm-toolchain-precise-3.5
    - llvm-toolchain-precise-3.6
    - llvm-toolchain-precise-3.7
    - ubuntu-toolchain-r-test
    packages:
    - libconfig++8-dev
    - gdb
    - gcc-4.9
    - g++-4.9
    - gcc-4.9-multilib
    - g++-4.9-multilib
    - gcc-multilib
    - g++-multilib
    - linux-libc-dev:i386
    - libcurl3:i386
    - libedit2
    - libedit-dev
    - llvm-3.5
    - llvm-3.5-dev
    - llvm-3.6
    - llvm-3.6-dev
    - llvm-3.7
    - llvm-3.7-dev
    - llvm-3.8
    - llvm-3.8-dev
    - llvm-3.9
    - llvm-3.9-dev
install:
  - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CC="gcc-4.9"; export CXX="g++-4.9"; fi
  - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew update; brew install llvm36; brew install libconfig; fi;
  - pip install --user lit
  - python -c "import lit; lit.main();" --version | head -n 1

env:
  - LLVM_CONFIG="llvm-config-3.7" OPTS="-DMULTILIB=ON"
  - LLVM_CONFIG="llvm-config-3.6" OPTS="-DBUILD_SHARED_LIBS=ON"
  - LLVM_CONFIG="llvm-config-3.5" OPTS="-DTEST_COVERAGE=ON"
  - LLVM_CONFIG="llvm-config-3.8"
  - LLVM_CONFIG="llvm-config-3.9"
  # OSX only (and the only ones for OSX):
  - LLVM_CONFIG="llvm-config-3.6" TEST_CONFIG="Debug"
  - LLVM_CONFIG="llvm-config-3.6" TEST_CONFIG="Release"
matrix:
  allow_failures:
    - env: LLVM_CONFIG="llvm-config-3.9"
  exclude:
    - os: linux
      env: LLVM_CONFIG="llvm-config-3.6" TEST_CONFIG="Debug"
    - os: linux
      env: LLVM_CONFIG="llvm-config-3.6" TEST_CONFIG="Release"
    - os: osx
      env: LLVM_CONFIG="llvm-config-3.7" OPTS="-DMULTILIB=ON"
    - os: osx
      env: LLVM_CONFIG="llvm-config-3.6" OPTS="-DBUILD_SHARED_LIBS=ON"
    - os: osx
      env: LLVM_CONFIG="llvm-config-3.5" OPTS="-DTEST_COVERAGE=ON"
    - os: osx
      env: LLVM_CONFIG="llvm-config-3.8"
    - os: osx
      env: LLVM_CONFIG="llvm-config-3.9"
script:
  - cmake -DLLVM_CONFIG=$(which ${LLVM_CONFIG}) $OPTS .
  - make -j3
  # Outputs some environment info, plus makes sure we only run the test suite
  # if we could actually build the executable.
  - bin/ldc2 -version || exit 1
  # Build Phobos & druntime unittest modules.
  -
    if [ "${TEST_CONFIG}" = "Debug" ]; then
      MAKEOPTS=-j2 ctest --verbose -R "build-phobos2-ldc-unittest-debug";
      MAKEOPTS=-j3 ctest --verbose -R "build-druntime-ldc-unittest-debug";
    elif [ "${TEST_CONFIG}" = "Release" ]; then
      MAKEOPTS=-j2 ctest --verbose -R "build-phobos2-ldc-unittest" -E "-debug";
      MAKEOPTS=-j3 ctest --verbose -R "build-druntime-ldc-unittest" -E "-debug";
    else
      MAKEOPTS=-j2 ctest --verbose -R "build-phobos2-ldc-unittest";
      MAKEOPTS=-j3 ctest --verbose -R "build-druntime-ldc-unittest";
    fi
  # Run dmd-testsuite.
  -
    if [ "${TEST_CONFIG}" = "Debug" ]; then
      CC="" MAKEOPTS=-j4 ctest --verbose -R "dmd-testsuite-debug";
    elif [ "${TEST_CONFIG}" = "Release" ]; then
      CC="" MAKEOPTS=-j4 ctest --verbose -R "dmd-testsuite" -E "-debug";
    else
      CC="" MAKEOPTS=-j4 ctest --verbose -R "dmd-testsuite";
    fi
  # Run LLVM IR testsuite.
  - ctest --output-on-failure -R "llvm-ir-testsuite"
  # Link and run Phobos & druntime unittest runners.
  -
    if [ "${TEST_CONFIG}" = "Debug" ]; then
      MAKEOPTS=-j3 ctest --verbose -R "-test-runner-debug";
      ctest -j4 --output-on-failure -R "-debug" -E "testsuite";
    elif [ "${TEST_CONFIG}" = "Release" ]; then
      MAKEOPTS=-j3 ctest --verbose -R "-test-runner" -E "-debug";
      ctest -j4 --output-on-failure -E "(-debug|testsuite)";
    else
      MAKEOPTS=-j3 ctest --verbose -R "-test-runner";
      ctest -j4 --output-on-failure -E "testsuite";
    fi

after_success:
  -
    if [[ "${OPTS}" == *TEST_COVERAGE*ON* ]]; then
      coveralls -e runtime -e tests -e vcbuild --gcov gcov-4.9 --gcov-options '\-lp' > /dev/null 2>&1;
    fi

notifications:
  email:
    recipients:
      - "digitalmars-d-ldc@puremagic.com"
    on_success: never
    on_failure: change
  irc:
    channels:
      - "irc.freenode.org#ldc"
    on_success: always
    on_failure: always
    use_notice: false
    skip_join: true
