version: '{build}'

init:
- git config --global core.autocrlf input
#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://gist.githubusercontent.com/cor3ntin/1327dbf8aedab79f9fa305c001190268/raw/05155caad3a68c48be5f6873c3aca6ad8a30e31a/rdp.ps1'))

matrix:
  fast_finish: true

skip_branch_with_pr: true

install:
  - mkdir C:\projects\deps
  - cd C:\projects\deps

  # Install Bonjour
  - 7z x "%APPVEYOR_BUILD_FOLDER%\third_party\bonjour\bonjoursdksetup.exe"
  - if [%platform%]==[x64] cd C:\projects\deps && msiexec /i C:\projects\deps\Bonjour64.msi /qb /quiet
  - if [%platform%]==[x64] cd C:\projects\deps && msiexec /i C:\projects\deps\BonjourSDK64.msi /qb /quiet
  - if [%platform%]==[x86] cd C:\projects\deps && msiexec /i C:\projects\deps\Bonjour.msi /qb /quiet
  - if [%platform%]==[x86] cd C:\projects\deps && msiexec /i C:\projects\deps\BonjourSDK.msi /qb /quiet

  # Use msys packages for the mingw builds
  - if [%COMPILER%]==[MinGW] (
      %BASH% -lc "pacman -R catgets libcatgets --noconfirm"
    )

  - if [%COMPILER%]==[MinGW] if [%ARCH%]==[x86] %BASH% -lc "pacman --noconfirm -Sy -d mingw-w64-i686-{binutils,gcc,gcc-libs,cmake,qt5,qwt-qt5,libxml2,SDL2}"
  - if [%COMPILER%]==[MinGW] if [%ARCH%]==[x64] %BASH% -lc "pacman --noconfirm -Sy -d mingw-w64-x86_64-{binutils,gcc,gcc-libs,cmake,qt5,qwt-qt5,libxml2,SDL2}"


  # Install cmake
  - if [%USE_VS_TOOLCHAIN%]==[true] (
      cd C:\projects\deps &&
      appveyor DownloadFile %CMAKE_URL% -FileName cmake.zip &&
      7z x cmake.zip -oC:\projects\deps > nul &&
      move C:\projects\deps\cmake-* C:\projects\deps\cmake &&
      set "PATH=C:\projects\deps\cmake\bin;%PATH%"
      cmake --version
    )

  #Install LLVM to have a newer clang cl
  - if [%COMPILER%]==[ClangCL] (
      cd C:\projects\deps &&
      appveyor DownloadFile %LLVM_URL% -FileName llvm.exe &&
      7z x llvm.exe -oC:\projects\deps\llvm > nul &&
      set "PATH=C:\projects\deps\llvm\bin;%PATH%" &&
      set "LLD_LINK=C:\projects\deps\llvm\bin\lld-link.exe"
    )
  # Install SDL ( for msvc & clang)
  - if [%USE_VS_TOOLCHAIN%]==[true] (
      appveyor DownloadFile %SDL_URL% -FileName sdl.zip  &&
      7z x sdl.zip -oC:\projects\deps\sdl > nul
    )

  - appveyor DownloadFile %NINJA_URL% -FileName ninja.zip
  - 7z x ninja.zip -oC:\projects\deps\ninja > nul
  - set "PATH=C:\projects\deps\ninja;%PATH%"
  - ninja --version


  # NSIS
  - ps: |
      if (Test-Path "C:/Program Files (x86)/NSIS/makensis.exe") {
          echo "using nsis from cache"
      } else {
          choco install -y nsis.install
      }
  - set "PATH=%PATH%;C:\Program Files (x86)\NSIS"

  # Blockly deps
  - if [%USE_VS_TOOLCHAIN%]==[true] python -m pip install -U pip setuptools wheel
  - if [%USE_VS_TOOLCHAIN%]==[true] python -m pip install beautifulsoup4 lxml

  - if [%COMPILER%]==[MinGW] appveyor DownloadFile %https://bootstrap.pypa.io/get-pip.py% -FileName get-pip.py
  - if [%COMPILER%]==[MinGW] (
      %BASH% -x -lc "python2 get-pip.py --user && python2 -m pip install -U pip setuptools wheel && python2 -m pip install beautifulsoup4 lxml"
    )


before_build:
  - cd "%APPVEYOR_BUILD_FOLDER%"
  - if [%USE_VS_TOOLCHAIN%]==[true] (
      set "PATH=%QT5%\bin;%PATH%" &&
      call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %ARCH%
    )
  - git submodule init
  - git submodule update --recursive --remote
  - if NOT DEFINED APPVEYOR_PULL_REQUEST_NUMBER git clone https://github.com/aseba-community/thymio-blockly-standalone.git thymio-blockly-standalone --branch master --recurse-submodules

build_script:
  - cd "%APPVEYOR_BUILD_FOLDER%"
  - mkdir build
  - cd build
  - if [%COMPILER%]==[MinGW] if [%ARCH%]==[x86] set MinGWPath="/mingw32"
  - if [%COMPILER%]==[MinGW] if [%ARCH%]==[x64] set MinGWPath="/mingw64"
  - if [%COMPILER%]==[MinGW] (
      %BASH% -x -lc "cd '%APPVEYOR_BUILD_FOLDER%\\build' && export PATH=\"%MinGWPath%/bin:${PATH}\"  && cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_PREFIX_PATH='%MinGWPath%;/c/Program Files/Bonjour SDK' && ninja -v"
    )

  - if [%COMPILER%]==[ClangCL] (
      cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF "-DCMAKE_TOOLCHAIN_FILE=%APPVEYOR_BUILD_FOLDER%\windows\clang-cl-toolchain.cmake" "-DCMAKE_LINKER=%LLD_LINK%" "-DCMAKE_PREFIX_PATH=%QT5%;C:\Program Files\Bonjour SDK" -DCMAKE_BUILD_TYPE=Release &&
      ninja -v &&
      ctest &&
      cpack -D CPACK_GENERATOR="NSIS"
    )

  - if [%COMPILER%]==[MSVC] (
      cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF "-DCMAKE_TOOLCHAIN_FILE=%APPVEYOR_BUILD_FOLDER%\windows\cl-toolchain.cmake" "-DCMAKE_PREFIX_PATH=%QT5%;C:\Program Files\Bonjour SDK" -DCMAKE_BUILD_TYPE=Release &&
      ninja -v &&
      ctest &&
      cpack -D CPACK_GENERATOR="NSIS"
    )

artifacts:
  - path: 'build\aseba-*.exe'
    name: Aseba


cache:
  - '%MSYS_CACHE%'
  - C:\ProgramData\chocolatey\bin -> appveyor.yml
  - C:\ProgramData\chocolatey\lib -> appveyor.yml
  - 'C:\Program Files (x86)\NSIS'

image: Visual Studio 2017
platform: x64

environment:
  NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip
  SDL_URL: https://libsdl.org/release/SDL2-devel-2.0.7-VC.zip
  CMAKE_URL: https://cmake.org/files/v3.8/cmake-3.8.0-win64-x64.zip
  APPVEYOR_CACHE_ENTRY_ZIP_ARGS: "-t7z -m0=lzma -mx=5"
  matrix:
    - ARCH: x86
      QT5: C:\Qt\5.10\msvc2015
      COMPILER: MSVC
      USE_VS_TOOLCHAIN: true

    - ARCH: x64
      COMPILER: MSVC
      QT5: C:\Qt\5.10\msvc2017_64
      USE_VS_TOOLCHAIN: true

    #- COMPILER: MinGW
      #ARCH: x86
      #BASH: C:\msys64\usr\bin\bash
      #MSYS_CACHE: C:\msys64\var\cache\pacman\pkg

    #- platform: x64
      #COMPILER: MinGW
      #ARCH: x64
      #BASH: C:\msys64\usr\bin\bash
      #MSYS_CACHE: C:\msys64\var\cache\pacman\pkg

    - platform: x64
      COMPILER: ClangCL
      ARCH: x64
      LLVM_URL: http://prereleases.llvm.org/win-snapshots/LLVM-7.0.0-r323406-win64.exe
      LLVM_VERSION: 7.0
      USE_VS_TOOLCHAIN: true
      QT5: C:\Qt\5.10\msvc2017_64

deploy:
  tag: nightly
  release: nightly
  description: 'Nightly Build'
  provider: GitHub
  auth_token:
    secure: Xehpz2B9WwN2wOzHfWMBQ83W31YluiEz6s9LjOi+vOjHcMxnjYCk7mNdQhSFOuE9 # your encrypted token from GitHub
  artifact: Aseba
  prerelease: true
  on:
    branch: master
  force_update: true

