os: Visual Studio 2015

environment:
  CTEST_OUTPUT_ON_FAILURE: 1
  ruby_version: 22-x64
  TargetPath: sassc/bin/sassc
  matrix:
  - Compiler: msvc
    Config: Release
  - Compiler: msvc
    Config: Debug
  - Compiler: mingw
    Build: static
  - Compiler: mingw
    Build: shared

cache:
  - C:\Ruby%ruby_version%\lib\ruby\gems
  - C:\mingw64

install:
  - git clone https://github.com/sass/sassc.git
  - git clone https://github.com/sass/sass-spec.git
  - set PATH=C:\Ruby%ruby_version%\bin;%PATH%
  - ps: |
      if(!(gem which minitest 2>$nul)) { gem install minitest --no-ri --no-rdoc }
      if ($env:Compiler -eq "mingw" -AND -Not (Test-Path "C:\mingw64")) {
        # Install MinGW.
        $file = "x86_64-4.9.2-release-win32-seh-rt_v4-rev3.7z"
        $url  = "https://bintray.com/artifact/download/drewwells/generic/"
        $url += $file
        Invoke-WebRequest -UserAgent wget -Uri $url -OutFile $file
        &7z x -oC:\ $file > $null
      }
  - set PATH=C:\mingw64\bin;%PATH%
  - set CC=gcc

build_script:
  - ps: |
      if ($env:Compiler -eq "mingw") {
        mingw32-make -j4 sassc
      } else {
        msbuild /m:4 /p:Configuration=$env:Config sassc\win\sassc.sln
      }

      # print the branding art
      mv script/branding script/branding.ps1
      script/branding.ps1

      # print the version info
      &$env:TargetPath -v
      ruby -v

test_script:
  - ps: |
      $PRNR = [System.Environment]::ExpandEnvironmentVariables("%APPVEYOR_PULL_REQUEST_NUMBER%")
      if ($PRNR -ne "") {
        echo "Fetching info for PR $PRNR"
        $request = (New-Object System.Net.WebClient)
        $request.headers['User-Agent'] = "Mozilla/5.0"
        $request.DownloadFile( "https://api.github.com/repos/sass/libsass/pulls/$PRNR", 'pr.json')
        $json = [IO.File]::ReadAllText('pr.json')
        $SPEC_PR = [regex]::match($json,'sass\/sass-spec(#|\/pull\/)([0-9]+)').Groups[2].Value
        if ($SPEC_PR -ne "") {
          echo "Checkout sass spec PR $SPEC_PR"
          git -C sass-spec fetch -q -u origin pull/$SPEC_PR/head:ci-spec-pr-$SPEC_PR
          git -C sass-spec checkout -q --force ci-spec-pr-$SPEC_PR
        }
      }
      ruby sass-spec/sass-spec.rb -c $env:TargetPath -s --ignore-todo sass-spec/spec
