-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
128 lines (103 loc) · 3.76 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Allow setting different go version from the command line. E.g.,`make GO=go1.19.4 binary`
GO ?= go
TIMEOUT = 20m
DOCKER = docker
DOCKER_IMAGE = orionbcdb/orion-server
DOCKERFILE = images/Dockerfile
PROTO_COMPILER_IMAGE = orionbcdb/protobuf
PROTO_COMPILER_DOCKERFILE = images/Proto
PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...))
TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
$(PKGS))
COVERAGE_MODE = atomic
COVERAGE_PROFILE = $(COVERAGE_DIR)/profile.out
COVERAGE_XML = $(COVERAGE_DIR)/coverage.xml
COVERAGE_HTML = $(COVERAGE_DIR)/index.html
BIN = $(CURDIR)/bin
$(BIN):
@mkdir -p $@
$(BIN)/%: | $(BIN)
@tmp=$$(mktemp -d); \
env GO11MODULE=off GOPATH=$$tmpp GOBIN=$(BIN) $(GO) get $(PACKAGE) \
|| ret=$$?;
rm -rf $$tmp ; exit $$ret
$(BIN)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint
GOLINT = $(BIN)/golangci-lint
lint: | $(GOLINT)
$(GOLINT) run
GOCOV = $(BIN)/gocov
$(BIN)/gocov: PACKAGE=github.com/axw/gocov/...
GOCOVXML = $(BIN)/gocov-xml
$(BIN)/gocov-xml: PACKAGE=github.com/AlekSi/gocov-xml
GO2XUNIT = $(BIN)/go2xunit
$(BIN)/go2xunit: PACKAGE=github.com/tebeka/go2xunit
.PHONY: fmt
fmt:
$(GO) fmt $(PKGS)
.PHONY: goimports
goimports:
find . -name \*.go -not -path "./pkg/types/*" -exec goimports -w -l {} \;
.PHONY: binary
binary:
$(GO) build -o $(BIN)/bdb cmd/bdb/main.go
$(GO) build -o $(BIN)/signer cmd/signer/signer.go
$(GO) build -o $(BIN)/encoder cmd/base64_encoder/encoder.go
$(GO) build -o $(BIN)/decoder cmd/base64_decoder/decoder.go
.PHONY: test
test-script:
scripts/run-unit-tests.sh
.PHONY: clean
clean:
@rm -rf $(BIN)
@rm -rf test/tests.* test/coverage.*
.PHONY: docker-clean
docker-clean:
$(DOCKER) rmi $(DOCKER_IMAGE)
.PHONY: protos
protos:
$(DOCKER) build -t $(PROTO_COMPILER_IMAGE) --no-cache -f $(PROTO_COMPILER_DOCKERFILE) .
docker run -it -v `pwd`:`pwd` -w `pwd` $(PROTO_COMPILER_IMAGE) scripts/compile_go_protos.sh
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
test-bench: ARGS=-run=__absolutelynothing__ -bench=.
test-short: ARGS=-short
test-verbose: ARGS=-v
test-race: ARGS=-race
$(TEST_TARGETS): test
check test tests:
$(GO) build -o $(BIN)/bdb cmd/bdb/main.go
$(GO) test -timeout $(TIMEOUT) $(ARGS) $(TESTPKGS)
test-coverage-tools: | $(GOCOVMERGE) $(GOCOV) $(GOCOVXML)
test-coverage: COVERAGE_DIR := $(CURDIR)/test/coverage.$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
test-coverage: test-coverage-tools
$(GO) build -o $(BIN)/bdb cmd/bdb/main.go
mkdir -p $(COVERAGE_DIR)/coverage
$(GO) test \
-coverpkg=$$($(GO) list -f '{{ join .Deps "\n" }}' $(TESTPKGS) | \
grep '^$(MODULE)/' | \
tr '\n' ',' | sed 's/,$$//') \
-covermode=$(COVERAGE_MODE) \
-coverprofile="$(COVERAGE_PROFILE)" $(TESTPKGS)
$(GO) tool cover -html=$(COVERAGE_PROFILE) -o $(COVERAGE_HTML)
$(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML)
.PHONY: docker
docker:
$(DOCKER) build -t $(DOCKER_IMAGE) --no-cache -f $(DOCKERFILE) .
.PHONY: docker-multiarch
docker-multiarch:
make docker-linux-amd64
make docker-linux-arm64
make docker-linux-arm-v7
make docker-linux-s390x
.PHONY: docker-linux-amd64
docker-linux-amd64:
$(DOCKER) buildx build --platform linux/amd64 -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-amd64 --load .
.PHONY: docker-linux-arm64
docker-linux-arm64:
$(DOCKER) buildx build --platform linux/arm64 -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-arm64 --load .
.PHONY: docker-linux-arm-v7
docker-linux-arm-v7:
$(DOCKER) buildx build --platform linux/arm/v7 -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-arm-v7 --load .
.PHONY: docker-linux-s390x
docker-linux-s390x:
$(DOCKER) buildx build --platform linux/s390x -f $(DOCKERFILE) -t $(DOCKER_IMAGE):linux-s390x --load .