Frun1na opened a new pull request, #6770:
URL: https://github.com/apache/rocketmq-dashboard/pull/6770
### Which Issue(s) This PR Fixes
- Fixes #6769
### Brief Description
`35506238` (#6461) pinned the host target for the Windows build script,
`rmqctl/scripts/build-windows.ps1`: "Do not inherit GOOS/GOARCH left over from
a previous cross-compilation command". The Unix entry point that script names
as its counterpart - `make build` (`rmqctl/Makefile:70-74` on this base) -
still inherits an exported cross target: it reaches the compile and the two
`license-binary.go` commands that inspect the result, so `GOOS=windows
GOARCH=amd64 make build` wrote a Windows PE to the native output path
`rmqctl/bin/rmqctl` and then died in the license gate with `license gate: exec:
"go": executable file not found in %PATH%`. `verify`, `completion` and
`install` all depend on `build` and failed with it.
The Makefile now resolves the host target once (`HOST_OS`/`HOST_ARCH`,
lazily, so only the recipes that use them run `go env`) and binds it on the
native compile and on every license command. `build-all` is untouched as the
cross-compilation entry point: its six `go build` commands keep their own
`GOOS=darwin/linux/windows` binding stack, and this change only gives its two
license commands - host programs by nature - the same host binding. No
behaviour changes for a caller that does not export a cross target: the binding
is the value those commands used anyway.
### How Did You Test This Change?
The new test drives both targets with `make -n` under an exported cross
target and fails on any command that does not carry the host binding (CI runs
it through `make test-race`):
```
$ go test -race -count=1 -run TestMakeBuildBindsHostTargetTest ./scripts
ok github.com/apache/rocketmq-dashboard/rmqctl/scripts 2.9s
```
The whole mapped check set and the project's own Go gate:
```
$ make -C rmqctl ci # gofmt, catalog-verify, go vet, go test -race,
build-all
ok github.com/apache/rocketmq-dashboard/rmqctl/cmd 1.693s
ok github.com/apache/rocketmq-dashboard/rmqctl/internal/config 1.035s
ok github.com/apache/rocketmq-dashboard/rmqctl/scripts 22.027s
...
license materials: windows/arm64, 12 actual components, 25 files
$ echo $?
0
```
The real reproduction, before and after (`rmqctl/`, Go 1.27.1, linux/amd64):
```
$ GOOS=windows GOARCH=amd64 make build # before
license gate: exec: "go": executable file not found in %PATH%
exit status 1
make: *** [Makefile:73: build] Error 1
$ file bin/rmqctl
bin/rmqctl: PE32+ executable (console) x86-64, for MS Windows, 8 sections
$ GOOS=windows GOARCH=amd64 make build # after
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "..." -o
.../bin/rmqctl main.go
GOOS=linux GOARCH=amd64 go run scripts/license-binary.go -go "go" -binary
.../bin/rmqctl -output .../bin/legal/native
license materials: linux/amd64, 11 actual components, 26 files
GOOS=linux GOARCH=amd64 go run scripts/license-binary.go -go "go" -binary
.../bin/rmqctl -output .../bin/legal/native -check
license materials: linux/amd64, 11 actual components, 26 files
$ echo $?
0
$ file bin/rmqctl
bin/rmqctl: ELF 64-bit LSB executable, x86-64, statically linked, stripped
```
The new test fails without the fix:
```
$ git stash push -- rmqctl/Makefile # keep the test, drop the binding
$ go test -race -count=1 -run TestMakeBuildBindsHostTargetTest ./scripts
--- FAIL: TestMakeBuildBindsHostTargetTest (0.30s)
--- FAIL: TestMakeBuildBindsHostTargetTest/build (0.01s)
makefile_host_target_test.go:66: make build inherits the caller's
GOOS/GOARCH instead of binding linux/amd64: CGO_ENABLED=0 go build -ldflags "-s
-w -X ..." -o .../bin/rmqctl main.go
makefile_host_target_test.go:66: make build inherits the caller's
GOOS/GOARCH instead of binding linux/amd64: go run scripts/license-binary.go
-go "go" -binary .../bin/rmqctl -output .../bin/legal/native
makefile_host_target_test.go:66: make build inherits the caller's
GOOS/GOARCH instead of binding linux/amd64: go run scripts/license-binary.go
-go "go" -binary .../bin/rmqctl -output .../bin/legal/native -check
--- FAIL: TestMakeBuildBindsHostTargetTest/build-all (0.01s)
makefile_host_target_test.go:66: make build-all inherits the
caller's GOOS/GOARCH instead of binding linux/amd64: go run
scripts/license-binary.go -go "go" -binary .../rmqctl-$os-$arch$suffix -output
.../legal/$target; \
makefile_host_target_test.go:66: make build-all inherits the
caller's GOOS/GOARCH instead of binding linux/amd64: go run
scripts/license-binary.go -go "go" -binary .../rmqctl-$os-$arch$suffix -output
.../legal/$target -check; \
FAIL
```
Each assertion names the command that would run with the caller's target;
restoring the Makefile makes it pass again.
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits (`feat:` / `fix:` /
`refactor:` / `chore:` / `docs:` / `perf:`)
- [x] Tests added or updated for non-trivial changes, test methods named
`...Test`
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks)
- [x] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed (README / `docs/` /
in-app help)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]