diff --git a/makelib/golang.mk b/makelib/golang.mk index a20ac3e..8d9357d 100644 --- a/makelib/golang.mk +++ b/makelib/golang.mk @@ -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 @@ -30,10 +30,6 @@ GO_SUBDIRS ?= cmd pkg # Optional. Additional subdirs used for integration or e2e testings GO_INTEGRATION_TESTS_SUBDIRS ?= -# Optional directories (relative to CURDIR) -GO_VENDOR_DIR ?= vendor -GO_PKG_DIR ?= $(WORK_DIR)/pkg - # Optional build flags passed to go tools GO_BUILDFLAGS ?= GO_LDFLAGS ?= @@ -81,21 +77,25 @@ endif GOPATH := $(shell $(GO) env GOPATH) # setup tools used during the build -DEP_VERSION=v0.5.1 -DEP := $(TOOLS_HOST_DIR)/dep-$(DEP_VERSION) GOJUNIT := $(TOOLS_HOST_DIR)/go-junit-report +GOJUNIT_VERSION ?= v2.0.0 + GOCOVER_COBERTURA := $(TOOLS_HOST_DIR)/gocover-cobertura +# https://github.com/t-yuki/gocover-cobertura/commit/aaee18c8195c3f2d90e5ef80ca918d265463842a +GOCOVER_COBERTURA_VERSION ?= aaee18c8195c3f2d90e5ef80ca918d265463842a + GOIMPORTS := $(TOOLS_HOST_DIR)/goimports +GOIMPORTS_VERSION ?= v0.1.12 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. # see https://github.com/golang/go/issues/26397 for more details -GOFMT_VERSION := 1.18 +GOFMT_VERSION := $(GO_VERSION) ifneq ($(findstring $(GOFMT_VERSION),$(GO_VERSION)),) GOFMT := $(shell which gofmt) else @@ -124,28 +124,10 @@ ifeq ($(RUNNING_IN_CI),true) GO_LINT_ARGS += --timeout 10m0s --out-format=checkstyle > $(GO_LINT_OUTPUT)/checkstyle.xml endif -# NOTE: the install suffixes are matched with the build container to speed up the -# the build. Please keep them in sync. - -ifneq ($(GO_PKG_DIR),) -GO_PKG_BASE_DIR := $(abspath $(GO_PKG_DIR)/$(PLATFORM)) -GO_PKG_STATIC_FLAGS := -pkgdir $(GO_PKG_BASE_DIR)_static -endif - -GO_COMMON_FLAGS = $(GO_BUILDFLAGS) -tags '$(GO_TAGS)' -GO_STATIC_FLAGS = $(GO_COMMON_FLAGS) $(GO_PKG_STATIC_FLAGS) -installsuffix static -ldflags '$(GO_LDFLAGS)' +GO_COMMON_FLAGS = $(GO_BUILDFLAGS) -tags '$(GO_TAGS)' -trimpath +GO_STATIC_FLAGS = $(GO_COMMON_FLAGS) -installsuffix static -ldflags '$(GO_LDFLAGS)' GO_GENERATE_FLAGS = $(GO_BUILDFLAGS) -tags 'generate $(GO_TAGS)' -export GO111MODULE - -# switch for go modules -ifeq ($(GO111MODULE),on) - -# set GOPATH to $(GO_PKG_DIR), so that the go modules are installed there, instead of the default $HOME/go/pkg/mod -export GOPATH=$(abspath $(GO_PKG_DIR)) - -endif - # ==================================================================================== # Go Targets @@ -217,61 +199,47 @@ go.fmt.simplify: $(GOFMT) go.validate: go.vet go.fmt -ifeq ($(GO111MODULE),on) +go.vendor.lite go.vendor.check: go.modules.check +go.vendor.update: go.modules.update +go.vendor: go.modules.download -go.vendor.lite go.vendor.check: - @$(INFO) verify dependencies have expected content - @$(GOHOST) mod verify || $(FAIL) - @$(OK) go modules dependencies verified +go.modules.check: go.modules.tidy.check go.modules.verify -go.vendor.update: - @$(INFO) update go modules - @$(GOHOST) get -u ./... || $(FAIL) - @$(OK) update go modules - -go.vendor: - @$(INFO) go mod vendor - @$(GOHOST) mod vendor || $(FAIL) - @$(OK) go mod vendor - -else +go.modules.download: + @$(INFO) mod download + @$(GO) mod download || $(FAIL) + @$(OK) mod download -go.vendor.lite: $(DEP) -# dep ensure blindly updates the whole vendor tree causing everything to be rebuilt. This workaround -# will only call dep ensure if the .lock file changes or if the vendor dir is non-existent. - @if [ ! -d $(GO_VENDOR_DIR) ]; then \ - $(MAKE) vendor; \ - elif ! $(DEP) ensure -no-vendor -dry-run &> /dev/null; then \ - $(MAKE) vendor; \ - fi +go.modules.verify: + @$(INFO) verify go modules dependencies have expected content + @$(GO) mod verify || $(FAIL) + @$(OK) go modules dependencies verified -go.vendor.check: $(DEP) - @$(INFO) checking if vendor deps changed - @$(DEP) check -skip-vendor || $(FAIL) - @$(OK) vendor deps have not changed +go.modules.tidy: + @$(INFO) mod tidy + @$(GO) mod tidy + @$(OK) mod tidy -go.vendor.update: $(DEP) - @$(INFO) updating vendor deps - @$(DEP) ensure -update -v || $(FAIL) - @$(OK) updating vendor deps +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.vendor: $(DEP) - @$(INFO) dep ensure - @$(DEP) ensure || $(FAIL) - @$(OK) dep ensure +go.modules.update: + @$(INFO) update go modules + @$(GO) get -u ./... || $(FAIL) + @$(MAKE) go.modules.tidy + @$(MAKE) go.modules.verify + @$(OK) update go modules -endif +go.modules.clean: + @$(GO) clean -modcache go.clean: - @# `go modules` creates read-only folders under WORK_DIR - @# make all folders within WORK_DIR writable, so they can be deleted - @if [ -d $(WORK_DIR) ]; then chmod -R +w $(WORK_DIR); fi - + @$(GO) clean -cache -testcache -modcache @rm -fr $(GO_BIN_DIR) $(GO_TEST_DIR) -go.distclean: - @rm -rf $(GO_VENDOR_DIR) $(GO_PKG_DIR) - go.generate: @$(INFO) go generate $(PLATFORM) @CGO_ENABLED=0 $(GOHOST) generate $(GO_GENERATE_FLAGS) $(GO_PACKAGES) $(GO_INTEGRATION_TEST_PACKAGES) || $(FAIL) @@ -281,7 +249,8 @@ go.generate: @$(OK) go mod tidy .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.validate go.vendor.lite go.vendor go.vendor.check go.vendor.update go.clean +.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 @@ -334,14 +303,6 @@ help-special: go.help # ==================================================================================== # Tools install targets -$(DEP): - @$(INFO) installing dep-$(DEP_VERSION) $(SAFEHOSTPLATFORM) - @mkdir -p $(TOOLS_HOST_DIR)/tmp-dep || $(FAIL) - @curl -fsSL -o $(DEP) https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-$(SAFEHOSTPLATFORM) || $(FAIL) - @chmod +x $(DEP) || $(FAIL) - @rm -fr $(TOOLS_HOST_DIR)/tmp-dep - @$(OK) installing dep-$(DEP_VERSION) $(SAFEHOSTPLATFORM) - $(GOLANGCILINT): @$(INFO) installing golangci-lint-v$(GOLANGCILINT_VERSION) $(SAFEHOSTPLATFORM) @mkdir -p $(TOOLS_HOST_DIR)/tmp-golangci-lint || $(FAIL) @@ -360,21 +321,15 @@ $(GOFMT): $(GOIMPORTS): @$(INFO) installing goimports - @mkdir -p $(TOOLS_HOST_DIR)/tmp-goimports || $(FAIL) - @GO111MODULE=off GOPATH=$(TOOLS_HOST_DIR)/tmp-goimports GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get golang.org/x/tools/cmd/goimports || rm -fr $(TOOLS_HOST_DIR)/tmp-goimports || $(FAIL) - @rm -fr $(TOOLS_HOST_DIR)/tmp-goimports + @GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION) || $(FAIL) @$(OK) installing goimports $(GOJUNIT): @$(INFO) installing go-junit-report - @mkdir -p $(TOOLS_HOST_DIR)/tmp-junit || $(FAIL) - @GO111MODULE=off GOPATH=$(TOOLS_HOST_DIR)/tmp-junit GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get github.com/jstemmer/go-junit-report || rm -fr $(TOOLS_HOST_DIR)/tmp-junit || $(FAIL) - @rm -fr $(TOOLS_HOST_DIR)/tmp-junit + @GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) install github.com/jstemmer/go-junit-report/v2@$(GOJUNIT_VERSION) || $(FAIL) @$(OK) installing go-junit-report $(GOCOVER_COBERTURA): @$(INFO) installing gocover-cobertura - @mkdir -p $(TOOLS_HOST_DIR)/tmp-gocover-cobertura || $(FAIL) - @GO111MODULE=off GOPATH=$(TOOLS_HOST_DIR)/tmp-gocover-cobertura GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) get github.com/t-yuki/gocover-cobertura || rm -fr $(TOOLS_HOST_DIR)/tmp-covcover-cobertura || $(FAIL) - @rm -fr $(TOOLS_HOST_DIR)/tmp-gocover-cobertura + @GOBIN=$(TOOLS_HOST_DIR) $(GOHOST) install github.com/t-yuki/gocover-cobertura@$(GOCOVER_COBERTURA_VERSION) || $(FAIL) @$(OK) installing gocover-cobertura diff --git a/makelib/local.mk b/makelib/local.mk index 3ec70ec..b997200 100644 --- a/makelib/local.mk +++ b/makelib/local.mk @@ -70,7 +70,7 @@ export BUILD_IMAGE_ARCHS=$(subst linux_,,$(filter linux_%,$(BUILD_PLATFORMS))) export TARGETARCH # Install gomplate -GOMPLATE_VERSION := 3.7.0 +GOMPLATE_VERSION := 3.11.1 GOMPLATE := $(TOOLS_HOST_DIR)/gomplate-$(GOMPLATE_VERSION) gomplate.buildvars: @@ -181,4 +181,4 @@ local.help: help-special: local.help -### \ No newline at end of file +### diff --git a/run b/run index 367c035..3de36fb 100755 --- a/run +++ b/run @@ -152,7 +152,6 @@ docker run \ -h ${BUILD_HOST} \ -e BUILD_REGISTRY=${BUILD_REGISTRY} \ -e GOPATH="${BUILDER_HOME}/go" \ - -e GO_PKG_DIR="" \ -e GITHUB_TOKEN \ -e VERSION \ -e CHANNEL \