version: 0.7.{build}
image: Visual Studio 2019
clone_folder: c:\projects\lief

configuration: Release

services:
- docker

platform:
- x86
- x64

environment:
 LIEF_AUTOMATIC_BUILDS_KEY:
    secure: TT7SXISIifq2/tf02n2ATgPj+Ky4Cjl3Fg44BAfyI4yRa4i87UAQIx5EFeV63+Xv2rhcU7JcMgl+An7QBrV6ofuQ9jxbuw+Gd1GqcCrAIyY=
 LIEF_AUTOMATIC_BUILDS_IV:
    secure: /S6Vbt3vEisoC81siFbkqOXQeVnwxLZZPMYp1r79G7h+HFjLlWUZSidxxpsAgHNE
 SCCACHE_CACHE_SIZE: "750M"
 SCCACHE_DIR: C:\Users\appveyor\AppData\Local\Mozilla\sccache
 SCCACHE_ERROR_LOG: C:\projects\sccache.log
 matrix:
    # Python 3.6
    - PYTHON_VERSION:   "3.6"
      PYTHON32_PATH:    "C:\\Python36"
      PYTHON32_INCLUDE: "C:\\Python36\\include"
      PYTHON32_BINARY:  "C:\\Python36\\python.exe"
      PYTHON32_LIBRARY: "C:\\Python36\\libs\\python36.lib"
      PYTHON64_PATH:    "C:\\Python36-x64"
      PYTHON64_INCLUDE: "C:\\Python36-x64\\include"
      PYTHON64_BINARY:  "C:\\Python36-x64\\python.exe"
      PYTHON64_LIBRARY: "C:\\Python36-x64\\libs\\python36.lib"

    # Python 3.7
    - PYTHON_VERSION:   "3.7"
      PYTHON32_PATH:    "C:\\Python37"
      PYTHON32_INCLUDE: "C:\\Python37\\include"
      PYTHON32_BINARY:  "C:\\Python37\\python.exe"
      PYTHON32_LIBRARY: "C:\\Python37\\libs\\python37.lib"
      PYTHON64_PATH:    "C:\\Python37-x64"
      PYTHON64_INCLUDE: "C:\\Python37-x64\\include"
      PYTHON64_BINARY:  "C:\\Python37-x64\\python.exe"
      PYTHON64_LIBRARY: "C:\\Python37-x64\\libs\\python37.lib"

    # Python 3.8
    - PYTHON_VERSION:   "3.8"
      PYTHON32_PATH:    "C:\\Python38"
      PYTHON32_INCLUDE: "C:\\Python38\\include"
      PYTHON32_BINARY:  "C:\\Python38\\python.exe"
      PYTHON32_LIBRARY: "C:\\Python38\\libs\\python38.lib"
      PYTHON64_PATH:    "C:\\Python38-x64"
      PYTHON64_INCLUDE: "C:\\Python38-x64\\include"
      PYTHON64_BINARY:  "C:\\Python38-x64\\python.exe"
      PYTHON64_LIBRARY: "C:\\Python38-x64\\libs\\python38.lib"

    # Python 3.9
    - PYTHON_VERSION:   "3.9"
      PYTHON32_PATH:    "C:\\Python39"
      PYTHON32_INCLUDE: "C:\\Python39\\include"
      PYTHON32_BINARY:  "C:\\Python39\\python.exe"
      PYTHON32_LIBRARY: "C:\\Python39\\libs\\python39.lib"
      PYTHON64_PATH:    "C:\\Python39-x64"
      PYTHON64_INCLUDE: "C:\\Python39-x64\\include"
      PYTHON64_BINARY:  "C:\\Python39-x64\\python.exe"
      PYTHON64_LIBRARY: "C:\\Python39-x64\\libs\\python39.lib"

cache:
  - '%SCCACHE_DIR%'

install:
  - cmd: choco install sccache
  - cmd: sccache.exe --start-server
  - ps: if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" }

  - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_PATH    = $env:PYTHON64_PATH    }
  - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_INCLUDE = $env:PYTHON64_INCLUDE }
  - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_BINARY  = $env:PYTHON64_BINARY  }
  - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_LIBRARY = $env:PYTHON64_LIBRARY }

  - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_PATH    = $env:PYTHON32_PATH    }
  - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_INCLUDE = $env:PYTHON32_INCLUDE }
  - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_BINARY  = $env:PYTHON32_BINARY  }
  - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_LIBRARY = $env:PYTHON32_LIBRARY }
  - set PATH=%PYTHON_PATH%;%PATH%

  # Upgrade pip
  - python.exe -m pip install --disable-pip-version-check --user --upgrade pip
  - python.exe -m pip install --user wheel mako
  - python.exe -m pip install --upgrade setuptools


build_script:
  - cd %APPVEYOR_BUILD_FOLDER%
  - python.exe .\setup.py --ninja --lief-test build bdist_wheel --skip-build && exit 0 # Ignore warnings...
  - ps: if ($env:PYTHON_VERSION -eq "3.9") { python.exe .\scripts\windows\package_sdk.py  }

after_build:
  - ps: Get-Service -Name 'ssh-agent' | Set-Service -StartupType Manual
  - ps: Start-Service -Name 'ssh-agent'
  - cd %APPVEYOR_BUILD_FOLDER%
  - ps: docker pull liefproject/deploy:latest
  - ps: |
      docker run `
        -v ${PWD}:/src `
        -e APPVEYOR="true" `
        -e APPVEYOR_PULL_REQUEST_NUMBER="$env:APPVEYOR_PULL_REQUEST_NUMBER" `
        -e APPVEYOR_REPO_NAME="$env:APPVEYOR_REPO_NAME" `
        -e APPVEYOR_REPO_TAG_NAME="$env:APPVEYOR_REPO_TAG_NAME" `
        -e APPVEYOR_REPO_BRANCH="$env:APPVEYOR_REPO_BRANCH" `
        -e APPVEYOR_BUILD_FOLDER="$env:APPVEYOR_BUILD_FOLDER" `
        -e LIEF_AUTOMATIC_BUILDS_KEY="$env:LIEF_AUTOMATIC_BUILDS_KEY" `
        -e LIEF_AUTOMATIC_BUILDS_IV="$env:LIEF_AUTOMATIC_BUILDS_IV" `
        --rm `
        liefproject/deploy python3 /src/.github/deploy.py
        $host.SetShouldExit(0)

on_finish:
  - cmd: sccache.exe --stop-server

artifacts:
  - path: 'dist\*.whl'
    name: python-wheel

  - path: 'build\*.zip'
    name: sdk

#deploy:
#  description: "LIEF version $(APPVEYOR_REPO_TAG_NAME)"
#  provider: GitHub
#  auth_token:
#    secure: FU9CGrZ1lm0VDHUZg6zvTL4tidluDvRegVUTehCRo2xgiOv6NZePi7TdSy5CsOdG
#  artifact: sdk;python-wheel
#  draft: false
#  prerelease: false
#  force_update: true
#  on:
#    appveyor_repo_tag: true # deploy on tag push only


