-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
118 lines (93 loc) · 2.83 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
MAKEFLAGS += --warn-undefined-variables
SHELL = /bin/bash -o nounset -o errexit -o pipefail
.DEFAULT_GOAL = build
## display this help message
help:
@echo -e "\033[32m"
@echo "plan-vault-libp2p"
@echo
@awk '/^##.*$$/,/[a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}' | sort
# ----------------------------------------
# build
GOFILES = $(shell find . -type f -name '*.go')
.PHONY: build
## build the vault binary
build: bin/vault bin/test
bin/vault: $(GOFILES)
CGO_ENABLED=0 \
GOPRIVATE='github.com/libp2p/*' go build \
-trimpath \
-o bin/vault
bin/test: $(GOFILES)
CGO_ENABLED=0 \
GOPRIVATE='github.com/libp2p/*' go build \
-trimpath \
-o bin/test ./tests
# ----------------------------------------
# test
## build and run the vault binary
run: build
./bin/vault
## run unit tests
test:
go test -v -cover ./... -count=1
## run units tests and show coverage profile
cover:
go test -v -cover -coverprofile=./cover.out ./... -count=1
go tool cover -html=./cover.out
## run linting and static analysis
check:
@echo -n gofmt
@find . -type f -name '*.go' ! -name '*.pb.go' -exec gofmt -w -s {} \;
@echo ' ......... ok!'
@echo -n go vet
@go vet ./...
@echo ' ........ ok!'
@echo -n go mod tidy
@go mod tidy
@if (git status --porcelain | grep -Eq "go\.(mod|sum)"); then \
echo \
echo go.mod or go.sum needs updating; \
git --no-pager diff go.mod; \
git --no-pager diff go.sum; \
exit 1; fi
@echo ' ... ok!'
.PHONY: tests/setup
tests/setup:
./tests/setup.sh
# ----------------------------------------
# tooling
## install protobuf tools
tools:
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
## remove build artifacts
clean:
rm -rf ./bin
rm -rf ./tests/{vault1,vault2,client1,client2}
rm -rf cover.out
## remove build artifacts and all generated code
nuke: clean
rm -f protos/*.pb.go
# ----------------------------------------
# protobuffers
.PHONY: protos
## generate code from protobufs
protos: protos/vault.pb.go protos/vault_grpc.pb.go protos/internal.pb.go
protos/vault_grpc.pb.go: protos/vault.pb.go
protos/internal.pb.go: protos/vault.pb.go
protos/vault.pb.go: protos/vault.proto
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
protos/vault.proto \
protos/internal.proto
.PHONY: protosync
# TODO: this is temporary until the proto definition settles down a
# bit, at which point we can git submodule the protobufs repo and
# use a proper go_package option
## sync protobufs from the outer workspace
protosync:
sed 's~syntax = "proto3";~syntax = "proto3";\noption go_package = "github.com/plan-systems/plan-vault-libp2p/protos";~' ../plan-protobufs/pkg/vault/vault.proto > protos/vault.proto