@@ -7,11 +7,10 @@ ifndef GOPATH
77GOPATH := $(shell go env GOPATH)
88endif
99
10- PROTO_ROOT := temporal-proto
1110COLOR := "\e[1;36m%s\e[0m\n"
12- # List only subdirectories with *.proto files. Sort to remove duplicates.
13- PROTO_DIRS = $( sort $( dir $( wildcard $( PROTO_ROOT ) / * / * / * . proto) ) )
14- PROTO_SERVICES = $(wildcard $(PROTO_ROOT ) / * / * /service .proto)
11+
12+ PROTO_ROOT := temporal- proto
13+ PROTO_DIRS = $(shell find $(PROTO_ROOT ) -name " * .proto" -printf " % h\n" | sort -u )
1514PROTO_OUT := .
1615PROTO_IMPORT := $(PROTO_ROOT ) :$(GOPATH ) /src/github.com/temporalio/gogo-protobuf/protobuf
1716
@@ -32,15 +31,15 @@ update-proto-submodule:
3231
3332# Compile proto files to go
3433
35- grpc : gogo-grpc
34+ grpc : gogo-grpc fix-path
3635
3736gogo-grpc : clean $(PROTO_OUT )
3837 printf $(COLOR ) " Compiling for gogo-gRPC..."
39- $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --proto_path=$(PROTO_IMPORT ) --gogoslick_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) * .proto;)
38+ $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --proto_path=$(PROTO_IMPORT ) --gogoslick_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) / * .proto;)
4039
4140gogo-protobuf : clean $(PROTO_OUT )
4241 printf $(COLOR ) " Compiling for gogo-protobuf..."
43- $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --proto_path=$(PROTO_IMPORT ) --gogofaster_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) * .proto;)
42+ $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --proto_path=$(PROTO_IMPORT ) --gogofaster_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) / * .proto;)
4443
4544go-protobuf : clean $(PROTO_OUT )
4645 printf $(COLOR ) " Compiling for go-protobuf..."
@@ -50,16 +49,19 @@ go-grpc: clean $(PROTO_OUT)
5049 printf $(COLOR ) " Compiling for go-gRPC..."
5150 $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --proto_path=$(PROTO_IMPORT ) --go_out=plugins=grpc,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) * .proto;)
5251
52+ fix-path :
53+ mv -f $(PROTO_OUT ) /temporal/* $(PROTO_OUT ) && rm -d $(PROTO_OUT ) /temporal
54+
5355# Generate mocks
5456
55- # All generated service files pathes relative to PROTO_OUT
57+ # All generated service files pathes relative to PROTO_OUT.
5658PROTO_GRPC_SERVICES = $(patsubst $(PROTO_OUT ) /% ,% ,$(shell find $(PROTO_OUT ) -name "service.pb.go") )
5759service_name = $(firstword $(subst /, ,$(1 ) ) )
5860mock_file_name = $(call service_name,$(1 ) ) mock/$(subst $(call service_name,$(1 ) ) /,,$(1:go=mock.go ) )
5961
6062grpc-mock :
6163 printf $(COLOR ) " Generate gRPC mocks..."
62- $(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 ) ) )
64+ $(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 ) )
6365
6466# Plugins & tools
6567
@@ -95,8 +97,9 @@ gomodtidy:
9597 printf $(COLOR ) " Run 'go mod tidy'..."
9698 go mod tidy
9799
98- # clean
100+ # Clean
99101
100102clean :
101103 printf $(COLOR ) " Deleting generated go files..."
102- rm -rf $(PROTO_OUT ) /* /* /* .pb.* go
104+ # Delete all directories with *.pb.go and *.mock.go files from $(PROTO_OUT)
105+ $(foreach PROTO_OUT_DIR,$(shell find $(PROTO_OUT) \( -name "*.pb.go" -o -name "*.mock.go" \) -printf "%h\n" | sort -u),rm -rf $(dir $(PROTO_OUT_DIR)) )
0 commit comments