Skip to content

Commit cdb9bac

Browse files
committed
hack/make/go: update go.mk to latest
1 parent 756d44d commit cdb9bac

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

hack/make/go.mk

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# global
33

44
SHELL = /usr/bin/env bash
5+
56
ifneq ($(shell command -v go),)
67
GO_PATH ?= $(shell go env GOPATH)
78
GO_OS ?= $(shell go env GOOS)
@@ -11,10 +12,7 @@ PKG := $(subst $(GO_PATH)/src/,,$(CURDIR))
1112
GO_PKGS := $(shell go list ./... | grep -v -e '.pb.go')
1213
GO_APP_PKGS := $(shell go list -f '{{if and (or .GoFiles .CgoFiles) (ne .Name "main")}}{{.ImportPath}}{{end}}' ${PKG}/...)
1314
GO_TEST_PKGS := $(shell go list -f='{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{end}}' ./...)
14-
GO_VENDOR_PKGS=
15-
ifneq ($(wildcard ./vendor),)
16-
GO_VENDOR_PKGS = $(shell go list -f '{{if and (or .GoFiles .CgoFiles) (ne .Name "main")}}./vendor/{{.ImportPath}}{{end}}' ./vendor/...)
17-
endif
15+
GO_VENDOR_PKGS := $(shell go list -f '{{if and (or .GoFiles .CgoFiles) (ne .Name "main")}}./vendor/{{.ImportPath}}{{end}}' ./vendor/...)
1816

1917
GO_TEST ?= go test
2018
GO_TEST_FUNC ?= .
@@ -23,11 +21,8 @@ GO_BENCH_FUNC ?= .
2321
GO_BENCH_FLAGS ?= -benchmem
2422

2523
CGO_ENABLED ?= 0
26-
GO_LDFLAGS=-s -w $(CTIMEVAR)
27-
GO_LDFLAGS_STATIC=-s -w '-extldflags=-static' $(CTIMEVAR)
28-
ifneq ($(GO_OS),darwin)
29-
GO_LDFLAGS_STATIC+=-d
30-
endif
24+
GO_LDFLAGS=-s -w
25+
GO_LDFLAGS_STATIC=-s -w '-extldflags=-static'
3126

3227
ifneq ($(wildcard go.mod),) # exist go.mod
3328
ifeq ($(GO111MODULE),off)
@@ -52,6 +47,13 @@ endef
5247
# ----------------------------------------------------------------------------
5348
# targets
5449

50+
## build and install
51+
52+
.PHONY: pkg/install
53+
pkg/install:
54+
$(call target)
55+
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GO_OS) GOARCH=$(GO_ARCH) go install -v ${GO_APP_PKGS}
56+
5557
## test, bench and coverage
5658

5759
.PHONY: test
@@ -60,30 +62,30 @@ test: GO_BUILDTAGS+=${GO_BUILDTAGS_STATIC}
6062
test: GO_FLAGS+=-installsuffix ${GO_INSTALLSUFFIX_STATIC}
6163
test: ## Runs package test including race condition.
6264
$(call target)
63-
$(GO_TEST) -v -race $(strip $(GO_FLAGS)) -run=$(GO_TEST_FUNC) $(GO_TEST_PKGS)
65+
@GO111MODULE=on $(GO_TEST) -v -race $(strip $(GO_FLAGS)) -run=$(GO_TEST_FUNC) $(GO_TEST_PKGS)
6466

6567
.PHONY: bench
6668
bench: GO_LDFLAGS=${GO_LDFLAGS_STATIC}
6769
bench: GO_BUILDTAGS+=${GO_BUILDTAGS_STATIC}
6870
bench: GO_FLAGS+=-installsuffix ${GO_INSTALLSUFFIX_STATIC}
6971
bench: ## Take a package benchmark.
7072
$(call target)
71-
$(GO_TEST) -v $(strip $(GO_FLAGS)) -run='^$$' -bench=$(GO_BENCH_FUNC) -benchmem $(GO_TEST_PKGS)
73+
@GO111MODULE=on $(GO_TEST) -v $(strip $(GO_FLAGS)) -run='^$$' -bench=$(GO_BENCH_FUNC) -benchmem $(GO_TEST_PKGS)
7274

7375
.PHONY: bench/race
7476
bench/race: ## Takes packages benchmarks with the race condition.
7577
$(call target)
76-
$(GO_TEST) -v -race $(strip $(GO_FLAGS)) -run='^$$' -bench=$(GO_BENCH_FUNC) -benchmem $(GO_TEST_PKGS)
78+
@GO111MODULE=on $(GO_TEST) -v -race $(strip $(GO_FLAGS)) -run='^$$' -bench=$(GO_BENCH_FUNC) -benchmem $(GO_TEST_PKGS)
7779

7880
.PHONY: bench/trace
7981
bench/trace: ## Take a package benchmark with take a trace profiling.
8082
$(GO_TEST) -v -c -o bench-trace.test $(PKG)/stackdriver
81-
GODEBUG=allocfreetrace=1 ./bench-trace.test -test.run=none -test.bench=$(GO_BENCH_FUNC) -test.benchmem -test.benchtime=10ms 2> trace.log
83+
GO111MODULE=on GODEBUG=allocfreetrace=1 ./bench-trace.test -test.run=none -test.bench=$(GO_BENCH_FUNC) -test.benchmem -test.benchtime=10ms 2> trace.log
8284

8385
.PHONY: coverage
8486
coverage: ## Takes packages test coverage.
8587
$(call target)
86-
$(GO_TEST) -v -race $(strip $(GO_FLAGS)) -covermode=atomic -coverpkg=$(PKG)/... -coverprofile=coverage.out $(GO_PKGS)
88+
GO111MODULE=on $(GO_TEST) -v -race $(strip $(GO_FLAGS)) -covermode=atomic -coverpkg=$(PKG)/... -coverprofile=coverage.out $(GO_PKGS)
8789

8890
$(GO_PATH)/bin/go-junit-report:
8991
@GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
@@ -99,23 +101,23 @@ coverage/ci: cmd/go-junit-report
99101
coverage/ci: ## Takes packages test coverage, and output coverage results to CI artifacts.
100102
$(call target)
101103
@mkdir -p /tmp/ci/artifacts /tmp/ci/test-results
102-
$(GO_TEST) -v -race $(strip $(GO_FLAGS)) -covermode=atomic -coverpkg=$(PKG)/pkg/... -coverprofile=/tmp/ci/artifacts/coverage.out $(GO_PKGS) 2>&1 | tee /dev/stderr | go-junit-report -set-exit-code > /tmp/ci/test-results/junit.xml
104+
GO111MODULE=on $(GO_TEST) -a -v -race $(strip $(GO_FLAGS)) -covermode=atomic -coverpkg=$(PKG)/... -coverprofile=/tmp/ci/artifacts/coverage.out $(GO_PKGS) 2>&1 | tee /dev/stderr | go-junit-report -set-exit-code > /tmp/ci/test-results/junit.xml
103105
@if [[ -f '/tmp/ci/artifacts/coverage.out' ]]; then go tool cover -html=/tmp/ci/artifacts/coverage.out -o /tmp/ci/artifacts/coverage.html; fi
104106

105107

106108
## lint
107109

108110
.PHONY: lint
109-
lint: lint/golangci-lint ## Runs the all linters.
111+
lint: lint/golangci-lint ## Run all linters.
110112

111113
$(GO_PATH)/bin/golangci-lint:
112-
GO111MODULE=off go get -u -v github.com/golangci/golangci-lint/cmd/golangci-lint
114+
@GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
113115

114116
.PHONY: cmd/golangci-lint
115-
cmd/golangci-lint: $(GO_PATH)/bin/golangci-lint # go get 'golangci-lint' binary.
117+
cmd/golangci-lint: $(GO_PATH)/bin/golangci-lint # go get 'golangci-lint' binary
116118

117119
.PHONY: golangci-lint
118-
lint/golangci-lint: cmd/golangci-lint .golangci.yml ## Runs the `golangci-lint` linter.
120+
lint/golangci-lint: cmd/golangci-lint .golangci.yml ## Run golangci-lint.
119121
$(call target)
120122
@GO111MODULE=on golangci-lint run ./...
121123

@@ -191,7 +193,7 @@ boilerplate/go/%: BOILERPLATE_PKG_DIR=$(shell printf $@ | cut -d'/' -f3- | rev |
191193
boilerplate/go/%: BOILERPLATE_PKG_NAME=$(if $(findstring main,$@),main,$(shell printf $@ | rev | cut -d/ -f2 | rev))
192194
boilerplate/go/%: hack/boilerplate/boilerplate.go.txt
193195
boilerplate/go/%: ## Creates a go file based on boilerplate.go.txt in % location.
194-
@if [ ! ${BOILERPLATE_PKG_DIR:-3} == ".go" ] && [ ! -d ${BOILERPLATE_PKG_DIR} ]; then mkdir -p ${BOILERPLATE_PKG_DIR}; fi
196+
@if [[ ! ${BOILERPLATE_PKG_DIR} == *'.go'* ]] && [ ! -d ${BOILERPLATE_PKG_DIR} ]; then mkdir -p ${BOILERPLATE_PKG_DIR}; fi
195197
@cat hack/boilerplate/boilerplate.go.txt <(printf "package ${BOILERPLATE_PKG_NAME}\\n") > $*
196198
@sed -i "s|YEAR|$(shell date '+%Y')|g" $*
197199

0 commit comments

Comments
 (0)