Add disposable slot dev reload scripts
This commit is contained in:
parent
0fdbcbbe83
commit
1a0dc36148
3 changed files with 178 additions and 0 deletions
24
README.md
24
README.md
|
|
@ -43,12 +43,36 @@ dotnet build Aquarium.Engine.slnx
|
|||
dotnet run --project src\Aquarium.Engine\Aquarium.Engine.csproj
|
||||
```
|
||||
|
||||
For iteration while an Aquarium window is already open, use the dev reload
|
||||
runner instead of `dotnet run`:
|
||||
|
||||
```powershell
|
||||
.\scripts\dev-reload.ps1
|
||||
```
|
||||
|
||||
It builds to a fresh disposable slot under `artifacts\dev-reload`, starts that
|
||||
slot, records the PID, and replaces only the previous process that the script
|
||||
itself launched. This keeps MSBuild away from the locked normal
|
||||
`bin\Debug` output while a live window is still open.
|
||||
|
||||
Stop the script-owned Aquarium process:
|
||||
|
||||
```powershell
|
||||
.\scripts\dev-stop.ps1
|
||||
```
|
||||
|
||||
Headless smoke:
|
||||
|
||||
```powershell
|
||||
dotnet run --project src\Aquarium.Engine\Aquarium.Engine.csproj -- --headless
|
||||
```
|
||||
|
||||
Headless reload smoke without touching the normal build output:
|
||||
|
||||
```powershell
|
||||
.\scripts\dev-reload.ps1 -Headless
|
||||
```
|
||||
|
||||
The first cut opens a Win32 window directly and owns a D3D11 swapchain through
|
||||
Vortice. No Stride runtime, no asset protocol, no borrowed game loop wearing a
|
||||
fake mustache. See `docs/vortice-spine.md`.
|
||||
|
|
|
|||
115
scripts/dev-reload.ps1
Normal file
115
scripts/dev-reload.ps1
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
param(
|
||||
[switch]$Headless,
|
||||
[switch]$NoStop,
|
||||
[switch]$BuildOnly
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
||||
$projectPath = Join-Path $repoRoot "src\Aquarium.Engine\Aquarium.Engine.csproj"
|
||||
$devRoot = Join-Path $repoRoot "artifacts\dev-reload"
|
||||
$slotRoot = Join-Path $devRoot "slots"
|
||||
$statePath = Join-Path $devRoot "state.json"
|
||||
$stdoutLogPath = Join-Path $devRoot "latest.out.log"
|
||||
$stderrLogPath = Join-Path $devRoot "latest.err.log"
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $slotRoot | Out-Null
|
||||
|
||||
function Stop-PreviousOwnedProcess {
|
||||
if ($NoStop -or -not (Test-Path $statePath)) {
|
||||
return
|
||||
}
|
||||
|
||||
$state = Get-Content -Raw -Path $statePath | ConvertFrom-Json
|
||||
if (-not $state.pid) {
|
||||
return
|
||||
}
|
||||
|
||||
$process = Get-Process -Id ([int]$state.pid) -ErrorAction SilentlyContinue
|
||||
if (-not $process) {
|
||||
return
|
||||
}
|
||||
|
||||
$recordedPath = [string]$state.slot
|
||||
$commandLine = $null
|
||||
try {
|
||||
$commandLine = (Get-CimInstance Win32_Process -Filter "ProcessId = $($process.Id)").CommandLine
|
||||
}
|
||||
catch {
|
||||
$commandLine = $null
|
||||
}
|
||||
|
||||
if (-not $commandLine -or $commandLine -notlike "*$recordedPath*") {
|
||||
Write-Host "Previous PID $($state.pid) no longer belongs to the recorded slot; leaving it alone."
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "Stopping previous script-owned Aquarium process $($state.pid)."
|
||||
Stop-Process -Id ([int]$state.pid) -Force
|
||||
}
|
||||
|
||||
Stop-PreviousOwnedProcess
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$slotName = "$timestamp-$([guid]::NewGuid().ToString("N").Substring(0, 8))"
|
||||
$slotPath = Join-Path $slotRoot $slotName
|
||||
New-Item -ItemType Directory -Force -Path $slotPath | Out-Null
|
||||
|
||||
Write-Host "Building Aquarium into disposable slot:"
|
||||
Write-Host " $slotPath"
|
||||
dotnet build $projectPath `
|
||||
-c Debug `
|
||||
-o $slotPath `
|
||||
/p:UseAppHost=false
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "dotnet build failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
|
||||
if ($BuildOnly) {
|
||||
@{
|
||||
slot = $slotPath
|
||||
builtAt = (Get-Date).ToString("o")
|
||||
pid = $null
|
||||
stdoutLog = $stdoutLogPath
|
||||
stderrLog = $stderrLogPath
|
||||
} | ConvertTo-Json | Set-Content -Path $statePath
|
||||
Write-Host "Build-only slot ready."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$dllPath = Join-Path $slotPath "Aquarium.Engine.dll"
|
||||
$arguments = @($dllPath)
|
||||
if ($Headless) {
|
||||
$arguments += "--headless"
|
||||
}
|
||||
|
||||
$startProcessParameters = @{
|
||||
FilePath = "dotnet"
|
||||
ArgumentList = $arguments
|
||||
WorkingDirectory = $slotPath
|
||||
RedirectStandardOutput = $stdoutLogPath
|
||||
RedirectStandardError = $stderrLogPath
|
||||
PassThru = $true
|
||||
}
|
||||
|
||||
if ($Headless) {
|
||||
$startProcessParameters.WindowStyle = "Hidden"
|
||||
}
|
||||
|
||||
$process = Start-Process @startProcessParameters
|
||||
|
||||
@{
|
||||
slot = $slotPath
|
||||
builtAt = (Get-Date).ToString("o")
|
||||
pid = $process.Id
|
||||
stdoutLog = $stdoutLogPath
|
||||
stderrLog = $stderrLogPath
|
||||
} | ConvertTo-Json | Set-Content -Path $statePath
|
||||
|
||||
Write-Host "Aquarium running from disposable slot."
|
||||
Write-Host " PID: $($process.Id)"
|
||||
Write-Host " Stdout: $stdoutLogPath"
|
||||
Write-Host " Stderr: $stderrLogPath"
|
||||
Write-Host "Run this script again to replace only this script-owned process."
|
||||
39
scripts/dev-stop.ps1
Normal file
39
scripts/dev-stop.ps1
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
$ErrorActionPreference = "Stop"
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
||||
$statePath = Join-Path $repoRoot "artifacts\dev-reload\state.json"
|
||||
|
||||
if (-not (Test-Path $statePath)) {
|
||||
Write-Host "No dev-reload state file exists."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$state = Get-Content -Raw -Path $statePath | ConvertFrom-Json
|
||||
if (-not $state.pid) {
|
||||
Write-Host "No script-owned Aquarium PID is recorded."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$process = Get-Process -Id ([int]$state.pid) -ErrorAction SilentlyContinue
|
||||
if (-not $process) {
|
||||
Write-Host "Recorded Aquarium process $($state.pid) is not running."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$recordedPath = [string]$state.slot
|
||||
$commandLine = $null
|
||||
try {
|
||||
$commandLine = (Get-CimInstance Win32_Process -Filter "ProcessId = $($process.Id)").CommandLine
|
||||
}
|
||||
catch {
|
||||
$commandLine = $null
|
||||
}
|
||||
|
||||
if (-not $commandLine -or $commandLine -notlike "*$recordedPath*") {
|
||||
Write-Host "PID $($state.pid) no longer belongs to the recorded slot; leaving it alone."
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "Stopping script-owned Aquarium process $($state.pid)."
|
||||
Stop-Process -Id ([int]$state.pid) -Force
|
||||
Loading…
Reference in a new issue