language: cpp

git:
  depth: false


jobs:
    include:
      - os: linux
        dist: xenial
        services: docker
        env: >
          [
          PYTHON_VERSION=3.5                                 ,
          PYTHON_BINARY=/opt/python/cp35-cp35m/bin/python3.5 ,
          ]

      - os: linux
        dist: xenial
        services: docker
        env: >
          [
          PYTHON_VERSION=3.6                                 ,
          PYTHON_BINARY=/opt/python/cp36-cp36m/bin/python3.6 ,
          ]

      - os: linux
        dist: xenial
        services: docker
        env: >
          [
          PYTHON_VERSION=3.7                                 ,
          PYTHON_BINARY=/opt/python/cp37-cp37m/bin/python3.7 ,
          ]

      - services: docker
        env: >
          [
          PYTHON_VERSION=3.8                                 ,
          PYTHON_BINARY=/opt/python/cp38-cp38/bin/python3.8 ,
          ]

        # OSX 10.12 - xcode 8.3 - Python 3.5
      - os: osx
        osx_image: xcode8.3
        compiler: clang
        env: >
          [
          CXX=clang++ ,
          CC=clang     ,
          PYTHON_VERSION=3.5   ,
          ]


      # OSX 10.12 - xcode 8.3 - Python 3.6
      - os: osx
        osx_image: xcode8.3
        compiler: clang
        env: >
          [
          CXX=clang++ ,
          CC=clang     ,
          PYTHON_VERSION=3.6   ,
          ]


      # OSX 10.12 - xcode 10.1 - Python 3.7
      - os: osx
        osx_image: xcode10.1
        compiler: clang
        env: >
          [
          CXX=clang++ ,
          CC=clang     ,
          PYTHON_VERSION=3.7   ,
          ]

      # OSX 10.12 - xcode 10.1 - Python 3.8
      - os: osx
        osx_image: xcode10.1
        compiler: clang
        env: >
          [
          CXX=clang++ ,
          CC=clang     ,
          PYTHON_VERSION=3.8   ,
          ]

#branches:
#  only:
#  - master


notifications:
  email:
    on_success: never
    on_failure: always

cache:
  - apt
  - ccache
  - $HOME/.pyenv
  - build/rang_cpp_color-prefix
  - build/mbed_tls
  - build/libjson-prefix
  - build/easyloggingpp-prefix
  - build/tests/YAMLCPP
  - build/tests/lief-samples
  - build/tests/catch
  - build/api/python/pybind11-prefix

before_install:
  - if [ "$TRAVIS_OS_NAME" == "linux" ]; then docker build -t lief/manylinux1_x86_64 .; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install ccache; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi

  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PYTHON_CONFIGURE_OPTS="--enable-shared --enable-unicode=ucs2"; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv root; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew upgrade pyenv||true; fi
  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv install --list  ;fi

  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then pyenv install 2.7.12; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then pyenv install --skip-existing 3.5.9; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then pyenv install --skip-existing 3.6.0; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then pyenv install --skip-existing 3.7.0; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.8" ]]; then pyenv install --skip-existing 3.8.0; fi
  #- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then ls -alR $(pyenv root)/versions/3.7.0a1; fi

  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/2.7.12/include/python2.7  ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/2.7.12/lib/libpython2.7.dylib ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/2.7.12/bin/python2.7           ;fi

  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.5.9/include/python3.5m ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.5.9/lib/libpython3.dylib   ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.5.9/bin/python3.5           ;fi

  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.6.0/include/python3.6m ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.6.0/lib/libpython3.dylib   ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.6.0/bin/python3.6           ;fi

  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.7.0/include/python3.7m  ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.7.0/lib/libpython3.7m.dylib ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.7.0/bin/python3.7            ;fi

  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.8" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.8.0/include/python3.    ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.8" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.8.0/bin/python3.8            ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade pip        ;fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi

install:
  - if [ "$GCOV" == "ON" ]; then sudo ln -sf /usr/bin/gcov-5 /usr/bin/gcov; fi
  - if [ "$GCOV" == "ON" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.13.orig.tar.gz; fi
  - if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi
  - if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi

script:
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run --name lief_$PYTHON_VERSION -e PYTHON_BINARY=$PYTHON_BINARY -e CCACHE_DIR=/ccache -v $HOME/.ccache:/ccache lief/manylinux1_x86_64 bash -c '$PYTHON_BINARY setup.py --lief-test --sdk build -j8 bdist_wheel --dist-dir wheel_stage && auditwheel repair -w dist --plat manylinux1_x86_64 wheel_stage/*.whl ' && docker cp lief_$PYTHON_VERSION:/src/dist/ . && docker cp lief_$PYTHON_VERSION:/src/build/ .; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo $PYTHON_BINARY -m pip install -U pip setuptools wheel && $PYTHON_BINARY ./setup.py --lief-test --sdk build -j8 bdist_wheel; fi

after_success:
  - make package
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PYTHON_BINARY=python3; sudo apt-get update && sudo apt-get install -y python3 python3-pip; fi
  - sudo $PYTHON_BINARY -m pip install --upgrade pip
  - sudo $PYTHON_BINARY -m pip install --upgrade setuptools
  - sudo $PYTHON_BINARY -m pip install --upgrade requests mako wheel
    #- if [[ -z "$TRAVIS_TAG" ]]; then $PYTHON_BINARY setup.py sdist --dev --formats=zip ;fi
    #- if [[ -n "$TRAVIS_TAG" ]]; then $PYTHON_BINARY setup.py sdist --formats=zip       ;fi
  - cd $TRAVIS_BUILD_DIR
  - bash ./.github/deploy.sh
  - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then $PYTHON_BINARY ./.github/trigger_docker.py ;fi


deploy:
  provider: releases
  token:
    - secure: LTJMZp9kJ9/tmv73YGktP3Bdhh3moettDNooiRlQfUEgUemRlp9K+ybbufN0ya0Md0bouOJ/7nWqFToWl1G5/kcRr4MjV/P2c+iH8W7mvWcFupLGdwm1+aqpin3hiGsdYz0a1TK37y6DANspFwHILjq1SPf5L8kGEHnYSIfyUFHaETbv7GHL+4gf1XG/55KVuyFa3vZ2BPa3sIXr4bRypdNsqssFOZ7qeoJawtcI3TbjmLqx+sOGR2aiG+9lX+/vcYVGECHOE4KdV5BbTFitDLkJ0toAQrgN4XuB6XMXEnijU0RGtpkvsUAYJUuYaNcV2ea4bwLPCKz0IJvzTw3gtyB/pioP4OUx0xY2csuNuGfppZ0Fb+BWhPx9wOg209lrPjtoWszK8vo4PywKlEUviNG+3hEYx9x382IbtbXvIxp+c2iYdRicudFIdjjSZt7fy1MwBvHhWoBRl1hVw5fpFvRIC6Q1/B6MV55Jc3LVYCs+QHPAXq2KJ1KWK/Q7mmlriG3O+dvswcE1l0/AmeqKuXLsgUMuzScYa4fMFvXL3l/B8bKw205ynMzKvbb61P3sGrJJ+AFDEoHDk8yNtSaTowoUveu75DbL1s1p02QjYeVt7AJS8AsqUm7QPcUU5iXW1gSgt50jD/46/uvK7NZCFj2LzkiVzM5JIbiUANx8pKA=
  file_glob: true
  file:
    - ${TRAVIS_BUILD_DIR}/dist/*.whl
    - ${TRAVIS_BUILD_DIR}/build/*.tar.gz
  on:
    #branch: master
    tags: true

