-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (82 loc) · 3.22 KB
/
Makefile
File metadata and controls
102 lines (82 loc) · 3.22 KB
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
PGG := bin/protoc-gen-go
FFJ := bin/ffjson
PGIT := bin/protoc-go-inject-tag
PGGG := bin/protoc-gen-grpc-gateway
PKGS := $(shell go list ./... | grep -v vendor | grep -v rpc)
VERSION := $(shell git describe --tags 2> /dev/null || echo "unreleased")
V_DIRTY := $(shell git describe --exact-match HEAD 2> /dev/null > /dev/null || echo "-unreleased")
GIT := $(shell git rev-parse --short HEAD)
DIRTY := $(shell git diff-index --quiet HEAD 2> /dev/null > /dev/null || echo "-dirty")
GOFILES := $(shell find . -type f | grep go$$ ) rpc/qproxy.pb_ffjson.go rpc/qproxy.pb_jsonpb.go
default: build/qproxy.linux
build/qproxy.linux: ${GOFILES}
@echo "$@"
@GOOS=linux GOARCH=$(TARGETARCH) CGO_ENABLED=0 go build -o build/qproxy.linux -ldflags\
"-X github.com/wish/qproxy.Version=$(VERSION)$(V_DIRTY) \
-X github.com/wish/qproxy.Git=$(GIT)$(DIRTY)" \
github.com/wish/qproxy/cmd/qproxy
build/qproxy.darwin: ${GOFILES}
@echo "$@"
@GOOS=darwin CGO_ENABLED=0 go build -o build/qproxy.darwin -ldflags\
"-X github.com/wish/qproxy.Version=$(VERSION)$(V_DIRTY) \
-X github.com/wish/qproxy.Git=$(GIT)$(DIRTY)" \
github.com/wish/qproxy/cmd/qproxy
# all .go files are deps, so these are fine specified as such:
rpc/qproxy.pb.go: ${PGG} ${PGIT} rpc/qproxy.proto
@echo "protoc $@"
@protoc --plugin=${PGG} \
-I /usr/local/include -I.\
-I third_party/googleapis \
-I rpc/ rpc/qproxy.proto \
--go_out=plugins=grpc:.
@sed s/,omitempty// $@ > $@.tmp
@mv $@.tmp $@
@${PGIT} -input=$@ 2> /dev/null
rpc/qproxy.pb.gw.go: ${PGGG} rpc/qproxy.proto
@echo "protoc $@"
@protoc -I /usr/local/include -I. \
-I third_party/googleapis \
--plugin=$(PGGG) \
--grpc-gateway_out=logtostderr=true:. rpc/qproxy.proto
rpc/qproxy.pb_ffjson.go: ${FFJ} rpc/qproxy.pb.go rpc/qproxy.pb.gw.go
@rm -f rpc/qproxy.pb_jsonpb.go
bin/ffjson rpc/qproxy.pb.go
rpc/qproxy.pb_jsonpb.go: rpc/qproxy.pb_ffjson.go
@cp rpc/qproxy.pb_jsonpb.go.stub rpc/qproxy.pb_jsonpb.go
.PHONY: coverage
coverage:
@go test -coverprofile=/tmp/cover github.com/wish/qproxy
@go tool cover -html=/tmp/cover -o coverage.html
@rm /tmp/cover
# the reason we introduce test and vtest is to have a way to view the results
# of failing tests, but being silient in the successful case (silence is golden
# principle)
.PHONY: test
test: default
@echo "running unittests"
@go test -cover ${PKGS} > /dev/null
.PHONY: vtest
vtest: default
@go test -cover -v ${PKGS}
.PHONY: clean
clean:
rm -rf build
rm -f rpc/qproxy.pb.go rpc/qproxy.pb.gw.go rpc/qproxy.pb_ffjson.go rpc/qproxy.pb_jsonpb.go
rm -f bin/ffjson bin/protoc-gen-go bin/protoc-gen-grpc-gateway bin/protoc-go-inject-tag
.PHONY: release
release: default test build/checksums.256
build/checksums.256: build/qproxy.linux build/qproxy.darwin
@rm -f build/checksums.256
@cd build && shasum -a 256 * > checksums.256
$(PGG):
@echo "$@"
@GOBIN=$(CURDIR)/bin go get github.com/golang/protobuf/protoc-gen-go@v1.2.0
$(FFJ):
@echo "$@"
@GOBIN=$(CURDIR)/bin go get github.com/pquerna/ffjson@v0.0.0-20181028064349-e517b90714f7
$(PGIT):
@echo "$@"
@GOBIN=$(CURDIR)/bin go get github.com/favadi/protoc-go-inject-tag@v1.3.0
$(PGGG):
@echo "$@"
@GOBIN=$(CURDIR)/bin go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.16.0