. ./exiter.ps1

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

$BOSH_INSTALL_TARGET = Resolve-Path "${env:BOSH_INSTALL_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

$pkg_name="healthcheck"
$pkg_path="code.cloudfoundry.org/healthcheck/cmd/healthcheck"

$env:CGO_ENABLED=0

New-Item -ItemType directory -Path "${BOSH_INSTALL_TARGET}\internal" -Force
New-Item -ItemType directory -Path "${BOSH_INSTALL_TARGET}\external" -Force

Push-Location src/code.cloudfoundry.org
go.exe build -buildvcs=false -tags=external -a -installsuffix static -o "${BOSH_INSTALL_TARGET}\external\${pkg_name}.exe" "${pkg_path}"
if ($LASTEXITCODE -ne 0) {
    Write-Error "Error compiling: ${pkg_path}"
}

go.exe build -buildvcs=false -a -installsuffix static -o "${BOSH_INSTALL_TARGET}\internal\${pkg_name}.exe" "${pkg_path}"
if ($LASTEXITCODE -ne 0) {
    Write-Error "Error compiling: ${pkg_path}"
}

Pop-Location

Exit 0
