language: cpp

git:
  depth: 500

env:
  global:
    # ANDROID_STOREPASS
    secure: RGovyUnMw3fp/bHZi058JvANT1rYmNqrsuSYew0cIgirO6YbMHr/rsjwCm1FTYpBl8s1zgr+u2b8ftYnfnCz2YT+Aip4NWrVYpVU0FEmfytGILrnUS0pjlt8m7fU9AKR1ElOSll7yw7e1kftynN39Q321etvwbLZcXon6zz0suE=

matrix:
    fast_finish: true
    include:
        - os: linux
          env: SPEC=linux-g++-64 CONFIG=debug
          sudo: true
        - os: linux
          env: SPEC=linux-g++-64 CONFIG=installer
          sudo: true
        - os: osx
          osx_image: xcode7
          env: SPEC=macx-clang CONFIG=debug
        - os: osx
          osx_image: xcode7
          env: SPEC=macx-clang CONFIG=installer
        - os: android
          language: android
          env: SPEC=android-g++ CONFIG=debug
          sudo: false
        - os: android
          language: android
          env: SPEC=android-g++ CONFIG=installer
          sudo: false

android:
  components:
    - platform-tools
    - build-tools-21.1.1
    - android-21

cache:
  - apt

before_install:
  - cd ${TRAVIS_BUILD_DIR} && git fetch --unshallow && git fetch --tags
  - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then mkdir -p ~/.config/QtProject/ && cp ${TRAVIS_BUILD_DIR}/test/qtlogging.ini ~/.config/QtProject/; fi
  - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then mkdir -p ~/Library/Preferences/QtProject/ && cp ${TRAVIS_BUILD_DIR}/test/qtlogging.ini ~/Library/Preferences/QtProject/; fi
  - if [ "${TRAVIS_OS_NAME}" = "android" ]; then wget https://s3-us-west-2.amazonaws.com/qgroundcontrol/dependencies/gstreamer-1.0-android-armv7-1.5.2.tar.bz2 && mkdir -p ${TRAVIS_BUILD_DIR}/gstreamer-1.0-android-armv7-1.5.2 && tar jxf gstreamer-1.0-android-armv7-1.5.2.tar.bz2 -C ${TRAVIS_BUILD_DIR}/gstreamer-1.0-android-armv7-1.5.2; fi

install:
  - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
         sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test
      && sudo apt-get -qq update
      && sudo apt-get -qq install g++-4.8 espeak libespeak-dev libopenscenegraph-dev libsdl1.2-dev libudev-dev
      && wget https://s3-us-west-2.amazonaws.com/qgroundcontrol/dependencies/Qt5.5.1-linux.tar.bz2
      && tar jxf Qt5.5.1-linux.tar.bz2 -C /tmp
      && export PATH=/tmp/Qt/5.5/gcc_64/bin:$PATH
      && export CXX="g++-4.8"
      && export CC="gcc-4.8"
      && export DISPLAY=:99.0
      && sh -e /etc/init.d/xvfb start
      ;
    elif [ "${TRAVIS_OS_NAME}" = "osx" ]; then
         brew update
      && brew install qt5
      && export PATH=/usr/local/opt/qt5/bin:$PATH
      ;
    elif [ "${TRAVIS_OS_NAME}" = "android" ]; then
         wget http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin
      && chmod +x android-ndk-r10e-linux-x86_64.bin
      && ./android-ndk-r10e-linux-x86_64.bin > /dev/null
      && export PATH=`pwd`/android-ndk-r10e:$PATH
      && export ANDROID_NDK_ROOT=`pwd`/android-ndk-r10e
      && export ANDROID_SDK_ROOT=/usr/local/android-sdk
      && wget https://s3-us-west-2.amazonaws.com/qgroundcontrol/dependencies/Qt5.5.1-linux.tar.bz2
      && tar jxf Qt5.5.1-linux.tar.bz2 -C /tmp
      && export PATH=/tmp/Qt/5.5/android_armv7/bin:$PATH
      ;
    fi


before_script:
  - if [[ "${TRAVIS_OS_NAME}" = "android" && "${CONFIG}" = "installer" && -z ${ANDROID_STOREPASS} ]]; then export CONFIG=release; fi
  - qmake -r qgroundcontrol.pro CONFIG+=${CONFIG} CONFIG+=WarningsAsErrorsOn -spec ${SPEC}

script:
  - echo 'Building QGroundControl' && echo -en 'travis_fold:start:script.1\\r'
  - make -j4
  - echo -en 'travis_fold:end:script.1\\r'
  - echo 'Running unittests' && echo -en 'travis_fold:start:script.2\\r'
  - if [[ "${TRAVIS_OS_NAME}" = "linux" && "${CONFIG}" = "debug" ]]; then ./debug/qgroundcontrol --unittest; fi
  - if [[ "${TRAVIS_OS_NAME}" = "osx" && "${CONFIG}" = "debug" ]]; then ./debug/qgroundcontrol.app/Contents/MacOS/qgroundcontrol --unittest; fi
  - echo -en 'travis_fold:end:script.2\\r'

deploy:
  - provider: s3
    access_key_id: AKIAIVORNALE7NHD3T6Q
    secret_access_key:
      secure: BsLXeXUPsCJdX4tawrDnO8OFK5Hk4kzlDTiyH93En6TbjUargVAWDMcHVj7TUhr7+3Tao1W1zb0G4SJe9kHv+jrky0yE72KvoG3YAON0VXWKizxBAKkgHE2RxSTNAwDeKbi2G6YJfNDescBBfX7zEohShdXglQu7CGaUQKRaiI4=
    bucket: qgroundcontrol
    local_dir: release/package
    upload-dir: ${TRAVIS_BRANCH}
    acl: public_read
    skip_cleanup: true
    on:
      all_branches: true
      condition: $CONFIG = installer
  - provider: releases
    api-key:
      secure: K/Zqr/FCC7QvzFxYvBtCinPkacQq2ubJ2qm982+38Zf/KjibVOF1dEbVdrGZmII6Tg5DaQzNXGYkg5PvYmJgT9xRsqeQjeYIUYqYZpAt+HYWA38AVfMU8jip/1P1wmwqD469nzJOBBa8yfsMs6Ca7tBaNl/zTxCRGnAgEzqtkdQ=
    file:
      - release/package/qgroundcontrol.apk
      - release/package/qgroundcontrol.dmg
      - release/package/qgroundcontrol.tar.bz2
    skip_cleanup: true
    on:
      tags: true
      condition: $CONFIG = installer

notifications:
  webhooks:
    urls:
      - https://webhooks.gitter.im/e/60b033428ae9dc715662
    on_success: change  # options: [always|never|change] default: always
    on_failure: always  # options: [always|never|change] default: always
    on_start: never     # options: [always|never|change] default: always

