|
1 | 1 | #!/usr/bin/env pwsh |
2 | 2 |
|
3 | | -Write-Output "moving bazel outputs to goreleaser dist directory for packaging..." |
| 3 | +# goreleaser compiles the placeholder dummy.go (see .goreleaser.yml). This hook |
| 4 | +# replaces one target's placeholder binary in goreleaser's dist directory with |
| 5 | +# the real binary that bazel built under bazel-bin/bdist, before goreleaser |
| 6 | +# archives it. goreleaser runs the post hook once per target in parallel and |
| 7 | +# passes that target's os and arch, so each invocation swaps only its own |
| 8 | +# binary (copying every binary on every invocation would race). |
| 9 | +# |
| 10 | +# goreleaser v2 appends a CPU microarchitecture level to each output directory |
| 11 | +# (e.g. vbs_darwin_arm64_v8.0, vbs_linux_amd64_v1), while bazel emits plain |
| 12 | +# vbs_<os>_<arch> directories. Match by os/arch prefix so the swap keeps working |
| 13 | +# regardless of which microarchitecture suffix goreleaser chooses. |
4 | 14 |
|
5 | | -if (-Not (Test-Path "dist")) { |
6 | | - New-Item -Force -Path (Get-Location).Path -Name "dist" -ItemType "directory" |
| 15 | +param( |
| 16 | + [Parameter(Mandatory = $true)][string]$Os, |
| 17 | + [Parameter(Mandatory = $true)][string]$Arch |
| 18 | +) |
| 19 | + |
| 20 | +$ErrorActionPreference = "Stop" |
| 21 | + |
| 22 | +$name = "vbs_${Os}_${Arch}" |
| 23 | +$srcDir = Join-Path (Resolve-Path "bazel-bin/bdist") $name |
| 24 | +if (-Not (Test-Path $srcDir)) { |
| 25 | + throw "no bazel output at $srcDir for target $Os/$Arch" |
7 | 26 | } |
8 | 27 |
|
9 | | -Copy-Item (Resolve-Path "bazel-bin/bdist/*") -Destination (Resolve-Path "dist") -Recurse -Force |
| 28 | +$destDirs = Get-ChildItem -Path "dist" -Directory -Filter "$name*" |
| 29 | +if ($destDirs.Count -eq 0) { |
| 30 | + throw "no goreleaser dist directory matches $name; cannot swap in the bazel binary" |
| 31 | +} |
| 32 | + |
| 33 | +foreach ($destDir in $destDirs) { |
| 34 | + Copy-Item -Path (Join-Path $srcDir "*") -Destination $destDir.FullName -Recurse -Force |
| 35 | + Write-Output "swapped bazel binary $name -> dist/$($destDir.Name)" |
| 36 | +} |
0 commit comments