forked from temporalio/api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (80 loc) · 3.98 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
$(VERBOSE).SILENT:
############################# Main targets #############################
# Install everything, update submodule, and compile proto files.
install: grpc-install mockgen-install goimports-install update-proto
# Compile proto files.
proto: grpc grpc-mock goimports copyright
# Update submodule and compile proto files.
update-proto: update-proto-submodule proto update-dependencies gomodtidy
hack:
find . -type f -name '*.pb.go' -exec sed -i -E 's/go.temporal.io\/api\/dependencies\/gogoproto/github.com\/gogo\/protobuf\/gogoproto/g' {} \;
find . -type f -name '*.pb.go' -exec go fmt {} \;
########################################################################
##### Variables ######
ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
GOBIN := $(if $(shell go env GOBIN),$(shell go env GOBIN),$(GOPATH)/bin)
export PATH := $(GOBIN):$(PATH)
COLOR := "\e[1;36m%s\e[0m\n"
PROTO_ROOT := proto/api
PROTO_FILES = $(shell find $(PROTO_ROOT) -name "*.proto")
PROTO_DIRS = $(sort $(dir $(PROTO_FILES)))
PROTO_OUT := .
PROTO_IMPORT := $(PROTO_ROOT):$(GOPATH)/src/github.com/temporalio/gogo-protobuf/protobuf
$(PROTO_OUT):
mkdir $(PROTO_OUT)
##### git submodule for proto files #####
update-proto-submodule:
printf $(COLOR) "Update proto-submodule..."
git submodule update --init --force --remote $(PROTO_ROOT)
##### Compile proto files for go #####
grpc: gogo-grpc fix-path
go-grpc: clean $(PROTO_OUT)
printf $(COLOR) "Compiling for go-gRPC..."
$(foreach PROTO_DIR,$(PROTO_DIRS),protoc --proto_path=$(PROTO_IMPORT) --go_out=plugins=grpc,paths=source_relative:$(PROTO_OUT) $(PROTO_DIR)*.proto;)
gogo-grpc: clean $(PROTO_OUT)
printf $(COLOR) "Compiling for gogo-gRPC..."
$(foreach PROTO_DIR,$(PROTO_DIRS),protoc --proto_path=$(PROTO_IMPORT) --gogoslick_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) $(PROTO_DIR)*.proto;)
fix-path:
mv -f $(PROTO_OUT)/temporal/api/* $(PROTO_OUT) && rm -rf $(PROTO_OUT)/temporal
# All generated service files pathes relative to PROTO_OUT.
PROTO_GRPC_SERVICES = $(patsubst $(PROTO_OUT)/%,%,$(shell find $(PROTO_OUT) -name "service.pb.go"))
service_name = $(firstword $(subst /, ,$(1)))
mock_file_name = $(call service_name,$(1))mock/$(subst $(call service_name,$(1))/,,$(1:go=mock.go))
grpc-mock:
printf $(COLOR) "Generate gRPC mocks..."
$(foreach PROTO_GRPC_SERVICE,$(PROTO_GRPC_SERVICES),cd $(PROTO_OUT) && mockgen -package $(call service_name,$(PROTO_GRPC_SERVICE))mock -source $(PROTO_GRPC_SERVICE) -destination $(call mock_file_name,$(PROTO_GRPC_SERVICE))$(NEWLINE) )
goimports:
@printf $(COLOR) "Run goimports..."
@goimports -w $(PROTO_OUT)
##### Plugins & tools #####
grpc-install: gogo-protobuf-install
printf $(COLOR) "Install/update gRPC plugins..."
GO111MODULE=off go get -u google.golang.org/grpc
gogo-protobuf-install: go-protobuf-install
GO111MODULE=off go get -u github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
go-protobuf-install:
GO111MODULE=off go get -u github.com/golang/protobuf/protoc-gen-go
mockgen-install:
printf $(COLOR) "Install/update mockgen..."
GO111MODULE=off go get -u github.com/golang/mock/mockgen
goimports-install:
printf $(COLOR) "Install/update goimports..."
GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports
##### License header #####
copyright:
printf $(COLOR) "Update license headers..."
go run ./cmd/copyright/licensegen.go
##### go.mod #####
update-dependencies:
printf $(COLOR) "Update go dependencies..."
go get -u -t ./...
gomodtidy:
printf $(COLOR) "go mod tidy..."
go mod tidy
##### Clean #####
clean:
printf $(COLOR) "Deleting generated go files..."
# Delete all directories with *.pb.go and *.mock.go files from $(PROTO_OUT)
find $(PROTO_OUT) \( -name "*.pb.go" -o -name "*.mock.go" \) | xargs dirname | sort -u | xargs rm -rf