From 82c9d757a8e2ab284bc2d5e950772cd737140360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Weisbarth?= Date: Mon, 18 Sep 2023 10:57:09 +0200 Subject: [PATCH] Switch to order-only dependencies for `go-mod-tidy`. --- src/acceptance/assets/app/go_app/Makefile | 30 +++++++++++++++++------ src/autoscaler/Makefile | 30 ++++++++++++++++------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/acceptance/assets/app/go_app/Makefile b/src/acceptance/assets/app/go_app/Makefile index 9fcad48bc8..74ccec8c02 100644 --- a/src/acceptance/assets/app/go_app/Makefile +++ b/src/acceptance/assets/app/go_app/Makefile @@ -29,24 +29,38 @@ GOLANGCI_LINT_VERSION = v$(shell cat ../../../../../.tool-versions | grep --rege openapi-spec-path := ../../../../../api openapi-specs-list := $(wildcard ${openapi-spec-path}/*.openapi.yaml) + +# The presence of the subsequent directory indicates wheather the fakes still need to be generated +# or not. app-fakes-dir := ./internal/app/appfakes app-fakes-files := $(wildcard ${app-fakes-dir}/*.go) .PHONY: generate-fakes generate-fakes: ${app-fakes-dir} ${app-fakes-files} -${app-fakes-dir} ${app-fakes-files} &: ./internal/generate.go ${openapi-specs-list} - @echo -ne '${aes_terminal_font_yellow}' - @echo -e '⚠️ The client-fakes generated from the openapi-specification depend on\n' \ - 'the files ./go.mod and ./go.sum. This has not been reflected in this\n' \ - 'make-target to avoid cyclic dependencies because `go mod tidy`, which\n' \ - 'modifies both files, depends itself on the client-fakes.' - @echo -ne '${aes_terminal_reset}' +${app-fakes-dir} ${app-fakes-files} &: ./go.mod ./go.sum ./internal/generate.go ${openapi-specs-list} go generate ./... +# The generated fakes are order-only dependencies for `go-mod-tidy`. The reason is, that for +# `go-mod-tidy` the generated fakes need to be present but fortunately not necessarily +# up-to-date. This is fortunate because the generation of the fake requires the files `go.mod` and +# `go.sum` to be already tidied up, introducing a cyclic dependency otherwise. But that would make +# any modification to `go.mod` or `go.sum` impossible. This definition now makes it possible to +# update `go.mod` and `go.sum` as follows: +# 1. `make generate-fakes` +# 2. Update `go.mod` and/or `go.sum` +# 3. `make go-mod-tidy` +# 4. Optionally: `make generate-fakes` to update the fakes as well. +# +# For more information on order-only dependencies, see: +# .PHONY: go-mod-tidy -go-mod-tidy: ${app-fakes-dir} ${app-fakes-files} +go-mod-tidy: ./go.mod ./go.sum ${GO_DEPENDENCIES} | ${app-fakes-dir} ${app-fakes-files} + @echo -ne '${aes_terminal_font_yellow}' + @echo -e '⚠️ Warning: The client-fakes generated from the openapi-specification may be\n' \ + 'outdated. Please consider re-generating them, if this is relevant.' + @echo -ne '${aes_terminal_reset}' go mod tidy diff --git a/src/autoscaler/Makefile b/src/autoscaler/Makefile index 60cff2e904..c12357694a 100644 --- a/src/autoscaler/Makefile +++ b/src/autoscaler/Makefile @@ -25,27 +25,39 @@ export GO111MODULE=on GINKGO_OPTS=-r --race --require-suite --randomize-all --cover ${OPTS} GINKGO_VERSION=v$(shell cat ../../.tool-versions | grep ginkgo | cut -d " " -f 2 ) - +# The presence of the subsequent directory indicates wheather the fakes still need to be generated +# or not. app-fakes-dir := ./fakes app-fakes-files := $(wildcard ${app-fakes-dir}/*.go) .PHONY: generate-fakes generate-fakes: ${app-fakes-dir} ${app-fakes-files} -${app-fakes-dir} ${app-fakes-files} &: ./generate-fakes.go - @echo -ne '${aes_terminal_font_yellow}' - @echo -e '⚠️ The client-fakes generated from the openapi-specification depend on\n' \ - 'the files ./go.mod and ./go.sum. This has not been reflected in this\n' \ - 'make-target to avoid cyclic dependencies because `go mod tidy`, which\n' \ - 'modifies both files, depends itself on the client-fakes.' - @echo -ne '${aes_terminal_reset}' +${app-fakes-dir} ${app-fakes-files} &: ./go.mod ./go.sum ./generate-fakes.go @echo "# Generating counterfeits" mkdir -p '${app-fakes-dir}' COUNTERFEITER_NO_GENERATE_WARNING='true' go generate ./... +# The generated fakes are order-only dependencies for `go-mod-tidy`. The reason is, that for +# `go-mod-tidy` the generated fakes need to be present but fortunately not necessarily +# up-to-date. This is fortunate because the generation of the fake requires the files `go.mod` and +# `go.sum` to be already tidied up, introducing a cyclic dependency otherwise. But that would make +# any modification to `go.mod` or `go.sum` impossible. This definition now makes it possible to +# update `go.mod` and `go.sum` as follows: +# 1. `make generate-fakes` +# 2. Update `go.mod` and/or `go.sum` +# 3. `make go-mod-tidy` +# 4. Optionally: `make generate-fakes` to update the fakes as well. +# +# For more information on order-only dependencies, see: +# .PHONY: go-mod-tidy -go-mod-tidy: ${app-fakes-dir} ${app-fakes-files} +go-mod-tidy: ./go.mod ./go.sum ${GO_DEPENDENCIES} | ${app-fakes-dir} ${app-fakes-files} + @echo -ne '${aes_terminal_font_yellow}' + @echo -e '⚠️ Warning: The client-fakes generated from the openapi-specification may be\n' \ + 'outdated. Please consider re-generating them, if this is relevant.' + @echo -ne '${aes_terminal_reset}' go mod tidy