-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
61 lines (51 loc) · 1.48 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
DIR=$(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
OLDGOPATH := $(GOPATH)
GOPATH := $(GOPATH)
DATE=$(shell date -u +%Y%m%d.%H%M%S.%Z)
TESTPACKETS=$(shell if [ -f .testpackages ]; then cat .testpackages; fi)
BENCHPACKETS=$(shell if [ -f .benchpackages ]; then cat .benchpackages; fi)
default: lint test
## Generate code by go generate or other utilities
generate:
.PHONY: generate
## Dependence managers
dep:
@go clean -cache -modcache
@go get -u ./...
@go mod download
@go mod tidy
@go mod vendor
.PHONY: dep
build:
@go build -o bin/db2struct github.com/webnice/d2s/db2struct
.PHONY: build
test:
@echo "mode: set" > $(DIR)/coverage.log
@for PACKET in $(TESTPACKETS); do \
touch $(DIR)/coverage-tmp.log; \
GOPATH=${GOPATH} go test -v -covermode=count -coverprofile=$(DIR)/coverage-tmp.log $$PACKET; \
if [ "$$?" -ne "0" ]; then exit $$?; fi; \
tail -n +2 $(DIR)/coverage-tmp.log | sort -r | awk '{if($$1 != last) {print $$0;last=$$1}}' >> $(DIR)/coverage.log; \
rm -f $(DIR)/coverage-tmp.log; true; \
done
.PHONY: test
cover: test
@GOPATH=${GOPATH} go tool cover -html=$(DIR)/coverage.log
.PHONY: cover
bench:
@for PACKET in $(BENCHPACKETS); do GOPATH=${GOPATH} go test -race -bench=. -benchmem $$PACKET; done
.PHONY: bench
lint:
@golangci-lint \
run \
--enable-all \
--disable nakedret \
./...
.PHONY: lint
clean:
@rm -rf ${DIR}/src; true
@rm -rf ${DIR}/bin; true
@rm -rf ${DIR}/pkg; true
@rm -rf ${DIR}/*.log; true
@rm -rf ${DIR}/*.lock; true
.PHONY: clean