language: c

_anchors:
  envs:
    - &tiny-nogui
      BUILD=yes TEST=test FEATURES=tiny "CONFOPT='--disable-gui'" SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=no
    - &tiny
      BUILD=yes TEST=test FEATURES=tiny CONFOPT= SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=no
    - &small
      BUILD=yes TEST=test FEATURES=small CONFOPT= SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=no
    - &normal
      BUILD=yes TEST=test FEATURES=normal CONFOPT= SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=no
    - &linux-huge
      BUILD=yes TEST="scripttests test_libvterm" CFLAGS=--coverage LDFLAGS=--coverage FEATURES=huge SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=no
      "CONFOPT='--enable-perlinterp --enable-pythoninterp --enable-python3interp --enable-rubyinterp --enable-luainterp --enable-tclinterp'"
    - &osx-huge # macOS build
      BUILD=yes TEST=test FEATURES=huge SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=no
      "CONFOPT='--enable-perlinterp --enable-pythoninterp --enable-rubyinterp --enable-luainterp --enable-tclinterp'"
    - &unittests
      BUILD=no TEST=unittests CFLAGS=--coverage LDFLAGS=--coverage FEATURES=huge SHADOWOPT= SRCDIR=./src CHECK_AUTOCONF=yes
    - &asan # ASAN build
      SANITIZER_CFLAGS="-g -O1 -DABORT_ON_INTERNAL_ERROR -DEXITFREE -fsanitize=address -fno-omit-frame-pointer"
      ASAN_OPTIONS="print_stacktrace=1 log_path=asan" LSAN_OPTIONS="suppressions=$TRAVIS_BUILD_DIR/src/testdir/lsan-suppress.txt"
    - &shadowopt
      SHADOWOPT="-C src/shadow" SRCDIR=./src/shadow

  linux: &linux
    os: linux
    dist: trusty
    addons:
      apt:
        sources:
          # Need msgfmt 0.19.8 to be able to generate .desktop files
          - sourceline: 'ppa:ricotz/toolchain'
        packages: &linux-packages
          - autoconf
          - clang
          - lcov
          - gettext
          - libcanberra-dev
          - libperl-dev
          - python-dev
          - python3-dev
          - liblua5.2-dev
          - lua5.2
          - ruby-dev
          - tcl-dev
          - cscope
          - libgtk2.0-dev
          - desktop-file-utils
    before_install:
      - rvm reset
      # Remove /opt/python/3.x.x/bin from $PATH for using system python3.
      # ("pyenv global system" doesn't seem to work.)
      - |
        if [[ "$(which python3)" =~ ^/opt/python/ ]]; then
          export PATH=$(py3=$(which python3); echo ${PATH//${py3%/python3}:/})
        fi
      # Use llvm-cov instead of gcov when compiler is clang.
      - |
        if [[ "${CC}" = "clang" ]]; then
          ln -sf "$(which llvm-cov)" /home/travis/bin/gcov
        fi
    before_script:
      # Start virtual framebuffer to be able to test the GUI. For dists newer
      # than trusty, the "services: xvfb" setting should be used instead
      - |
        if [[ ${TRAVIS_DIST} = trusty ]]; then
          export DISPLAY=:99.0
          sh -e /etc/init.d/xvfb start && sleep 3
        fi
      - sudo bash ci/load-snd-dummy.sh || true
      - sudo usermod -a -G audio $USER
      - do_test() { sg audio "sg $(id -gn) '$*'"; }

  osx: &osx
    os: osx
    before_script:
      - do_test() { "$@"; }

  homebrew: &osx-homebrew
    addons:
      homebrew:
        packages:
          - lua
        update: true
    cache:
      directories:
        - /usr/local/Homebrew/Library/Homebrew/vendor/
        - /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/
    before_install:
      - rvm reset
      # Lua is not installed on Travis OSX
      - export LUA_PREFIX=/usr/local

  coverage: &coverage
    # needed for https support for coveralls building cffi only works with gcc,
    # not with clang
    - CC=gcc pip install --user cpp-coveralls pyopenssl ndg-httpsclient pyasn1
    - ~/.local/bin/coveralls -b "${SRCDIR}" -x .xs -e "${SRCDIR}"/if_perl.c -e "${SRCDIR}"/xxd -e "${SRCDIR}"/libvterm --encodings utf-8
    - (cd "${SRCDIR}" && bash <(curl -s https://codecov.io/bash))

  asan_symbolize: &asan_symbolize
    - |
      while read log; do
        asan_symbolize < "${log}"
      done < <(find . -type f -name 'asan.*' -size +0)

branches:
  except:
    - /^v[0-9]/

script:
  - NPROC=$(getconf _NPROCESSORS_ONLN)
  - set -o errexit
  - echo -e "\\033[33;1mConfiguring Vim\\033[0m" && echo -en "travis_fold:start:configure\\r\\033[0K"
  - |
    if [[ "${CHECK_AUTOCONF}" = "yes" ]] && [[ "${CC}" = "gcc" ]]; then
      make -C src autoconf
    fi
  - |
    if [[ -n "${SHADOWOPT}" ]]; then
      make -C src shadow
    fi
  # "./configure" changes its working directory into "$SRCDIR".
  - ./configure --with-features=${FEATURES} ${CONFOPT} --enable-fail-if-missing
  - echo -en "travis_fold:end:configure\\r\\033[0K"
  - echo -e "\\033[33;1mBuilding Vim\\033[0m" && echo -en "travis_fold:start:build\\r\\033[0K"
  - |
    if [[ "${BUILD}" = "yes" ]]; then
      make ${SHADOWOPT} -j${NPROC}
    fi
  - echo -en "travis_fold:end:build\\r\\033[0K"
  - set +o errexit
  # Show Vim version and also if_xx versions.
  - |
    if [[ "${BUILD}" = "yes" ]]; then
      "${SRCDIR}"/vim --version
      "${SRCDIR}"/vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-1.vim -c quit
      "${SRCDIR}"/vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-2.vim -c quit
    fi
  - echo -e "\\033[33;1mTesting Vim\\033[0m" && echo -en "travis_fold:start:test\\r\\033[0K"
  - do_test make ${SHADOWOPT} ${TEST} && FOLD_MARKER=travis_fold
  - echo -en "${FOLD_MARKER}:end:test\\r\\033[0K"


# instead of a 2*2*8 matrix (2*os + 2*compiler + 8*env),
# exclude some builds on mac os x and linux
# on mac os x "tiny" is always without GUI
# linux: 2*compiler + 5*env + mac: 2*compiler + 2*env
jobs:
  include:
    - <<: *osx
      name: tiny-nogui/clang
      compiler: clang
      env: *tiny-nogui
    - <<: *osx
      name: tiny-nogui/gcc
      compiler: gcc
      env: *tiny-nogui
    - <<: *osx
      <<: *osx-homebrew
      name: huge/clang
      compiler: clang
      env: *osx-huge
    - <<: *osx
      <<: *osx-homebrew
      name: huge/gcc
      compiler: gcc
      env: *osx-huge
    - <<: *linux
      name: tiny-nogui/clang
      compiler: clang
      env: *tiny-nogui
    - <<: *linux
      name: tiny-nogui/gcc
      compiler: gcc
      env: *tiny-nogui
    - <<: *linux
      name: tiny/clang
      compiler: clang
      env: *tiny
    - <<: *linux
      name: tiny/gcc
      compiler: gcc
      env: *tiny
    - <<: *linux
      name: small/gcc
      compiler: gcc
      env: *small
    - <<: *linux
      name: normal/clang
      compiler: clang
      env:
        - *normal
        - *shadowopt
    - <<: *linux
      name: normal/gcc
      compiler: gcc
      env:
        - *normal
        - *shadowopt
    - <<: *linux
      arch: s390x
      name: huge/gcc-s390x
      compiler: gcc
      env: *linux-huge
      addons:
        apt:
          packages:
            - *linux-packages
            - libtool-bin
    - <<: *linux
      name: huge+coverage/clang
      compiler: clang
      env: *linux-huge
      after_success: *coverage
    - <<: *linux
      name: huge+coverage/gcc
      compiler: gcc
      env: *linux-huge
      after_success: *coverage
    - <<: *linux
      name: unittests+coverage/gcc
      compiler: gcc
      env: *unittests
      after_success: *coverage
    - <<: *linux # ASAN
      name: huge+asan/gcc
      compiler: gcc
      env:
        - *linux-huge
        - *asan
      after_failure: *asan_symbolize
    - <<: *linux
      name: huge-testgui+coverage/gcc
      compiler: gcc
      env:
        - *linux-huge
        - TEST="-C src testgui"
      after_success: *coverage
    - <<: *linux
      name: vimtags/gcc
      compiler: gcc
      env:
        - *normal
        - TEST="-C runtime/doc vimtags VIMEXE=../../${SRCDIR}/vim"

# vim:set sts=2 sw=2 tw=0 et:
