# Control file for continuous integration testing at http://travis-ci.org/

language: cpp
compiler: gcc
sudo: required
dist: bionic
# We have some shenanigans to let us cache submodules, and update changed files
# without messing up mtimes and triggering rebuilds unnecessarily. Travis checks
# out our submodules and then restores the cache over them. We move the cached
# version out of the way, check out the versions we want, rsync over only the
# differing/updated files (updating only their mtimes), and then put the fixed
# version back.
# Doxygen docs depend on Protobuf so we still need to do dep cache stuff for docs.
before_install:
  - if [[ -e deps ]]; then mv deps deps_cached; fi
  - git submodule update --init --recursive
  - rsync -rv --links --checksum deps/ deps_cached/
  - rm -Rf deps
  # Keep the cached deps if the right compiler version was used.
  # Otherwise start fresh
  - if [[ "$TRAVIS_OS_NAME" == "linux" && -e "deps_cached/gcc$(gcc -dumpversion)" ]]; then mv deps_cached deps; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && -e deps_cached/clang ]]; then mv deps_cached deps; fi
  - (ls -lah deps/; ls -lah bin/; ls -lah lib/; ls -lah include/) || true
  - git submodule update --init --recursive
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ls /etc/apt/sources.list.d; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir -p deps; touch "deps/gcc$(gcc -dumpversion)"; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"; fi
  # Travis can't always actually use Homebrew to install our dependencies
  # And Homebrew can't always bundle unless it is the exact latest version:
  # See <https://github.com/Homebrew/homebrew-bundle/issues/646>
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update --verbose; fi
  # Allow the bundle command to fail because if anything it tries to install (like Python) 
  # provides a binary that can replace something that already exists, it will treat the
  # inability to link it as an error and fail the command. You can --force a link step, but
  # I don't see a way to tell it to not replace things that exist and also not fail.
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew bundle --verbose || true; fi
  # Try installing gcc6 twice in case of errors like this:
  # Error: HOMEBREW_LOGS was not exported!
  # Please don't worry, you likely hit a bug auto-updating from an old version.
  # Rerun your command, everything is up-to-date and fine now.
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir -p deps; touch deps/clang; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/bison/bin:$PATH"; fi # Homebrew no longer links Bison even if we try to force it
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="$(pwd)/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:$PATH"; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export LD_LIBRARY_PATH=/usr/local/lib/; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export CFLAGS="-I/usr/local/include/"; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export LIBRARY_PATH=$LD_LIBRARY_PATH; fi
  - which gcc && gcc --version && which g++ && g++ --version
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then which cc && cc --version && which c++ && c++ --version; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then find /usr/local/include || true ; fi
  - python ./configure.py
  - source ./source_me.sh
install:
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make get-deps; fi
script:
  - if [[ -z "$BUILD_DOCS_ONLY" && "$TRAVIS_OS_NAME" == "linux" ]]; then make -j4 && echo Testing && bin/vg test "Target to alignment extraction" && echo Full Testing && make test && make static -j4; fi
  - if [[ -z "$BUILD_DOCS_ONLY" && "$TRAVIS_OS_NAME" == "osx" ]]; then timeout 1800 make deps -j4 && make -j4 && echo Testing && bin/vg test "Target to alignment extraction" && echo Full Testing && make test; fi
  - if [[ ! -z "$BUILD_DOCS_ONLY" ]]; then doc/publish-docs.sh; fi
# Cache all our dependency directories, and our lib and include
cache:
  ccache: true
  directories:
    - deps
    - lib
    - include
    - bin
before_cache:
  - rm -f lib/libvg.*
  - rm -f include/vg_git_version.hpp
  - rm -f bin/vg /bin/vg* bin/g++ bin/gcc

addons:
  homebrew:
    brewfile: true 
  apt:
    update: true
    packages: # Get all the current dependency packages in advance. We will still do make get-deps but it will do less work.
      - bc 
      - rs 
      - jq
      - samtools
      - cmake
      - protobuf-compiler
      - libprotoc-dev
      - libprotobuf-dev
      - libjansson-dev
      - libbz2-dev
      - libncurses5-dev
      - automake
      - libtool
      - curl
      - unzip
      - redland-utils
      - librdf-dev
      - pkg-config
      - wget 
      - gtk-doc-tools
      - raptor2-utils
      - rasqal-utils
      - bison
      - flex
      - gawk
      - libgoogle-perftools-dev
      - liblz4-dev
      - liblzma-dev
      - libcairo2-dev
      - libpixman-1-dev
      - libffi-dev
      - doxygen

os:
  - linux
  - osx
osx_image: xcode10.1
compiler:
  - gcc
env:
  global:
    - DOCS_KEY_ENCRYPTION_LABEL=125272388526
    - VG_FULL_TRACEBACK=1
  
matrix:
  include:
    # We have a special entry to do the docs build
    - os: linux
      env: BUILD_DOCS_ONLY=1
