version: 0.3.2.{build}

environment:
  matrix:
    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
      CMAKE_GENERATOR: Visual Studio 16 2019
      TOOLSET: 142
    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
      CMAKE_GENERATOR: Visual Studio 15 2017
      TOOLSET: 141
#    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
#      TOOLSET: 140
#    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
#      TOOLSET: 120

branches:
  except:
    - coverity_scan

configuration:
- Debug
- Release

platform:
- Win32
- x64

before_build:
- git submodule sync
- git fetch --tags --prune
- git submodule update --init --recursive
- git submodule foreach --recursive git fetch --tags --prune
- cmake --version

build_script:
- ps: |
    Write-Output "*******************************************************************************"
    Write-Output "Configuration: $env:CONFIGURATION"
    Write-Output "Platform: $env:PLATFORM"
    Write-Output "Toolchain: $env:CMAKE_GENERATOR v$env:TOOLSET"
    Write-Output "*******************************************************************************"

    md _build -Force | Out-Null
    cd _build

    $generator = $env:CMAKE_GENERATOR
    if ($env:TOOLSET -lt 142) {
        if ($env:PLATFORM -eq "x64") {
            $generator = "$generator Win64"
        }
        & cmake -G "$generator" -DCMAKE_CONFIGURATION_TYPES="Debug;Release" ..
    } else {
        & cmake -G "$generator" -A $env:PLATFORM -DCMAKE_CONFIGURATION_TYPES="Debug;Release" ..
    }
    if ($LastExitCode -ne 0) {
        throw "Exec: $ErrorMessage"
    }
    Write-Output "*******************************************************************************"

    & cmake --build . --config $env:CONFIGURATION
    if ($LastExitCode -ne 0) {
        throw "Exec: $ErrorMessage"
    }
    Write-Output "*******************************************************************************"

test_script:
- ps: |
    if (($env:PLATFORM -ne "ARM") -and ($env:PLATFORM -ne "ARM64")) {
        & ./$env:CONFIGURATION/mdbx_test.exe --progress --console=no --pathname=test.db --dont-cleanup-after basic > test.log
        Get-Content test.log | Select-Object -last 42
        if ($LastExitCode -ne 0) {
            throw "Exec: $ErrorMessage"
        } else {
            & ./$env:CONFIGURATION/mdbx_chk.exe -nvv test.db | Tee-Object -file chk.log | Select-Object -last 42
        }
    }

on_failure:
- ps: Push-AppveyorArtifact _build\test.log
- ps: Push-AppveyorArtifact _build\test.db
- ps: Push-AppveyorArtifact _build\chk.log