1
1
# ----------------------------------------------------------------------------
2
2
# global
3
3
4
- SHELL =/usr/bin/env bash
5
- .DEFAULT_GOAL =test
4
+ .DEFAULT_GOAL := test
6
5
comma := ,
7
6
empty :=
8
7
space := $(empty ) $(empty )
@@ -14,14 +13,14 @@ ifneq ($(shell command -v go),)
14
13
GO_PATH ?= $(shell go env GOPATH)
15
14
GO_OS ?= $(shell go env GOOS)
16
15
GO_ARCH ?= $(shell go env GOARCH)
17
- TOOLS_BIN =${CURDIR}/bin
16
+ TOOLS_BIN =${CURDIR}/tools/ bin
18
17
19
18
PKG := $(subst $(GO_PATH ) /src/,,$(CURDIR ) )
20
19
GO_PKGS := $(shell go list ./... | grep -v -e '.pb.go')
21
20
GO_TEST_PKGS := $(shell go list -f='{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{end}}' ./...)
22
21
23
22
export GOTESTSUM_FORMAT =pkgname-and-test-fails
24
- GO_TEST ?= go test
23
+ GO_TEST ?= ${TOOLS_BIN}/gotestsum --
25
24
GO_TEST_FUNC ?= .
26
25
GO_TEST_FLAGS ?=
27
26
GO_BENCH_FUNC ?= .
@@ -37,35 +36,29 @@ endif
37
36
# ----------------------------------------------------------------------------
38
37
# defines
39
38
40
- GOPHER = " "
39
+ GOPHER = " "
41
40
define target
42
41
@printf "$(GOPHER ) \\x1b[1;32m$(patsubst ,$@ ,$(1 ) ) \\x1b[0m\\n"
43
42
endef
44
43
45
44
# ----------------------------------------------------------------------------
46
45
# target
47
46
48
- .PHONY : all
49
- all : mod pkg/install
50
-
51
- .PHONY : pkg/install
52
- pkg/install :
53
- $(call target)
54
- CGO_ENABLED=$(CGO_ENABLED ) GOOS=$(GO_OS ) GOARCH=$(GO_ARCH ) go install -v $(shell go list -f '{{if and (or .GoFiles .CgoFiles) (ne .Name " main" )}}{{.ImportPath}}{{end}}' ${PKG}/...)
55
-
56
47
# #@ tools
57
48
58
49
.PHONY : tools
59
- tools : # # Install tools
50
+ tools : ${TOOLS_BIN} # # Install tools
51
+
52
+ ${TOOLS_BIN} :
60
53
cd tools; \
61
- go mod vendor -v; \
62
54
for t in $$ (go list -f ' {{ join .Imports " " }}' -tags=tools); do \
63
- GOBIN=${CURDIR} /bin go install -v -x - mod=vendor " $$ {t}" > /dev/null 2>&1 ; \
55
+ GOBIN=${TOOLS_BIN} go install -v -mod=mod " $$ {t}" ; \
64
56
done
65
57
66
- # #@ test, bench and coverage
58
+ # #@ test, bench, coverage
67
59
68
60
.PHONY : test
61
+ test : ${TOOLS_BIN}
69
62
test : CGO_ENABLED=1
70
63
test : # # Runs package test including race condition.
71
64
$(call target)
@@ -81,7 +74,7 @@ bench: ## Take a package benchmark.
81
74
CGO_ENABLED=$(CGO_ENABLED ) $(GO_TEST ) -run=' ^$$' -bench=$(GO_BENCH_FUNC ) -benchmem $(strip $(GO_FLAGS ) ) $(GO_TEST_PKGS )
82
75
83
76
.PHONY : coverage
84
- coverage : GO_TEST= ${TOOLS_BIN}/gotestsum --
77
+ coverage : ${TOOLS_BIN}
85
78
coverage : CGO_ENABLED=1
86
79
coverage : # # Takes packages test coverage.
87
80
$(call target)
@@ -95,8 +88,9 @@ coverage/gojay: coverage
95
88
.PHONY : lint
96
89
lint : lint/golangci-lint # # Run all linters.
97
90
91
+
98
92
.PHONY : lint/golangci-lint
99
- lint/golangci-lint : tools .golangci.yml # # Run golangci-lint.
93
+ lint/golangci-lint : ${TOOLS_BIN} .golangci.yml # # Run golangci-lint.
100
94
$(call target)
101
95
@${TOOLS_BIN} /golangci-lint run $(strip ${GO_LINT_FLAGS}) ./...
102
96
@@ -106,24 +100,18 @@ lint/golangci-lint: tools .golangci.yml ## Run golangci-lint.
106
100
.PHONY : clean
107
101
clean : # # Cleanups binaries and extra files in the package.
108
102
$(call target)
109
- @$( RM ) $( APP ) * .out * .test * .prof trace.log
103
+ @rm -rf * .out * .test * .prof trace.log ${TOOLS_BIN}
110
104
111
105
112
106
# #@ miscellaneous
113
107
114
- .PHONY : AUTHORS
115
- AUTHORS : # # Creates AUTHORS file.
116
- @$(file >$@ ,# This file lists all individuals having contributed content to the repository.)
117
- @$(file >>$@ ,# For how it is generated, see `make AUTHORS`.)
118
- @printf " $( shell git log --format=" \n%aN <%aE>" | LC_ALL=C.UTF-8 sort -uf) " >> $@
119
-
120
108
.PHONY : todo
121
109
TODO : # # Print the all of (TODO|BUG|XXX|FIXME|NOTE) in packages.
122
- @rg -e ' (TODO|BUG|XXX|FIXME|NOTE)(\(.+\):|:)' --follow --hidden --glob= ' !.git ' --glob= ' !vendor ' --glob= ' !internal ' --glob= ' !Makefile ' --glob= ' !snippets ' --glob= ' !indent '
110
+ @grep -E ' (TODO|BUG|XXX|FIXME|NOTE)(\(.+\):|:)' $( find . -type f -name '*.go ' -and -not -iwholename '*vendor*' )
123
111
124
112
125
113
# #@ help
126
114
127
115
.PHONY : help
128
- help : # # Show make target help.
116
+ help : # # Show this help.
129
117
@awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[33m<target>\033[0m\n"} /^[a-zA-Z_0-9\/_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
0 commit comments