environment:
  PYTHON_VERSION: "2.7.x"
  PYTHON_ARCH: "32"
  APPVEYOR_SAVE_CACHE_ON_ERROR: true

  matrix:
    - TOXENV: py27
    - PYTHON_VERSION: "2.7.x"

pull_requests:
  do_not_increment_build_number: true

install:
  # If there is a newer build queued for the same PR, cancel this one.
  # The AppVeyor 'rollout builds' option is supposed to serve the same
  # purpose but it is problematic because it tends to cancel builds pushed
  # directly to master instead of just PR builds (or the converse).
  # credits: JuliaLang developers.
  - ps:
      if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
      https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
      Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
      throw "There are newer queued builds for this pull request, failing early." }

  - "python -m pip install --upgrade pip"
  - if defined TOXENV (
    pip install tox tox_venv
    )
  - if not defined TOXENV (
    pip install
    -rrequirements.txt
    pygame
    bbfreeze
    pefile
    )

  - echo "Installing openssl...."
  - if not exist openssl-1.1.0f-vs2008.7z (
    echo "Downloading openssl...."
    & appveyor-retry appveyor DownloadFile "https://www.npcglib.org/~stathis/downloads/openssl-1.1.0f-vs2008.7z"
    )
  - "7z x -oc:\\ -aoa openssl-1.1.0f-vs2008.7z"
  - "rename c:\\openssl-1.1.0f-vs2008 openssl-1.1"
  - "copy c:\\openssl-1.1\\bin\\libsslMD.dll c:\\openssl-1.1\\bin\\libssl-1_1.dll"
  - "copy c:\\openssl-1.1\\bin\\libcryptoMD.dll c:\\openssl-1.1\\bin\\libcrypto-1_1.dll"

  - echo "Installing libtorrent...."
  - if not exist libtorrent.pyd (
    echo "Downloading libtorrent...."
    & appveyor-retry appveyor DownloadFile "https://github.com/doadin/libtorrent/releases/download/1.1.7.test/libtorrent.pyd"
    )
  - "copy /Y libtorrent.pyd c:\\Python27\\Lib\\site-packages\\libtorrent.pyd"
  - "SET PATH=%TOXENV%;%PYTHON%;%PYTHON%\\Scripts;c:\\openssl-1.1\\bin;C:\\Program Files (x86)\\NSIS;%PATH%"

  - "python --version"
  - 'python -c "import struct; print(struct.calcsize(\"P\") * 8)"'
  - 'python -c "import libtorrent; print(libtorrent.__version__)"'
  - openssl version -v

cache:
  - openssl-1.1.0f-vs2008.7z
  - '%LOCALAPPDATA%\pip\cache'
  - libtorrent.pyd

build: false

test_script:
  - if defined TOXENV tox

# Commented out as require GTK3 to create package.
# after_test:
# - if not defined TOXENV python setup.py build && python setup.py install
# - cd %APPVEYOR_BUILD_FOLDER%\\packaging\\win32
# - if not defined TOXENV deluge-bbfreeze.py debug
# - if not defined TOXENV makensis deluge-win32-installer.nsi
# - if not defined TOXENV 7z a deluge-win32.zip build-win32 "-x!*.exe"

# artifacts:
# - path: packaging\win32\deluge-win32.zip
# - path: packaging\win32\build-win32\*.exe

#on_success:
#
