matrix:
    fast_finish: true
    include:
        - os: linux
          dist: trusty
          group: beta
          sudo: false
          env:
            - CC=gcc SANITIZE_ARG=--sanitize
          language: python
          python: "3.5"
          addons:
            apt:
              packages:
                - libfontconfig1-dev
                - libharfbuzz-dev
                - libglew-dev
                - libxi-dev
                - libxrandr-dev
                - libxinerama-dev
                - libxcursor-dev
                - libunistring-dev
                - libpng-dev
                - python3-pil

        - os: linux
          dist: trusty
          group: beta
          sudo: false
          env:
            - CC=clang SANITIZE_ARG=--sanitize
          language: python
          python: "3.5"
          addons:
            apt:
              packages:
                - libfontconfig1-dev
                - libharfbuzz-dev
                - libglew-dev
                - libxi-dev
                - libxrandr-dev
                - libxinerama-dev
                - libxcursor-dev
                - libunistring-dev
                - libpng-dev
                - python3-pil

        - os: linux
          dist: trusty
          group: beta
          sudo: false
          env:
            - RUN_FLAKE=1 BUILD_PKG=1
          language: python
          python: "3.5"
          addons:
            apt:
              packages:
                - libfontconfig1-dev
                - libharfbuzz-dev
                - libglew-dev
                - libxi-dev
                - libxrandr-dev
                - libxinerama-dev
                - libxcursor-dev
                - libunistring-dev
                - libpng-dev
                - python3-pil
                - clang
        - os: osx
          language: generic
          env: SWBASE=/Users/Shared/buildbot/sw SW=$SWBASE/sw PATH=$SW/bin:$PATH

        - os: osx
          language: generic
          env: USE_BREW=1 BUILD_PKG=1

env:
    global:
        - PYTHON=python3
        - PKG_CONFIG_PATH=$HOME/glfw/lib/pkgconfig:$PKG_CONFIG_PATH
        - LD_LIBRARY_PATH=$HOME/glfw/lib:$LD_LIBRARY_PATH
        - ASAN_OPTIONS=leak_check_at_exit=0

install: |
    set -e
    if [[ "$RUN_FLAKE" == "1" ]]; then pip install flake8; fi
    if [[ "$TRAVIS_OS_NAME" == 'osx' ]]; then
        if [[ "$USE_BREW" == "1" ]]; then
            brew update;
            brew install python3;
            brew install glfw;
            brew install libunistring;
        else
            mkdir -p $SW;
            curl https://download.calibre-ebook.com/travis/kitty/osx.tar.xz | tar xJ -C $SW;
        fi
    else
        wget -O glfw-3.2.1.zip https://github.com/glfw/glfw/archive/3.2.1.zip
        unzip -q glfw-3.2.1.zip
        cd glfw-3.2.1
        cmake -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DCMAKE_INSTALL_PREFIX=$HOME/glfw
        make
        make install
        cd ..
    fi
    pkg-config --cflags glfw3
    if [[ "$TRAVIS_OS_NAME" != 'osx' ]]; then
        PLIB=$(ldd `which python` | grep libpython | cut -d ' ' -f 3)
        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`dirname $PLIB`
    fi
    set +e

before_script:
    - echo $LD_LIBRARY_PATH
    - $PYTHON setup.py build --debug $SANITIZE_ARG;

script:
    - if [[ -z $SANITIZE_ARG ]]; then $PYTHON test.py; else ./asan-launcher test.py; fi
    - if [[ "$RUN_FLAKE" == "1" ]]; then flake8 --count .; fi
    - if [[ "$BUILD_PKG" == "1" ]]; then $PYTHON setup.py linux-package; fi
