mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
fix(build): follow GOBIN-then-GOPATH/bin for plugin PATH prefix
Reviewer (Codex) on PR #3371: the previous patch hardcoded \$HOME/go/bin, which is only the default fallback when GOBIN is unset AND GOPATH defaults to \$HOME/go. On machines with a custom GOBIN or a non-default GOPATH, `go install` targets a different directory — so hardcoding \$HOME/go/bin can force a stale binary from there to win over the freshly-installed SEBUF_VERSION sitting at the actual install location. Fix: resolve the install dir the same way `go install` does: GOBIN first, then GOPATH/bin. Shell expression: `go env GOBIN` returns an empty string (exit 0) when unset, so `||` alone doesn't cascade. Using explicit `[ -n "$gobin" ]` instead. Also dropped the misleading comment that claimed the pre-push hook used the same rule — it still hardcodes \$HOME/go/bin. Called that out in a note, but left the hook alone because its PATH prepend is belt-and-suspenders (only matters for locating `buf` itself; the Makefile's own recipe-level prepend decides plugin resolution). Verified on a machine with empty GOBIN: resolved → /Users/eliehabib/go/bin And \`make generate\` succeeds without manual PATH overrides.
This commit is contained in:
15
Makefile
15
Makefile
@@ -54,14 +54,21 @@ lint: ## Lint protobuf files
|
||||
|
||||
generate: clean ## Generate code from proto definitions
|
||||
@mkdir -p $(GEN_CLIENT_DIR) $(GEN_SERVER_DIR) $(DOCS_API_DIR)
|
||||
# Prepend $$HOME/go/bin so the Makefile-declared sebuf version
|
||||
# Prepend the Go install dir so the Makefile-declared sebuf version
|
||||
# ($(SEBUF_VERSION)) installed by `install-plugins` wins over any
|
||||
# stale sebuf binary that a package manager (Homebrew, etc.) may
|
||||
# have placed earlier on PATH. Without this, `buf generate` can
|
||||
# pick up an older sebuf v0.7.x build that ignores `bundle_only=true`
|
||||
# / `format=json` and produces duplicate-output errors. This matches
|
||||
# what .husky/pre-push already does before invoking this target.
|
||||
cd $(PROTO_DIR) && PATH="$$HOME/go/bin:$$PATH" buf generate
|
||||
# / `format=json` and produces duplicate-output errors.
|
||||
#
|
||||
# Mirror `go install`'s own resolution order: GOBIN first, then
|
||||
# GOPATH/bin. This respects developers who set a non-default GOBIN
|
||||
# (e.g. to keep binaries out of ~/go/bin) — hardcoding $$HOME/go/bin
|
||||
# would force a stale ~/go/bin copy to win on those machines.
|
||||
# (Note: .husky/pre-push:151-153 still hardcodes $$HOME/go/bin for
|
||||
# discovering `buf` itself. That's additive — the Makefile's own
|
||||
# recipe-level prepend here takes precedence for the plugin lookup.)
|
||||
cd $(PROTO_DIR) && PATH="$$(gobin=$$(go env GOBIN); [ -n "$$gobin" ] && printf '%s' "$$gobin" || printf '%s/bin' "$$(go env GOPATH)"):$$PATH" buf generate
|
||||
@echo "Code generation complete!"
|
||||
|
||||
breaking: ## Check for breaking changes against main
|
||||
|
||||
Reference in New Issue
Block a user