jobs:

  # Configure, build, install, and test job
  - job: 'vs_build'
    pool:
      vmImage: 'vs2017-win2016'
    timeoutInMinutes: 360
    steps:

      # Install Chocolatey (https://chocolatey.org/install#install-with-powershellexe)
      - powershell: |
          Set-ExecutionPolicy Bypass -Scope Process -Force
          iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
          Write-Host "##vso[task.setvariable variable=PATH]$env:PATH"
          choco --version
        displayName: "Install Chocolatey"

      # Install Miniconda
      - script: |
          choco install miniconda3 --yes
          set PATH=C:\tools\miniconda3\Scripts;C:\tools\miniconda3;C:\tools\miniconda3\Library\bin;%PATH%
          echo '##vso[task.setvariable variable=PATH]%PATH%'
          set LIB=C:\tools\miniconda3\Library\lib;%LIB%
          echo '##vso[task.setvariable variable=LIB]%LIB%'
          conda --version
        displayName: "Install Miniconda"

      # Configure Miniconda
      - script: |
          conda config --set always_yes yes
          conda config --append channels conda-forge
          conda config --append channels psi4
          conda info
        displayName: "Configure Miniconda"

      # Create conda enviroment
      # Note: conda activate doesn't work here, because it creates a new shell!
      #                  mkl-devel=%MKL_VERSION% ^
      - script: |
          conda install cmake ^
                        conda-build ^
                        conda-verify ^
                        ninja ^
                        numpy ^
                        pybind11 ^
                        python=%PYTHON_VERSION%
          conda list
        displayName: "Install conda packages"

      # Configure
      - script: |
          setlocal EnableDelayedExpansion
          call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
          mkdir build & cd build
          cmake -G Ninja ^
                -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% ^
                -DCMAKE_INSTALL_PREFIX=../install ^
                -Dlanguage=Python ^
                $(Build.SourcesDirectory)
        displayName: "Configure the MDI Library"
        workingDirectory: $(Build.BinariesDirectory)

      # Build
      - script: |
          call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
          cmake --build . ^
                --config %CMAKE_BUILD_TYPE% ^
                -- -j %NUMBER_OF_PROCESSORS%
        displayName: "Build the MDI Library"
        workingDirectory: $(Build.BinariesDirectory)/build

      # Install
      - script: |
          call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
          mkdir $(Build.BinariesDirectory)/install
          cmake --build . ^
                --config %CMAKE_BUILD_TYPE% ^
                --target install ^
                -- -j %NUMBER_OF_PROCESSORS%
        displayName: "Install the MDI Library"
        workingDirectory: $(Build.BinariesDirectory)/build
