This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new 242bfe6e1 fix(rmqctl): restore shell state after Windows build (#7060)
242bfe6e1 is described below
commit 242bfe6e17116172aea3d533edd29de35462b83a
Author: Loyal-Young <[email protected]>
AuthorDate: Mon Oct 26 21:21:59 2026 +0800
fix(rmqctl): restore shell state after Windows build (#7060)
* fix(rmqctl): restore shell state after Windows build
---
rmqctl/scripts/build-windows.ps1 | 14 +++++++++++++-
rmqctl/scripts/build_windows_test.go | 17 +++++++++++++++--
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/rmqctl/scripts/build-windows.ps1 b/rmqctl/scripts/build-windows.ps1
index 46cc8ca35..7c4fdf99a 100644
--- a/rmqctl/scripts/build-windows.ps1
+++ b/rmqctl/scripts/build-windows.ps1
@@ -53,7 +53,12 @@ $ErrorActionPreference = "Stop"
# Resolve module root: this script lives in scripts/, module root is one level
up.
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$moduleRoot = Split-Path -Parent $scriptDir
-Set-Location $moduleRoot
+$previousGoos = [Environment]::GetEnvironmentVariable("GOOS", "Process")
+$previousGoarch = [Environment]::GetEnvironmentVariable("GOARCH", "Process")
+$previousCgoEnabled = [Environment]::GetEnvironmentVariable("CGO_ENABLED",
"Process")
+$previousPath = [Environment]::GetEnvironmentVariable("Path", "Process")
+Push-Location -LiteralPath $moduleRoot
+try {
# Locate the Go toolchain.
if (-not (Get-Command go -ErrorAction SilentlyContinue)) {
@@ -102,3 +107,10 @@ if ($RunTests) {
}
Write-Host ">> done. verify with: .\$Output version"
+} finally {
+ [Environment]::SetEnvironmentVariable("GOOS", $previousGoos, "Process")
+ [Environment]::SetEnvironmentVariable("GOARCH", $previousGoarch, "Process")
+ [Environment]::SetEnvironmentVariable("CGO_ENABLED", $previousCgoEnabled,
"Process")
+ [Environment]::SetEnvironmentVariable("Path", $previousPath, "Process")
+ Pop-Location
+}
diff --git a/rmqctl/scripts/build_windows_test.go
b/rmqctl/scripts/build_windows_test.go
index 18f1d5338..cbd6ce50d 100644
--- a/rmqctl/scripts/build_windows_test.go
+++ b/rmqctl/scripts/build_windows_test.go
@@ -61,8 +61,21 @@ func TestWindowsNativeBuildIgnoresCrossCompilationTarget(t
*testing.T) {
t.Setenv("PATH",
filepath.Dir(goTool)+string(os.PathListSeparator)+os.Getenv("PATH"))
t.Setenv("GOOS", "linux")
t.Setenv("GOARCH", "arm64")
- command := exec.Command(shell, "-NoProfile", "-File",
filepath.Join(fixture, "scripts", "build-windows.ps1"),
- "-Output", filepath.Join("bin", "本机构建.exe"), "-RunTests")
+ t.Setenv("CGO_ENABLED", "1")
+ command := exec.Command(shell, "-NoProfile", "-Command", `
+$before = (Get-Location).Path
+$goos = $env:GOOS
+$goarch = $env:GOARCH
+$cgoEnabled = $env:CGO_ENABLED
+$path = $env:Path
+& $env:RMQCTL_BUILD_SCRIPT -Output 'bin\本机构建.exe' -RunTests
+if ((Get-Location).Path -ne $before) { throw 'Build changed the caller
location' }
+if ($env:GOOS -ne $goos -or $env:GOARCH -ne $goarch -or
+ $env:CGO_ENABLED -ne $cgoEnabled -or $env:Path -ne $path) {
+ throw 'Build changed the caller environment'
+}
+`)
+ command.Env = append(os.Environ(),
"RMQCTL_BUILD_SCRIPT="+filepath.Join(fixture, "scripts", "build-windows.ps1"))
if output, err := command.CombinedOutput(); err != nil {
t.Fatalf("native build failed: %v\n%s", err, output)
}