. ./exiter.ps1

$ErrorActionPreference = "Stop";
trap { $host.SetShouldExit(1) }

$BOSH_INSTALL_TARGET = Resolve-Path "${env:BOSH_INSTALL_TARGET}"
if ((Get-Item $BOSH_INSTALL_TARGET).LinkType -ne "") {
  $BOSH_INSTALL_TARGET = (Get-Item $BOSH_INSTALL_TARGET).Target
}

# Create GOPATH
New-Item -ItemType "directory" -Force src

robocopy.exe /E "${PWD}" src /xd src
if ($LASTEXITCODE -ge 8) {
    Write-Error "robocopy.exe /E ${PWD} src /xd src"
}

. C:\var\vcap\packages\golang-*-windows\bosh\compile.ps1

Push-Location code.cloudfoundry.org\guardian
go.exe build -buildvcs=false -tags windows -o "${BOSH_INSTALL_TARGET}\gdn.exe" ".\cmd\gdn"
if ($LASTEXITCODE -ne 0) {
    Write-Error "Error compiling: code.cloudfoundry.org/guardian/cmd/gdn"
}

go.exe build -buildvcs=false -tags windows -o "${BOSH_INSTALL_TARGET}\winit.exe" ".\cmd\winit"
if ($LASTEXITCODE -ne 0) {
    Write-Error "Error compiling: code.cloudfoundry.org/guardian/cmd/winit"
}
Pop-Location

Exit 0
