os: linux
dist: trusty
sudo: false

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - gdb
      - python-dbg
      - python3-dbg
      - gcc-6
      - g++-6
      # GCC-7 currently takes 5-7 *minutes* to download on travis
      #- gcc-7
      #- g++-7

cache:
  pip: true
  directories:
    - $HOME/.ccache

language: python
python:
  - 2.7
  - 3.6
  - 2.6
  - 3.3
  - 3.4
  - 3.5
  - 3.6-dev
  - 3.7-dev
  - pypy
  - pypy3

env:
  global:
    - USE_CCACHE=1
    - CCACHE_SLOPPINESS=pch_defines,time_macros
    - CCACHE_COMPRESS=1
    - CCACHE_MAXSIZE=150M
    - PATH="/usr/lib/ccache:$HOME/gcc-symlinks:$PATH"
  matrix:
    - BACKEND=c
    - BACKEND=cpp

matrix:
  include:
    #- python: 3.7-dev
    #  env: BACKEND=c PY=3 CC=gcc-7
    - os: osx
      osx_image: xcode6.4
      env: BACKEND=c PY=2
      python: 2
      language: c
      compiler: clang
      cache: false
    - os: osx
      osx_image: xcode6.4
      env: BACKEND=cpp PY=2
      python: 2
      language: cpp
      compiler: clang
      cache: false
    - os: osx
      osx_image: xcode6.4
      env: BACKEND=c PY=3
      python: 3
      language: c
      compiler: clang
      cache: false
    - os: osx
      osx_image: xcode6.4
      env: BACKEND=cpp PY=3
      python: 3
      language: cpp
      compiler: clang
      cache: false
  allow_failures:
    - python: pypy
    - python: pypy3
    - python: 3.7-dev
  exclude:
    - python: pypy
      env: BACKEND=cpp
    - python: pypy3
      env: BACKEND=cpp

branches:
  only:
    - master
    - release

before_install:
  - |
    if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
      mkdir "$HOME/gcc-symlinks"
      ln -s /usr/bin/gcc-6 $HOME/gcc-symlinks/gcc 
      ln -s /usr/bin/g++-6 $HOME/gcc-symlinks/g++ 
      
      if [ -n "$CC" ]; then "$CC" --version; else gcc --version; fi
    fi

  - |
    if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then # Install Miniconda
      curl -s -o miniconda.sh https://repo.continuum.io/miniconda/Miniconda$PY-latest-MacOSX-x86_64.sh;
      bash miniconda.sh -b -p $HOME/miniconda && rm miniconda.sh;
      export PATH="$HOME/miniconda/bin:$PATH"; hash -r;
      #conda install --quiet --yes nomkl --file=test-requirements.txt --file=test-requirements-cpython.txt;
    fi

install:
  - python -c 'import sys; print("Python %s" % (sys.version,))'
  - if [ -n "${TRAVIS_PYTHON_VERSION##*-dev}" -a -n "${TRAVIS_PYTHON_VERSION##2.6*}" ]; then pip install -r test-requirements.txt $( [ -z "${TRAVIS_PYTHON_VERSION##pypy*}" ] || echo " -r test-requirements-cpython.txt" ) $( [ -n "${TRAVIS_PYTHON_VERSION##3.3*}" ] || echo " tornado<5.0" ) ; fi
  - CFLAGS="-O2 -ggdb -Wall -Wextra $(python -c 'import sys; print("-fno-strict-aliasing" if sys.version_info[0] == 2 else "")')" python setup.py build

before_script: ccache -s || true

script:
  - PYTHON_DBG="python$( python -c 'import sys; print("%d.%d" % sys.version_info[:2])' )-dbg"
  - if $PYTHON_DBG -V >&2; then CFLAGS="-O0 -ggdb" $PYTHON_DBG runtests.py -vv Debugger --backends=$BACKEND; fi
  - if [ "$BACKEND" = "cpp" -a -n "${TRAVIS_PYTHON_VERSION##2.6*}" ]; then pip install pythran; fi
  - CFLAGS="-O2 -ggdb -Wall -Wextra $(python -c 'import sys; print("-fno-strict-aliasing" if sys.version_info[0] == 2 else "")')" python setup.py build_ext -i
  - CFLAGS="-O0 -ggdb -Wall -Wextra" python runtests.py -vv -x Debugger --backends=$BACKEND -j7
