From 0aec9966a16060fa7982136868d1f7bd23bd2869 Mon Sep 17 00:00:00 2001 From: Rustiqly Date: Sat, 7 Mar 2026 16:18:46 -0800 Subject: [PATCH] [build] Add go mod tidy before go mod vendor for Go 1.24 compat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Go 1.24 (shipped in Debian Trixie) is stricter about module graph consistency. Running `go mod vendor` without `go mod tidy` first fails with module resolution errors when the go.mod was written for an older Go version. Add `go mod tidy` before `go mod vendor`. This is backward compatible — on Go 1.21 (bookworm) it is a no-op. Signed-off-by: Rustiqly --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 253369fb3..c7fe75f67 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,15 @@ $(GO_MOD): $(GO) mod init github.com/Azure/sonic-mgmt-common $(GO_DEPS): $(GO_MOD) $(GO_PATCHES) + @# Run go mod tidy only if installed Go >= go.mod's go directive + @GO_MOD_VER=$$(sed -n 's/^go //p' go.mod) && \ + GO_CUR_VER=$$($(GO) env GOVERSION | sed 's/go//') && \ + if printf '%s\n' "$$GO_MOD_VER" "$$GO_CUR_VER" | sort -V | head -1 | grep -qx "$$GO_MOD_VER"; then \ + echo "Running go mod tidy (Go $$GO_CUR_VER >= go.mod $$GO_MOD_VER)"; \ + $(GO) mod tidy; \ + else \ + echo "Skipping go mod tidy (Go $$GO_CUR_VER < go.mod $$GO_MOD_VER)"; \ + fi $(GO) mod vendor patches/apply.sh vendor touch $@