From 4c10190b437a46623e745af1f9a7deab9181cb87 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 21 Mar 2025 15:51:27 +0000 Subject: [PATCH 1/3] fix(Makefile): fix dcspec gen dependencies and hide error output --- Makefile | 8 ++++++-- agent/agentcontainers/dcspec/gen.sh | 26 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f3801e4950c56..00a7ff7858d2f 100644 --- a/Makefile +++ b/Makefile @@ -659,8 +659,12 @@ agent/agentcontainers/acmock/acmock.go: agent/agentcontainers/containers.go go generate ./agent/agentcontainers/acmock/ touch "$@" -agent/agentcontainers/dcspec/dcspec_gen.go: agent/agentcontainers/dcspec/devContainer.base.schema.json - go generate ./agent/agentcontainers/dcspec/ +agent/agentcontainers/dcspec/dcspec_gen.go: \ + node_modules/.installed \ + agent/agentcontainers/dcspec/devContainer.base.schema.json \ + agent/agentcontainers/dcspec/gen.sh \ + agent/agentcontainers/dcspec/doc.go + DCSPEC_QUIET=true go generate ./agent/agentcontainers/dcspec/ touch "$@" $(TAILNETTEST_MOCKS): tailnet/coordinator.go tailnet/service.go diff --git a/agent/agentcontainers/dcspec/gen.sh b/agent/agentcontainers/dcspec/gen.sh index f9d3377d8170c..c74efe2efb0d5 100755 --- a/agent/agentcontainers/dcspec/gen.sh +++ b/agent/agentcontainers/dcspec/gen.sh @@ -30,14 +30,36 @@ fi TMPDIR=$(mktemp -d) trap 'rm -rfv "$TMPDIR"' EXIT -pnpm exec quicktype \ + +show_stderr=1 +exec 3>&2 +if [[ " $* " == *" --quiet "* ]] || [[ ${DCSPEC_QUIET:-false} == "true" ]]; then + # Redirect stderr to log because quicktype can't infer all types and + # we don't care right now. + show_stderr=0 + exec 2>"${TMPDIR}/stderr.log" +fi + +if ! pnpm exec quicktype \ --src-lang schema \ --lang go \ --just-types-and-package \ --top-level "DevContainer" \ --out "${TMPDIR}/${DEST_FILENAME}" \ --package "dcspec" \ - "${SCHEMA_DEST}" + "${SCHEMA_DEST}"; then + echo "quicktype failed to generate Go code." >&3 + if [[ "${show_stderr}" -eq 1 ]]; then + cat "${TMPDIR}/stderr.log" >&3 + fi + exit 1 +fi + +if [[ "${show_stderr}" -eq 0 ]]; then + # Restore stderr. + exec 2>&3 +fi +exec 3>&- # Format the generated code. go run mvdan.cc/gofumpt@v0.4.0 -w -l "${TMPDIR}/${DEST_FILENAME}" From cc0f78bbec03dce705928a1d1c5b9adc4d8eae75 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 24 Mar 2025 10:19:56 +0000 Subject: [PATCH 2/3] fix pnpm dependency when building dylib --- .github/workflows/ci.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index daa4670ea18a5..a941bce1b7491 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -988,6 +988,12 @@ jobs: set -euxo pipefail go mod download + # The "build/coder-dylib" target depends on all Go source files and + # the target "agent/agentcontainers/dcspec/dcspec_gen.go" depends on + # node/pnpm tooling. + mkdir -p node_modules + touch node_modules/.installed + make gen/mark-fresh make build/coder-dylib env: From feffa144012fe0b01de408086fa7d22babeba84c Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 24 Mar 2025 11:28:23 +0000 Subject: [PATCH 3/3] MOST_GO_SRC_FILES~ --- .github/workflows/ci.yaml | 6 ------ Makefile | 12 +++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a941bce1b7491..daa4670ea18a5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -988,12 +988,6 @@ jobs: set -euxo pipefail go mod download - # The "build/coder-dylib" target depends on all Go source files and - # the target "agent/agentcontainers/dcspec/dcspec_gen.go" depends on - # node/pnpm tooling. - mkdir -p node_modules - touch node_modules/.installed - make gen/mark-fresh make build/coder-dylib env: diff --git a/Makefile b/Makefile index 00a7ff7858d2f..e8cdcd3a3a1ba 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,16 @@ FIND_EXCLUSIONS= \ -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 \) # Source files used for make targets, evaluated on use. GO_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go' -not -name '*_test.go') +# Same as GO_SRC_FILES but excluding certain files that have problematic +# Makefile dependencies (e.g. pnpm). +MOST_GO_SRC_FILES := $(shell \ + find . \ + $(FIND_EXCLUSIONS) \ + -type f \ + -name '*.go' \ + -not -name '*_test.go' \ + -not -wholename './agent/agentcontainers/dcspec/dcspec_gen.go' \ +) # All the shell files in the repo, excluding ignored files. SHELL_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.sh') @@ -243,7 +253,7 @@ $(CODER_ALL_BINARIES): go.mod go.sum \ fi # This task builds Coder Desktop dylibs -$(CODER_DYLIBS): go.mod go.sum $(GO_SRC_FILES) +$(CODER_DYLIBS): go.mod go.sum $(MOST_GO_SRC_FILES) @if [ "$(shell uname)" = "Darwin" ]; then $(get-mode-os-arch-ext) ./scripts/build_go.sh \