Files
bd2/go/build/bootstrap.ps1
T
Flechazo 92bdf2e421 perf(all): bypass build bootstrap for help and unknown tasks
Read the shared task catalog and help text directly in both wrappers.
Cache Windows build tools by source fingerprints and avoid replacing active executables.
2026-10-24 01:21:15 +08:00

35 lines
1.5 KiB
PowerShell

param(
[Parameter(Mandatory)][string]$Root,
[Parameter(Mandatory)][string]$Candidate
)
$ErrorActionPreference = 'Stop'
try {
$inputs = [Collections.Generic.List[string]]::new()
foreach ($directory in @('go/build', 'go/internal')) {
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $Root $directory) -Recurse -File) {
$inputs.Add("$($file.FullName)|$($file.Length)|$($file.LastWriteTimeUtc.Ticks)")
}
}
foreach ($name in @('bd2w.cmd', 'go/go.mod', 'go/go.sum')) {
$file = Get-Item -LiteralPath (Join-Path $Root $name)
$inputs.Add("$($file.FullName)|$($file.Length)|$($file.LastWriteTimeUtc.Ticks)")
}
$compiler = Get-Item -LiteralPath (Get-Command go -CommandType Application).Source
$inputs.Add("$($compiler.FullName)|$($compiler.Length)|$($compiler.LastWriteTimeUtc.Ticks)")
$inputs.Sort([StringComparer]::Ordinal)
$sha = [Security.Cryptography.SHA256]::Create()
try {
$signature = [BitConverter]::ToString($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes([string]::Join("`n", $inputs)))).Replace("-", "").ToLowerInvariant()
} finally {
$sha.Dispose()
}
$tool = Join-Path $Root ('.build/tools/bd2w-' + $signature + '.exe')
[IO.File]::WriteAllText($Candidate, $tool, [Text.Encoding]::Default)
if (Test-Path -LiteralPath $tool -PathType Leaf) { exit 0 }
exit 1
} catch {
[Console]::Error.WriteLine("bd2w: cannot check build tool inputs: $($_.Exception.Message)")
exit 2
}