language: generic
sudo: false

cache:
  directories:
    - $HOME/opt

env:
  global:
    - OPT=$HOME/opt
    - CACHE=$OPT/cache
    - BREWCACHE=$HOME/Library/Caches/Homebrew

matrix:
  include:
    - os: linux
      dist: focal
      env: VIM=vim VIMPROG=$OPT/bin/$VIM
    - os: linux
      dist: focal
      env: VIM=nvim VIMPROG=$VIM
    - os: osx
      osx_image: xcode12
      env: VIM=vim PACKAGE=vim VIMPROG=$VIM
    - os: osx
      osx_image: xcode12
      env: VIM=nvim PACKAGE=neovim VIMPROG=$VIM


install: |
  if [ "$TRAVIS_OS_NAME" = "linux" ]; then
    if [ "$VIM" = "vim" ]; then
      git clone --depth 1 https://github.com/vim/vim
      cd vim
      echo -n 'Vim version: '
      git describe --tags | tee vim-ver.txt
      if [ -e $OPT/vim-ver.txt ]; then
        if diff $OPT/vim-ver.txt vim-ver.txt; then
          cd -
          return
        fi
      fi
      ./configure --prefix=$OPT --with-features=huge --disable-gui
      make
      make install
      cp vim-ver.txt $OPT
      cd -
    elif [ "$VIM" = "nvim" ]; then
      # https://github.com/neovim/bot-ci#setting-up-integration-builds
      eval "$(curl -Ss https://raw.githubusercontent.com/neovim/bot-ci/master/scripts/travis-setup.sh) nightly-x64"
    fi
  elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
    if [ -d $CACHE ]; then
      if [ "$(echo $CACHE/*)" != "$CACHE/*" ]; then
        cp $CACHE/* $BREWCACHE
      fi
    else
      mkdir $CACHE -p
    fi
    (cd $BREWCACHE; ls > $HOME/list1.txt)
    brew update
    #brew upgrade
    brew install $PACKAGE
    brew cleanup -s
    (cd $BREWCACHE; ls > $HOME/list2.txt)
    comm -1 -3 $HOME/list1.txt $HOME/list2.txt | (cd $BREWCACHE; xargs -I{} cp {} $CACHE)
    comm -2 -3 $HOME/list1.txt $HOME/list2.txt | (cd $CACHE; xargs rm -rf)
    $VIM --version
  fi

script:
  - cd test
  - make VIMPROG=$VIMPROG

# vim: sw=2 sts=2 et
