Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0080bcb

Browse files
fix(Makefile): rebuild clidocgen when Go sources or template change (#24302)
The `_gen/bin/clidocgen` binary only declared `scripts/clidocgen/*.go` as prerequisites. Since it reflects over the full CLI tree (227 transitive internal packages via `enterprise/cli` → `cli/` → `codersdk/` → …), any change to CLI flags, SDK structs, or command definitions could alter its output — but Make would keep serving the stale binary until it was manually deleted (or `-B` was passed). This caused a recurring developer-facing bug: after merging main (or rebasing onto new CLI/SDK changes), the pre-commit hook would use the stale binary, commit wrong docs, `make gen` would see no diff (same stale binary), and CI would fail because it builds fresh. Add `$(GO_SRC_FILES)` and the embedded `command.tpl` to the prerequisite list so Make invalidates the binary whenever its inputs change. Move `FIND_EXCLUSIONS` and `GO_SRC_FILES` above the helper-binary block so the variable is defined before first use.
1 parent 95fd3e5 commit 0080bcb

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ define atomic_write
9191
mv "$$tmpfile" "$@" && rm -rf "$$tmpdir"
9292
endef
9393

94+
# CLI doc generation reflects over the assembled CLI tree. Track command
95+
# definitions plus the top-level SDK types they expose in help text and flag
96+
# values, without pulling in unrelated generated sources.
97+
CLIDOC_SRC_FILES := \
98+
$(shell find ./cli ./enterprise/cli -type f -name '*.go' -not -name '*_test.go') \
99+
$(wildcard codersdk/*.go) \
100+
$(wildcard buildinfo/*.go)
101+
102+
CLIDOCGEN_INPUTS := \
103+
$(wildcard scripts/clidocgen/*.go) \
104+
scripts/clidocgen/command.tpl \
105+
$(CLIDOC_SRC_FILES)
106+
94107
# Helper binary targets. Built with go build -o to avoid caching
95108
# link-stage executables in GOCACHE. Each binary is a real Make
96109
# target so parallel -j builds serialize correctly instead of
@@ -108,7 +121,9 @@ _gen/bin/check-scopes: $(wildcard scripts/check-scopes/*.go) | _gen
108121
@mkdir -p _gen/bin
109122
go build -o $@ ./scripts/check-scopes
110123

111-
_gen/bin/clidocgen: $(wildcard scripts/clidocgen/*.go) | _gen
124+
# clidocgen reflects over the full CLI tree, so it must rebuild when its
125+
# command definitions, flag types, or embedded template change.
126+
_gen/bin/clidocgen: $(CLIDOCGEN_INPUTS) | _gen
112127
@mkdir -p _gen/bin
113128
go build -o $@ ./scripts/clidocgen
114129

@@ -1190,7 +1205,7 @@ docs/admin/integrations/prometheus.md: node_modules/.installed scripts/metricsdo
11901205
pnpm exec markdown-table-formatter "$$tmpfile" && \
11911206
mv "$$tmpfile" "$@" && rm -rf "$$tmpdir"
11921207

1193-
docs/reference/cli/index.md: node_modules/.installed scripts/clidocgen/main.go examples/examples.gen.json $(GO_SRC_FILES) | _gen _gen/bin/clidocgen
1208+
docs/reference/cli/index.md: node_modules/.installed examples/examples.gen.json _gen/bin/clidocgen | _gen
11941209
tmpdir=$$(mktemp -d -p _gen) && \
11951210
tmpdir=$$(realpath "$$tmpdir") && \
11961211
mkdir -p "$$tmpdir/docs/reference/cli" && \

0 commit comments

Comments
 (0)