81 lines
4.8 KiB
PowerShell
81 lines
4.8 KiB
PowerShell
# Windows front of scripts/release/package-5090.sh. ASCII only, PowerShell 5.1 compatible.
|
|
#
|
|
# Why two hosts: the pinned Linux toolchain lives in WSL2, but WSL2 git cannot open a worktree made by Windows git (its .git file names a C:/ path),
|
|
# and a Windows checkout with core.autocrlf=true is CRLF. So the git work happens in Git Bash and the build happens in WSL2 on an LF export.
|
|
#
|
|
# .\scripts\release\package-5090.ps1 check every gate, in Git Bash (writes nothing)
|
|
# .\scripts\release\package-5090.ps1 stage-source gates, then `git archive HEAD` into dist\release-5090\src\release-5090-src-COMMIT12 (clean tree only)
|
|
# .\scripts\release\package-5090.ps1 package [-Src DIR] build + package inside WSL2 from the staged tree (default: the newest one)
|
|
# .\scripts\release\package-5090.ps1 build [-Src DIR] only the three cargo builds
|
|
# .\scripts\release\package-5090.ps1 verify TARBALL digest check with Get-FileHash here, then the shell `verify` in WSL2
|
|
# .\scripts\release\package-5090.ps1 ptx-eol are all .ptx files of THIS checkout LF? (git ls-files --eol)
|
|
#
|
|
# Anything after the command is passed to the shell script unchanged (--rehearse, --bin-dir, --target-dir, --expert-profile, --out, ...).
|
|
# The packager never installs anything, never deletes anything and writes only under its output directory (default dist\release-5090, git-ignored).
|
|
# CARGO_TARGET_DIR stays inside the staged tree (AGENTS.md: WSL builds inside the repository folder) unless --target-dir says otherwise.
|
|
param(
|
|
[Parameter(Mandatory = $true, Position = 0)][ValidateSet('check', 'stage-source', 'build', 'package', 'verify', 'ptx-eol')][string]$Command,
|
|
[Parameter(Position = 1, ValueFromRemainingArguments = $true)][string[]]$Rest,
|
|
[string]$Src = '',
|
|
[string]$Distro = 'Ubuntu'
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$repo = (& git rev-parse --show-toplevel).Trim()
|
|
if (-not $repo) { throw 'run this inside the git checkout' }
|
|
Set-Location $repo
|
|
|
|
function ConvertTo-WslPath([string]$windowsPath) {
|
|
$full = (Resolve-Path -LiteralPath $windowsPath).Path
|
|
$drive = $full.Substring(0, 1).ToLower()
|
|
return '/mnt/' + $drive + ($full.Substring(2) -replace '\\', '/')
|
|
}
|
|
|
|
function Quote-Sh([string]$text) { return "'" + ($text -replace "'", "'\''") + "'" }
|
|
|
|
if ($Command -eq 'ptx-eol') {
|
|
$lines = & git ls-files --eol -- '*.ptx'
|
|
$bad = @($lines | Where-Object { $_ -match 'i/(crlf|mixed)|w/(crlf|mixed)' })
|
|
$total = @($lines).Count
|
|
if ($bad.Count -eq 0) { Write-Host "PASS all $total .ptx files are LF in the index and the working tree"; exit 0 }
|
|
Write-Host "FAIL $($bad.Count) of $total .ptx files are CRLF or mixed; with '*.ptx -text' in the index, re-create them from it:"
|
|
Write-Host " (Git Bash) git ls-files -z -- '*.ptx' | xargs -0 rm -f ; git ls-files -z -- '*.ptx' | xargs -0 git checkout --"
|
|
$bad | Select-Object -First 5 | ForEach-Object { Write-Host " $_" }
|
|
exit 1
|
|
}
|
|
|
|
if ($Command -in @('check', 'stage-source')) {
|
|
$bash = 'C:\Program Files\Git\bin\bash.exe'
|
|
$line = "cd " + (Quote-Sh ($repo -replace '\\', '/')) + " && sh scripts/release/package-5090.sh $Command " + (($Rest | ForEach-Object { Quote-Sh $_ }) -join ' ')
|
|
& $bash -c $line
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
# build / package / verify: inside WSL2, in the staged (LF, git-free) tree
|
|
$passThrough = @($Rest)
|
|
if ($Command -eq 'verify') {
|
|
if ($passThrough.Count -lt 1) { throw 'usage: package-5090.ps1 verify TARBALL' }
|
|
$tarball = $passThrough[0]
|
|
$sidecar = "$tarball.sha256"
|
|
if (Test-Path -LiteralPath $sidecar) {
|
|
$want = ((Get-Content -LiteralPath $sidecar -TotalCount 1) -split '\s+')[0].ToLower()
|
|
$have = (Get-FileHash -Algorithm SHA256 -LiteralPath $tarball).Hash.ToLower()
|
|
if ($want -ne $have) { Write-Host "FAIL tarball digest differs from $sidecar"; exit 1 }
|
|
Write-Host "PASS tarball digest matches $sidecar"
|
|
} else {
|
|
Write-Host "note no $sidecar next to the tarball"
|
|
}
|
|
$passThrough[0] = ConvertTo-WslPath $tarball
|
|
}
|
|
if (-not $Src) {
|
|
$newest = Get-ChildItem -LiteralPath (Join-Path $repo 'dist\release-5090\src') -Directory -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
|
if (-not $newest) { throw 'no staged tree: run stage-source first (or pass -Src DIR)' }
|
|
$Src = $newest.FullName
|
|
}
|
|
if (-not (Test-Path -LiteralPath (Join-Path $Src 'PROVENANCE.env'))) { throw "$Src is not a staged tree (no PROVENANCE.env)" }
|
|
$wslSrc = ConvertTo-WslPath $Src
|
|
$shellArgs = ($passThrough | ForEach-Object { Quote-Sh $_ }) -join ' '
|
|
# A login shell so that ~/.cargo/env is read.
|
|
$inner = ". ~/.cargo/env 2>/dev/null; cd " + (Quote-Sh $wslSrc) + " && sh scripts/release/package-5090.sh $Command $shellArgs"
|
|
& wsl.exe -d $Distro -- bash -lc $inner
|
|
exit $LASTEXITCODE
|