Skip to content

Commit 0aec996

Browse files
committed
[build] Add go mod tidy before go mod vendor for Go 1.24 compat
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 <rustiqly@users.noreply.github.com>
1 parent 61d8b07 commit 0aec996

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ $(GO_MOD):
3636
$(GO) mod init github.com/Azure/sonic-mgmt-common
3737

3838
$(GO_DEPS): $(GO_MOD) $(GO_PATCHES)
39+
@# Run go mod tidy only if installed Go >= go.mod's go directive
40+
@GO_MOD_VER=$$(sed -n 's/^go //p' go.mod) && \
41+
GO_CUR_VER=$$($(GO) env GOVERSION | sed 's/go//') && \
42+
if printf '%s\n' "$$GO_MOD_VER" "$$GO_CUR_VER" | sort -V | head -1 | grep -qx "$$GO_MOD_VER"; then \
43+
echo "Running go mod tidy (Go $$GO_CUR_VER >= go.mod $$GO_MOD_VER)"; \
44+
$(GO) mod tidy; \
45+
else \
46+
echo "Skipping go mod tidy (Go $$GO_CUR_VER < go.mod $$GO_MOD_VER)"; \
47+
fi
3948
$(GO) mod vendor
4049
patches/apply.sh vendor
4150
touch $@

0 commit comments

Comments
 (0)