Skip to content

Commit 5592f85

Browse files
authored
chore: Find source files once in Makefile targets (#4968)
1 parent 089659f commit 5592f85

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Makefile

+13-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ else
4444
ZSTDFLAGS := -6
4545
endif
4646

47+
# Source files used for make targets, evaluated on use.
48+
GO_SRC_FILES = $(shell find . -not \( -path './.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path './site/node_modules/*' -o -path './site/out/*' \) -type f -name '*.go')
49+
# All the shell files in the repo, excluding ignored files.
50+
SHELL_SRC_FILES = $(shell find . -not \( -path './.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path './site/node_modules/*' -o -path './site/out/*' \) -type f -name '*.sh')
51+
4752
# All ${OS}_${ARCH} combos we build for. Windows binaries have the .exe suffix.
4853
OS_ARCHES := \
4954
linux_amd64 linux_arm64 linux_armv7 \
@@ -171,7 +176,7 @@ endef
171176
# You should probably use the non-version targets above instead if you're
172177
# calling this manually.
173178
$(CODER_ALL_BINARIES): go.mod go.sum \
174-
$(shell find . -not -path './vendor/*' -type f -name '*.go') \
179+
$(GO_SRC_FILES) \
175180
$(shell find ./examples/templates)
176181

177182
$(get-mode-os-arch-ext)
@@ -333,7 +338,7 @@ build/coder_helm_$(VERSION).tgz:
333338
--version "$(VERSION)" \
334339
--output "$@"
335340

336-
site/out/index.html: $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.tsx') $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.ts') site/package.json
341+
site/out/index.html: site/package.json $(shell find ./site -not -path './site/node_modules/*' -type f \( -name '*.ts' -o -name '*.tsx' \))
337342
./scripts/yarn_install.sh
338343
cd site
339344
yarn build
@@ -364,13 +369,13 @@ fmt/terraform: $(wildcard *.tf)
364369
terraform fmt -recursive
365370
.PHONY: fmt/terraform
366371

367-
fmt/shfmt: $(shell shfmt -f .)
372+
fmt/shfmt: $(SHELL_SRC_FILES)
368373
echo "--- shfmt"
369374
# Only do diff check in CI, errors on diff.
370375
ifdef CI
371-
shfmt -d $(shell shfmt -f .)
376+
shfmt -d $(SHELL_SRC_FILES)
372377
else
373-
shfmt -w $(shell shfmt -f .)
378+
shfmt -w $(SHELL_SRC_FILES)
374379
endif
375380
.PHONY: fmt/shfmt
376381

@@ -383,9 +388,9 @@ lint/go:
383388
.PHONY: lint/go
384389

385390
# Use shfmt to determine the shell files, takes editorconfig into consideration.
386-
lint/shellcheck: $(shell shfmt -f .)
391+
lint/shellcheck: $(SHELL_SRC_FILES)
387392
echo "--- shellcheck"
388-
shellcheck --external-sources $(shell shfmt -f .)
393+
shellcheck --external-sources $(SHELL_SRC_FILES)
389394
.PHONY: lint/shellcheck
390395

391396
# all gen targets should be added here and to gen/mark-fresh
@@ -446,8 +451,7 @@ site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find codersdk
446451
update-golden-files: cli/testdata/.gen-golden
447452
.PHONY: update-golden-files
448453

449-
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) \
450-
$(shell find . -not -path './vendor/*' -type f -name '*.go')
454+
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(GO_SRC_FILES)
451455

452456
go test ./cli -run=TestCommandHelp -update
453457
touch "$@"

0 commit comments

Comments
 (0)