environment:
  ANDROID_HOME: "C:\\android-sdk-windows"
  ANDROID_NDK_HOME: "C:\\android-sdk-windows\\ndk-bundle"
  JAVA_HOME: "C:\\Program Files\\Java\\jdk1.8.0"
  BORINGSSL_HOME: "C:\\boringssl"
  ANDROID_TOOLS_URL: "https://dl.google.com/android/repository/tools_r25.2.3-windows.zip"
  NINJA_URL: "https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip"
  CMAKE_URL: "https://cmake.org/files/v3.4/cmake-3.4.0-win32-x86.zip"
  MSVC_HOME: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community"

clone_folder: "C:\\projects\\conscrypt"
shallow_clone: true

os: Visual Studio 2017

platform:
  # - x86
  - x64

version: '{branch}.{build}'

pull_requests:
    do_not_increment_build_number: true

build:
    verbosity: minimal

init:
  # Download the Android SDK
  - appveyor DownloadFile %ANDROID_TOOLS_URL% -FileName android-tools.zip
  - 7z x android-tools.zip -o"%ANDROID_HOME%" > nul

  # Get Ninja
  - appveyor DownloadFile %NINJA_URL% -FileName ninja.zip
  - 7z x ninja.zip -oC:\ninja > nul
  - set PATH=C:\ninja;%PATH%
  - ninja --version

  # Get CMake
  - appveyor DownloadFile %CMAKE_URL% -FileName cmake.zip
  - 7z x cmake.zip -oC:\cmake > nul
  - set PATH=C:\cmake\bin;%PATH%
  - cmake --version

  # Install yasm
  - choco install -y --allow-empty-checksums yasm

  # Install Go for BoringSSL compile (embedding test data)
  - choco install -y --allow-empty-checksums golang

  # Clone BoringSSL
  - git clone --depth 1 https://boringssl.googlesource.com/boringssl.git "%BORINGSSL_HOME%"

  # Work around gradle bug https://github.com/gradle/gradle/issues/929
  - set PATH=C:\Program Files (x86)\Windows Kits\8.1\bin\x86;%PATH%

before_build:
  # Build BoringSSL in 64-bit
  - call "%MSVC_HOME%\VC\Auxiliary\Build\vcvarsall.bat" x64
  - cd "%BORINGSSL_HOME%"
  - mkdir build64
  - cd build64
  - cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release "-DCMAKE_C_FLAGS_RELEASE=/MT -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" "-DCMAKE_CXX_FLAGS_RELEASE=/MT -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" -GNinja ..
  - ninja

  # Build BoringSSL in 32-bit
  - call "%MSVC_HOME%\VC\Auxiliary\Build\vcvarsall.bat" x86
  - cd "%BORINGSSL_HOME%"
  - mkdir build32
  - cd build32
  - cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release "-DCMAKE_C_FLAGS_RELEASE=/MT -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" "-DCMAKE_CXX_FLAGS_RELEASE=/MT -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" -GNinja ..
  - ninja

  # Go to project directory
  - cd C:\projects\conscrypt

install:
  - mkdir %ANDROID_HOME%\licenses
  - ps: 'Add-Content -Value "`n8933bad161af4178b1185d1a37fbf41ea5269c55`n`nd56f5187479451eabf01fb78af6dfcb131a6481e" -Path $env:ANDROID_HOME\licenses\android-sdk-license -Encoding ASCII'
  - ps: 'Add-Content -Value "`n84831b9409646a918e30573bab4c9c91346d8abd`n504667f4c0de7af1a06de9f4b1727b84351f2910" -Path $env:ANDROID_HOME\licenses\android-sdk-preview-license -Encoding ASCII'
  - ps: 'Add-Content -Value "`nd975f751698a77b662f1254ddbeed3901e976f5a" -Path $env:ANDROID_HOME\licenses\intel-android-extra-license -Encoding ASCII'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat tools'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat platform-tools'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat build-tools;25.0.0'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat platforms;android-25'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat extras;android;m2repository'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat --channel=1 ndk-bundle'
  - '%ANDROID_HOME%\tools\bin\sdkmanager.bat cmake;3.6.4111459'

build_script:
  - gradlew.bat assemble

test_script:
  - gradlew.bat check

after_test:
  - ps: |
      $url = "https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)"
      $files = Get-ChildItem '.\openjdk\build\test-results\windows_x86_64Test\TEST-*.xml'
      ForEach ($file in $files) {
          (New-Object 'System.Net.WebClient').UploadFile($url, (Resolve-Path $file))
      }

artifacts:
  - path: openjdk\build\reports\
    name: Test reports
  - path: openjdk\build\libs\*.jar
    name: OpenJDK binaries
  - path: android\build\outputs\aar\*.aar
    name: Android binaries

cache:
  - "%USERPROFILE%\\.m2"
  - "%USERPROFILE%\\.gradle"
  - C:\ProgramData\chocolatey\bin
  - C:\ProgramData\chocolatey\lib

# Debug
#on_finish:
#  - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
