Skip to content

Commit 6bf22f8

Browse files
authored
fix(Makefile): fix dcspec gen dependencies and hide error output (coder#17043)
1 parent 765e705 commit 6bf22f8

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

Makefile

+17-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ FIND_EXCLUSIONS= \
5454
-not \( \( -path '*/.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path '*/node_modules/*' -o -path '*/out/*' -o -path './coderd/apidoc/*' -o -path '*/.next/*' -o -path '*/.terraform/*' \) -prune \)
5555
# Source files used for make targets, evaluated on use.
5656
GO_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go' -not -name '*_test.go')
57+
# Same as GO_SRC_FILES but excluding certain files that have problematic
58+
# Makefile dependencies (e.g. pnpm).
59+
MOST_GO_SRC_FILES := $(shell \
60+
find . \
61+
$(FIND_EXCLUSIONS) \
62+
-type f \
63+
-name '*.go' \
64+
-not -name '*_test.go' \
65+
-not -wholename './agent/agentcontainers/dcspec/dcspec_gen.go' \
66+
)
5767
# All the shell files in the repo, excluding ignored files.
5868
SHELL_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.sh')
5969

@@ -243,7 +253,7 @@ $(CODER_ALL_BINARIES): go.mod go.sum \
243253
fi
244254

245255
# This task builds Coder Desktop dylibs
246-
$(CODER_DYLIBS): go.mod go.sum $(GO_SRC_FILES)
256+
$(CODER_DYLIBS): go.mod go.sum $(MOST_GO_SRC_FILES)
247257
@if [ "$(shell uname)" = "Darwin" ]; then
248258
$(get-mode-os-arch-ext)
249259
./scripts/build_go.sh \
@@ -659,8 +669,12 @@ agent/agentcontainers/acmock/acmock.go: agent/agentcontainers/containers.go
659669
go generate ./agent/agentcontainers/acmock/
660670
touch "$@"
661671

662-
agent/agentcontainers/dcspec/dcspec_gen.go: agent/agentcontainers/dcspec/devContainer.base.schema.json
663-
go generate ./agent/agentcontainers/dcspec/
672+
agent/agentcontainers/dcspec/dcspec_gen.go: \
673+
node_modules/.installed \
674+
agent/agentcontainers/dcspec/devContainer.base.schema.json \
675+
agent/agentcontainers/dcspec/gen.sh \
676+
agent/agentcontainers/dcspec/doc.go
677+
DCSPEC_QUIET=true go generate ./agent/agentcontainers/dcspec/
664678
touch "$@"
665679

666680
$(TAILNETTEST_MOCKS): tailnet/coordinator.go tailnet/service.go

agent/agentcontainers/dcspec/gen.sh

+24-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,36 @@ fi
3030

3131
TMPDIR=$(mktemp -d)
3232
trap 'rm -rfv "$TMPDIR"' EXIT
33-
pnpm exec quicktype \
33+
34+
show_stderr=1
35+
exec 3>&2
36+
if [[ " $* " == *" --quiet "* ]] || [[ ${DCSPEC_QUIET:-false} == "true" ]]; then
37+
# Redirect stderr to log because quicktype can't infer all types and
38+
# we don't care right now.
39+
show_stderr=0
40+
exec 2>"${TMPDIR}/stderr.log"
41+
fi
42+
43+
if ! pnpm exec quicktype \
3444
--src-lang schema \
3545
--lang go \
3646
--just-types-and-package \
3747
--top-level "DevContainer" \
3848
--out "${TMPDIR}/${DEST_FILENAME}" \
3949
--package "dcspec" \
40-
"${SCHEMA_DEST}"
50+
"${SCHEMA_DEST}"; then
51+
echo "quicktype failed to generate Go code." >&3
52+
if [[ "${show_stderr}" -eq 1 ]]; then
53+
cat "${TMPDIR}/stderr.log" >&3
54+
fi
55+
exit 1
56+
fi
57+
58+
if [[ "${show_stderr}" -eq 0 ]]; then
59+
# Restore stderr.
60+
exec 2>&3
61+
fi
62+
exec 3>&-
4163

4264
# Format the generated code.
4365
go run mvdan.cc/gofumpt@v0.4.0 -w -l "${TMPDIR}/${DEST_FILENAME}"

0 commit comments

Comments
 (0)