#!/bin/pwsh

$Env:LD_LIBRARY_PATH += "/opt/src"
$Env:PATH += ":/home/m2gba/.dotnet:/home/m2gba/.dotnet/tools"
Copy-Item -Path "\home\m2gba\src\*" -Destination "\opt\src" -Recurse -Force

"Starting to build tools"
./build-tools.ps1
if ($LASTEXITCODE -ne 0) { exit -1 }

"Starting to build test rom"
./test-fast.ps1
$LAST_VAL = $LASTEXITCODE

"Copying test log to output"
New-Item -Path "\home\m2gba\src" -Name "out" -ItemType "directory" -Force
Copy-Item -Path ".\bin\test.log" "\home\m2gba\src\out"
Copy-Item -Path ".\bin\m12test.gba" "\home\m2gba\src\out"

if ($LAST_VAL -ne 0) { exit -1 }

"Test ran successfully, please review the ./out folder for the resulting logs and test rom"
