language: cpp
cache:
  directories:
    - $HOME/third_party
    - $HOME/.ccache
    - $HOME/.cache/pip
sudo: required
dist: trusty
os:
  - linux
env:
  - JOB=DOCS
  - JOB=BUILD_AND_TEST
  - JOB=PRE_COMMIT

addons:
  apt:
    packages:
      - gcc-4.8
      - g++-4.8
      - gfortran-4.8
      - git
      - build-essential
      - python
      - python-pip
      - python2.7-dev
      - python-numpy
      - python-wheel
      - curl
      - swig
      - graphviz
      - clang-format-3.8
      - automake
      - libtool
      - ccache
before_install:
  - |
    if [ ${JOB} == "BUILD_AND_TEST" ]; then
      local change_list=`git diff --name-only $TRAVIS_COMMIT_RANGE`
      if [ $? -eq 0 ]; then  # if git diff return no zero, then rerun unit test.
        if ! echo ${change_list} | grep -qvE '(\.md$)|(\.rst$)|(\.jpg$)|(\.png$)'
        then
          echo "Only markdown docs were updated, stopping build process."
          exit
        fi
      fi
    fi
  - if [[ "$JOB" == "PRE_COMMIT" ]]; then sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format; fi
  # Paddle is using protobuf 3.1 currently. Protobuf 3.2 breaks the compatibility. So we specify the python 
  # protobuf version.
  - pip install numpy wheel 'protobuf==3.1' sphinx recommonmark sphinx-rtd-theme==0.1.9 virtualenv pre-commit requests==2.9.2 LinkChecker
script:
  - paddle/scripts/travis/main.sh
notifications:
  email:
    on_success: change
    on_failure: always
