-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathMakefile
101 lines (75 loc) · 2.78 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
PROJECT=unistore
GOPATH ?= $(shell go env GOPATH)
# Ensure GOPATH is set before running build process.
ifeq "$(GOPATH)" ""
$(error Please set the environment variable GOPATH before running `make`)
endif
FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'
GO := GO111MODULE=on go
GOBUILD := $(GO) build $(BUILD_FLAG) -tags codes
GOTEST := $(GO) test -p 8
STATICCHECK := GO111MODULE=on staticcheck
LDFLAGS += -X "main.gitHash=`git rev-parse HEAD`"
TEST_LDFLAGS := ""
PACKAGE_LIST := go list ./...| grep -vE "cmd"
PACKAGES := $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/ngaut/$(PROJECT)/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
# Targets
.PHONY: build linux test go-build go-build-linux go-test check
default: build
test: go-test
go-test:
@echo "Running tests in native mode."
@export TZ='Asia/Shanghai'; \
$(GOTEST) -race -cover $(PACKAGES)
go-build:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/unistore-server cmd/unistore-server/main.go
go-build-linux:
GOOS=linux $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/unistore-server-linux cmd/unistore-server/main.go
build: go-build
linux: go-build-linux
check: fmt errcheck unconvert lint tidy check-static vet staticcheck
fmt:
@echo "gofmt (simplify)"
@gofmt -s -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT)
errcheck:tools/bin/errcheck
@echo "errcheck"
@GO111MODULE=on tools/bin/errcheck -exclude ./tools/check/errcheck_excludes.txt -ignoretests -blank $(PACKAGES)
unconvert:tools/bin/unconvert
@echo "unconvert check"
@GO111MODULE=on tools/bin/unconvert ./...
lint:tools/bin/revive
@echo "linting"
@tools/bin/revive -formatter friendly -config tools/check/revive.toml $(FILES)
tidy:
@echo "go mod tidy"
./tools/check/check-tidy.sh
check-static: tools/bin/golangci-lint
@echo "golangci-lint"
./tools/bin/golangci-lint run -v --disable-all --deadline=3m \
--enable=misspell \
--enable=ineffassign \
--enable=typecheck \
--enable=varcheck \
--enable=structcheck \
--enable=deadcode \
$$($(PACKAGE_DIRECTORIES))
vet:
@echo "vet"
$(GO) vet -all $(PACKAGES) 2>&1 | $(FAIL_ON_STDOUT)
staticcheck:
@echo "staticcheck"
$(GO) get honnef.co/go/tools/cmd/staticcheck
$(STATICCHECK) ./...
tools/bin/errcheck: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/errcheck github.com/kisielk/errcheck
tools/bin/unconvert: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/unconvert github.com/mdempsky/unconvert
tools/bin/revive: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/revive github.com/mgechev/revive
tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.29.0