Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Add new go.modules targets
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Sharma <[email protected]>
  • Loading branch information
epk committed Jul 27, 2022
1 parent e0e4050 commit 8acbfc4
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions makelib/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Optional. The Go Binary to use
GO ?= go

# Optional. Minimum Go version.
# Optional. Required Go version.
GO_REQUIRED_VERSION ?= 1.18

# The go project including repo name, for example, github.com/rook/rook
Expand Down Expand Up @@ -84,7 +84,7 @@ GOIMPORTS := $(TOOLS_HOST_DIR)/goimports
GOHOST := GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) $(GO)
GO_VERSION := $(shell $(GO) version | sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p')
ifneq ($(GO_VERSION),$(GO_REQUIRED_VERSION))
$(error "$(GO) version $(GO_VERSION) is too old. required version is $(GO_REQUIRED_VERSION)")
$(error "$(GO) version $(GO_VERSION) is not supported. required version is $(GO_REQUIRED_VERSION)")
endif

# we use a consistent version of gofmt even while running different go compilers.
Expand Down Expand Up @@ -193,22 +193,45 @@ go.fmt.simplify: $(GOFMT)

go.validate: go.vet go.fmt

go.vendor.lite go.vendor.check:
@$(INFO) verify dependencies have expected content
@$(GOHOST) mod verify || $(FAIL)
go.vendor.lite go.vendor.check: go.modules.check
go.vendor.update: go.modules.update
go.vendor: go.modules.download

go.modules.check: go.modules.tidy.check go.modules.verify

go.modules.download:
@$(INFO) mod download
@$(GO) mod download || $(FAIL)
@$(OK) mod download

go.modules.verify:
@$(INFO) verify go modules dependencies have expected content
@$(GO) mod verify || $(FAIL)
@$(OK) go modules dependencies verified

go.vendor.update:
go.modules.tidy:
@$(INFO) mod tidy
@$(GO) mod tidy
@$(OK) mod tidy

go.modules.tidy.check:
@$(INFO) verify go modules dependencies are tidy
@$(GO) mod tidy
@$(shell git diff --exit-code --name-only go.mod go.sum)
@$(OK) go modules are tidy

go.modules.update:
@$(INFO) update go modules
@$(GOHOST) get -u ./... || $(FAIL)
@$(GO) get -u ./... || $(FAIL)
@$(MAKE) go.modules.tidy
@$(MAKE) go.modules.verify
@$(OK) update go modules

go.vendor:
@$(INFO) mod download
@$(GOHOST) mod download || $(FAIL)
@$(OK) mod download
go.modules.clean:
@$(GO) clean -modcache

go.clean:
@$(GO) clean -cache -testcache -modcache
@rm -fr $(GO_BIN_DIR) $(GO_TEST_DIR)

go.distclean:
Expand All @@ -224,6 +247,7 @@ go.generate:

.PHONY: go.init go.build go.install go.test.unit go.test.integration go.test.codecov go.lint go.vet go.fmt go.generate
.PHONY: go.validate go.vendor.lite go.vendor go.vendor.check go.vendor.update go.clean go.distclean
.PHONY: go.modules.check go.modules.download go.modules.verify go.modules.tidy go.modules.tidy.check go.modules.update go.modules.clean

# ====================================================================================
# Common Targets
Expand Down

0 comments on commit 8acbfc4

Please sign in to comment.