language: d
sudo: false

matrix:
  include:
    - os: linux
      d: ldc
      env: LLVM_VERSION=3.9.0
    - os: linux
      d: ldc-beta
      env: LLVM_VERSION=3.8.1
    - os: linux
      d: ldc
      env: LLVM_VERSION=3.7.1 OPTS="-DMULTILIB=ON"
    - os: linux
      d: ldc-0.17.1
      env: LLVM_VERSION=3.6.2 OPTS="-DBUILD_SHARED_LIBS=ON"
    - os: linux
      d: dmd
      env: LLVM_VERSION=3.5.2 OPTS="-DTEST_COVERAGE=ON"
    - os: osx
      d: ldc
      env: LLVM_CONFIG="llvm-config-3.8"
  allow_failures:
    #- env: LLVM_VERSION=3.9

cache:
  directories:
    - llvm-3.9.0
    - llvm-3.8.1
    - llvm-3.7.1
    - llvm-3.6.2
    - llvm-3.5.2
addons:
  apt:
    sources:
    - 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
    - libedit2
    - libedit-dev
    - libcurl3:i386
before_install:
  -
    if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
      if [ -z "$(ls -A llvm-$LLVM_VERSION)" ]; then
        wget -O llvm-$LLVM_VERSION.tar.xz http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-14.04.tar.xz;
        mkdir llvm-$LLVM_VERSION;
        tar -xvf llvm-$LLVM_VERSION.tar.xz --strip 1 -C llvm-$LLVM_VERSION;
      fi;
      llvm-$LLVM_VERSION/bin/llvm-config --version;
      export LLVM_CONFIG="llvm-$LLVM_VERSION/bin/llvm-config";
    fi
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 llvm38; brew install libconfig; fi;
  - eval "${DC} --version"
  - pip install --user lit
  - python -c "import lit; lit.main();" --version | head -n 1
  - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then gdb --version; fi

script:
  - cmake --version
  - 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 [ "${OPTS}" = "-DMULTILIB=ON" ]; then
      make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest phobos2-ldc-unittest-debug-32 phobos2-ldc-unittest-32;
      make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest druntime-ldc-unittest-debug-32 druntime-ldc-unittest-32;
    else
      make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest;
      make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest;
    fi
  # Run dmd-testsuite.
  - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest --verbose -R "dmd-testsuite"
  # Run LLVM IR testsuite.
  - ctest --output-on-failure -V -R "lit-tests"
  # Link and run Phobos & druntime unittest runners.
  - ctest -j3 --output-on-failure -E "dmd-testsuite|lit-tests"

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
