Quiet platform and Apple validation wrappers

This commit is contained in:
2026-06-17 09:36:21 +02:00
parent 01ff014dd9
commit c1163e39e4
7 changed files with 343 additions and 12 deletions

View File

@@ -4,7 +4,10 @@ param(
[string]$RemoteDirectory = "~/Dev/panopainter",
[string]$RepositoryUrl = "ssh://git@git.omar.synology.me:3022/omar/panopainter.git",
[string]$Branch = "codex/modernization-cmake-foundation",
[string[]]$Presets = @("macos", "ios-simulator", "ios-device")
[string[]]$Presets = @("macos", "ios-simulator", "ios-device"),
[switch]$Quiet,
[string]$LogDir = "out/logs/apple-remote-build",
[int]$FailureTailLines = 0
)
$ErrorActionPreference = "Stop"
@@ -36,6 +39,8 @@ $repositoryLiteral = ConvertTo-ShellSingleQuoted -Value $RepositoryUrl
$branchLiteral = ConvertTo-ShellSingleQuoted -Value $Branch
$presetLiteral = ConvertTo-ShellSingleQuoted -Value $presetArgument
$quietLiteral = if ($Quiet) { "1" } else { "0" }
$remoteScript = @"
set -eu
export PATH="/opt/homebrew/bin:/usr/local/bin:`$HOME/tools/bin:`$PATH"
@@ -45,6 +50,7 @@ remote_dir=$remoteDirectoryLiteral
repository_url=$repositoryLiteral
branch_name=$branchLiteral
presets=$presetLiteral
quiet_mode=$quietLiteral
case "`$remote_dir" in
"~/"*) remote_dir="`$HOME/`$(printf '%s' "`$remote_dir" | sed 's|^~/||')" ;;
@@ -83,11 +89,79 @@ set -e
printf '{"command":"apple-remote-build","host":"%s","branch":"%s","presets":"%s","log":"%s","exitCode":%s}\n' \
"`$(hostname)" "`$branch_name" "`$presets" "`$log" "`$exit_code"
tail -n 80 "`$log"
if [ "`$quiet_mode" != "1" ]; then
tail -n 80 "`$log"
fi
exit "`$exit_code"
"@
$remoteScript = $remoteScript -replace "`r`n", "`n"
$encodedRemoteScript = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($remoteScript))
& ssh -o BatchMode=yes $HostName "printf '%s' '$encodedRemoteScript' | base64 -D | sh"
exit $LASTEXITCODE
if (-not $Quiet) {
& ssh -o BatchMode=yes $HostName "printf '%s' '$encodedRemoteScript' | base64 -D | sh"
exit $LASTEXITCODE
}
New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
$runId = Get-Date -Format "yyyyMMdd-HHmmss"
$logPath = Join-Path -Path $LogDir -ChildPath "$runId-apple-remote-build.log"
$stderrPath = Join-Path -Path $LogDir -ChildPath "$runId-apple-remote-build.stderr.log"
$started = Get-Date
$exitCode = 0
try {
$process = Start-Process `
-FilePath "ssh" `
-ArgumentList @("-o", "BatchMode=yes", $HostName, "printf '%s' '$encodedRemoteScript' | base64 -D | sh") `
-NoNewWindow `
-Wait `
-PassThru `
-RedirectStandardOutput $logPath `
-RedirectStandardError $stderrPath
$exitCode = $process.ExitCode
}
catch {
$_ | Out-File -LiteralPath $LogPath -Append -Encoding utf8
$exitCode = 1
}
finally {
if (Test-Path -LiteralPath $stderrPath) {
Get-Content -LiteralPath $stderrPath | Out-File -LiteralPath $logPath -Append -Encoding utf8
Remove-Item -LiteralPath $stderrPath -Force
}
}
$rawLines = if (Test-Path -LiteralPath $logPath) {
@(Get-Content -LiteralPath $logPath)
} else {
@()
}
$remoteSummary = $null
foreach ($line in $rawLines) {
if ($line -match '"command":"apple-remote-build"') {
try {
$remoteSummary = $line | ConvertFrom-Json
}
catch {
}
}
}
$payload = [ordered]@{
command = "apple-remote-build"
exitCode = $exitCode
elapsedMs = [int]((Get-Date) - $started).TotalMilliseconds
host = $HostName
branch = $Branch
presets = $Presets
log = $logPath
}
if ($null -ne $remoteSummary) {
$payload.remoteHost = $remoteSummary.host
$payload.remoteLog = $remoteSummary.log
}
if ($exitCode -ne 0 -and $FailureTailLines -gt 0 -and $rawLines.Count -gt 0) {
$payload.failureTail = @($rawLines | Select-Object -Last $FailureTailLines | ForEach-Object { [string]$_ })
}
$payload | ConvertTo-Json -Compress -Depth 6
exit $exitCode

View File

@@ -80,7 +80,10 @@ param(
"pp_app_core_main_toolbar_tests",
"pp_app_core_quick_ui_tests",
"pp_app_core_tools_menu_tests"
)
),
[switch]$Quiet,
[string]$LogDir = "out/logs/platform-build",
[int]$FailureTailLines = 0
)
$ErrorActionPreference = "Stop"
@@ -100,6 +103,64 @@ function Expand-ArgumentList {
return $expanded
}
function Limit-LogSlug {
param(
[string]$Value,
[int]$MaxLength = 96
)
if ($Value.Length -le $MaxLength) {
return $Value
}
return $Value.Substring(0, $MaxLength)
}
function Invoke-LoggedCommand {
param(
[string]$Command,
[string[]]$Arguments,
[string]$LogPath,
[int]$FailureTailLines
)
$started = Get-Date
$exitCode = 0
$restoreNativeCommandPreference = $false
if (Get-Variable -Name PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue) {
$previousNativeCommandPreference = $PSNativeCommandUseErrorActionPreference
$PSNativeCommandUseErrorActionPreference = $false
$restoreNativeCommandPreference = $true
}
try {
& $Command @Arguments *> $LogPath
$exitCode = $LASTEXITCODE
if ($null -eq $exitCode) {
$exitCode = 0
}
}
catch {
$_ | Out-File -LiteralPath $LogPath -Append -Encoding utf8
$exitCode = 1
}
finally {
if ($restoreNativeCommandPreference) {
$PSNativeCommandUseErrorActionPreference = $previousNativeCommandPreference
}
}
$result = [ordered]@{
exitCode = $exitCode
elapsedMs = [int]((Get-Date) - $started).TotalMilliseconds
log = $LogPath
}
if ($exitCode -ne 0 -and $FailureTailLines -gt 0 -and (Test-Path -LiteralPath $LogPath)) {
$result.failureTail = @(Get-Content -LiteralPath $LogPath -Tail $FailureTailLines | ForEach-Object { [string]$_ })
}
return $result
}
function Get-VcpkgRoot {
$candidates = @()
if ($env:VCPKG_ROOT) {
@@ -153,6 +214,11 @@ if ($Presets | Where-Object { $_ -like "android-*" }) {
$started = Get-Date
$results = @()
$overallExitCode = 0
$runId = Get-Date -Format "yyyyMMdd-HHmmss"
if ($Quiet) {
New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
}
foreach ($preset in $Presets) {
$presetCmakeCommand = $cmakeCommand
@@ -160,15 +226,35 @@ foreach ($preset in $Presets) {
$presetCmakeCommand = "cmake"
}
& $presetCmakeCommand --preset $preset
$configureExitCode = $LASTEXITCODE
$configureExitCode = 0
$configureLog = $null
if ($Quiet) {
$configureLog = Join-Path -Path $LogDir -ChildPath ("{0}-configure-{1}.log" -f $runId, (Limit-LogSlug (($preset -replace "[^A-Za-z0-9_.-]", "_"))))
$configureResult = Invoke-LoggedCommand `
-Command $presetCmakeCommand `
-Arguments @("--preset", $preset) `
-LogPath $configureLog `
-FailureTailLines $FailureTailLines
$configureExitCode = $configureResult.exitCode
}
else {
& $presetCmakeCommand --preset $preset
$configureExitCode = $LASTEXITCODE
}
if ($configureExitCode -ne 0) {
$overallExitCode = $configureExitCode
$results += [ordered]@{
$result = [ordered]@{
preset = $preset
stage = "configure"
exitCode = $configureExitCode
}
if ($Quiet) {
$result.log = $configureLog
if ($configureResult.Contains("failureTail")) {
$result.failureTail = $configureResult.failureTail
}
}
$results += $result
continue
}
@@ -177,18 +263,39 @@ foreach ($preset in $Presets) {
$buildArgs += @("--target", $target)
}
& $presetCmakeCommand @buildArgs
$buildExitCode = $LASTEXITCODE
$buildExitCode = 0
$buildLog = $null
if ($Quiet) {
$safeTargets = Limit-LogSlug (($Targets -join "_") -replace "[^A-Za-z0-9_.-]", "_")
$buildLog = Join-Path -Path $LogDir -ChildPath ("{0}-build-{1}-{2}.log" -f $runId, ($preset -replace "[^A-Za-z0-9_.-]", "_"), $safeTargets)
$buildResult = Invoke-LoggedCommand `
-Command $presetCmakeCommand `
-Arguments $buildArgs `
-LogPath $buildLog `
-FailureTailLines $FailureTailLines
$buildExitCode = $buildResult.exitCode
}
else {
& $presetCmakeCommand @buildArgs
$buildExitCode = $LASTEXITCODE
}
if ($buildExitCode -ne 0 -and $overallExitCode -eq 0) {
$overallExitCode = $buildExitCode
}
$results += [ordered]@{
$result = [ordered]@{
preset = $preset
stage = "build"
targets = $Targets
exitCode = $buildExitCode
}
if ($Quiet) {
$result.log = $buildLog
if ($buildResult.Contains("failureTail")) {
$result.failureTail = $buildResult.failureTail
}
}
$results += $result
}
$elapsed = [int]((Get-Date) - $started).TotalMilliseconds

View File

@@ -13,7 +13,12 @@ param(
[string]$LogDir = "out/logs/quiet-validation",
[string]$IgnoreFilterFile = "",
[string[]]$IgnorePattern = @(),
[int]$FailureTailLines = 0
[int]$FailureTailLines = 0,
[switch]$IncludePlatformBuild,
[string[]]$PlatformBuildPresets = @("android-arm64", "android-x64", "android-quest-arm64", "android-focus-arm64"),
[string[]]$PlatformBuildTargets = @(),
[switch]$IncludeAppleRemote,
[string[]]$AppleRemotePresets = @("macos", "ios-simulator", "ios-device")
)
$ErrorActionPreference = "Stop"
@@ -179,6 +184,12 @@ function Invoke-QuietStep {
$started = Get-Date
$exitCode = 0
$restoreNativeCommandPreference = $false
if (Get-Variable -Name PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue) {
$previousNativeCommandPreference = $PSNativeCommandUseErrorActionPreference
$PSNativeCommandUseErrorActionPreference = $false
$restoreNativeCommandPreference = $true
}
try {
& $Command @Arguments *> $LogPath
$exitCode = $LASTEXITCODE
@@ -190,6 +201,11 @@ function Invoke-QuietStep {
$_ | Out-File -LiteralPath $LogPath -Append -Encoding utf8
$exitCode = 1
}
finally {
if ($restoreNativeCommandPreference) {
$PSNativeCommandUseErrorActionPreference = $previousNativeCommandPreference
}
}
$elapsed = [int]((Get-Date) - $started).TotalMilliseconds
$summary = Measure-Log -Path $LogPath -IgnorePatterns $IgnorePatterns
@@ -212,6 +228,9 @@ $resolvedCMake = Resolve-CMakeCommand -Requested $CMakeCommand
$resolvedCTest = Resolve-CTestCommand -Requested $CTestCommand -ResolvedCMake $resolvedCMake
$BuildTargets = @(Expand-ArgumentList -Values $BuildTargets)
$IgnorePattern = @(Expand-ArgumentList -Values $IgnorePattern)
$PlatformBuildPresets = @(Expand-ArgumentList -Values $PlatformBuildPresets)
$PlatformBuildTargets = @(Expand-ArgumentList -Values $PlatformBuildTargets)
$AppleRemotePresets = @(Expand-ArgumentList -Values $AppleRemotePresets)
$ignorePatterns = Read-IgnorePatterns -FilterFile $IgnoreFilterFile -InlinePatterns $IgnorePattern
New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
@@ -283,6 +302,76 @@ if (-not $SkipTests) {
}
}
if ($IncludePlatformBuild) {
$safePresets = if ($PlatformBuildPresets.Count -gt 0) {
Limit-LogSlug -Value (($PlatformBuildPresets -join "_") -replace "[^A-Za-z0-9_.-]", "_")
} else {
"defaults"
}
$log = Join-Path -Path $LogDir -ChildPath "$runId-platform-build-$safePresets.log"
$platformArgs = @(
"-ExecutionPolicy", "Bypass",
"-File", (Join-Path -Path $PSScriptRoot -ChildPath "platform-build.ps1"),
"-Quiet",
"-FailureTailLines", [string]$FailureTailLines
)
foreach ($preset in $PlatformBuildPresets) {
$platformArgs += @("-Presets", $preset)
}
foreach ($target in $PlatformBuildTargets) {
$platformArgs += @("-Targets", $target)
}
$result = Invoke-QuietStep `
-Name "platform-build" `
-Command "powershell" `
-Arguments $platformArgs `
-LogPath $log `
-IgnorePatterns $ignorePatterns `
-FailureTailLines $FailureTailLines
if ($PlatformBuildPresets.Count -gt 0) {
$result.presets = $PlatformBuildPresets
}
if ($PlatformBuildTargets.Count -gt 0) {
$result.targets = $PlatformBuildTargets
}
$results += $result
if ($result.exitCode -ne 0 -and $overallExitCode -eq 0) {
$overallExitCode = $result.exitCode
}
}
if ($IncludeAppleRemote) {
$safePresets = if ($AppleRemotePresets.Count -gt 0) {
Limit-LogSlug -Value (($AppleRemotePresets -join "_") -replace "[^A-Za-z0-9_.-]", "_")
} else {
"defaults"
}
$log = Join-Path -Path $LogDir -ChildPath "$runId-apple-remote-$safePresets.log"
$appleArgs = @(
"-ExecutionPolicy", "Bypass",
"-File", (Join-Path -Path $PSScriptRoot -ChildPath "apple-remote-build.ps1"),
"-Quiet",
"-FailureTailLines", [string]$FailureTailLines
)
foreach ($preset in $AppleRemotePresets) {
$appleArgs += @("-Presets", $preset)
}
$result = Invoke-QuietStep `
-Name "apple-remote-build" `
-Command "powershell" `
-Arguments $appleArgs `
-LogPath $log `
-IgnorePatterns $ignorePatterns `
-FailureTailLines $FailureTailLines
if ($AppleRemotePresets.Count -gt 0) {
$result.presets = $AppleRemotePresets
}
$results += $result
if ($result.exitCode -ne 0 -and $overallExitCode -eq 0) {
$overallExitCode = $result.exitCode
}
}
$elapsed = [int]((Get-Date) - $started).TotalMilliseconds
$summaryPath = Join-Path -Path $LogDir -ChildPath "$runId-summary.json"
$payload = [ordered]@{