@@ -15,58 +15,77 @@ GOPATH := $(shell go env GOPATH)
1515endif
1616
1717GOBIN := $(if $(shell go env GOBIN) ,$(shell go env GOBIN) ,$(GOPATH ) /bin)
18- SHELL := PATH=$(GOBIN ) :$(PATH ) /bin/sh
18+ PATH := $(GOBIN ) :$(PATH )
19+ STAMPDIR := .stamp
1920
2021COLOR := "\e[1;36m%s\e[0m\n"
2122
23+ # Only prints output if the exit code is non-zero
24+ define silent_exec
25+ @output=$$($(1 ) 2>&1) ; \
26+ status=$$? ; \
27+ if [ $$status -ne 0 ]; then \
28+ echo "$$output"; \
29+ fi; \
30+ exit $$status
31+ endef
32+
2233PROTO_ROOT := .
23- PROTO_FILES = $(shell find $( PROTO_ROOT ) -name "* .proto")
34+ PROTO_FILES = $(shell find temporal -name "* .proto")
2435PROTO_DIRS = $(sort $(dir $(PROTO_FILES ) ) )
2536PROTO_OUT := .gen
26- PROTO_IMPORTS = -I=$(PROTO_ROOT ) -I=$(shell go list -modfile build/go.mod -m -f '{{.Dir}}' github.com/temporalio/gogo-protobuf) /protobuf
37+ PROTO_IMPORTS = \
38+ -I=$(PROTO_ROOT )
39+ PROTO_PATHS = paths=source_relative:$(PROTO_OUT )
2740
2841$(PROTO_OUT ) :
2942 mkdir $(PROTO_OUT )
3043
3144# #### Compile proto files for go #####
32- grpc : buf-lint api-linter buf-breaking gogo -grpc fix-path
45+ grpc : buf-lint api-linter buf-breaking clean go -grpc fix-path
3346
3447go-grpc : clean $(PROTO_OUT )
3548 printf $(COLOR ) " Compile for go-gRPC..."
36- $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --fatal_warnings $(PROTO_IMPORTS ) --go_out=plugins=grpc,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) * .proto;)
37-
38- gogo-grpc : clean $(PROTO_OUT )
39- printf $(COLOR ) " Compile for gogo-gRPC..."
40- $(foreach PROTO_DIR,$(PROTO_DIRS ) ,protoc --fatal_warnings $(PROTO_IMPORTS ) --gogoslick_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT ) $(PROTO_DIR ) * .proto;)
49+ $(foreach PROTO_DIR,$(PROTO_DIRS ) ,\
50+ protoc --fatal_warnings $(PROTO_IMPORTS ) \
51+ --go_out=$(PROTO_PATHS ) \
52+ --grpc-gateway_out=allow_patch_feature =false,$(PROTO_PATHS ) \
53+ --doc_out=html,index.html,source_relative:$(PROTO_OUT ) \
54+ $(PROTO_DIR ) *.proto;)
4155
4256fix-path :
4357 mv -f $(PROTO_OUT ) /temporal/api/* $(PROTO_OUT ) && rm -rf $(PROTO_OUT ) /temporal
4458
4559# #### Plugins & tools #####
46- grpc-install : gogo-protobuf-install
47- printf $(COLOR ) " Install/update gRPC plugins..."
48- go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
49-
50- gogo-protobuf-install : go-protobuf-install
51- go install -modfile build/go.mod github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
52-
53- go-protobuf-install :
54- go install github.com/golang/protobuf/protoc-gen-go@v1.5.2
60+ grpc-install :
61+ @printf $(COLOR ) " Install/update protoc and plugins..."
62+ @go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
63+ @go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
64+ @go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
65+ @go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
5566
5667api-linter-install :
5768 printf $(COLOR ) " Install/update api-linter..."
5869 go install github.com/googleapis/api-linter/cmd/api-linter@v1.32.3
5970
6071buf-install :
6172 printf $(COLOR ) " Install/update buf..."
62- go install github.com/bufbuild/buf/cmd/buf@v1.6 .0
73+ go install github.com/bufbuild/buf/cmd/buf@v1.27 .0
6374
6475# #### Linters #####
6576api-linter :
6677 printf $(COLOR ) " Run api-linter..."
67- api-linter --set-exit-status $(PROTO_IMPORTS ) --config $(PROTO_ROOT ) /api-linter.yaml $(PROTO_FILES )
78+ $(call silent_exec, api-linter --set-exit-status $(PROTO_IMPORTS ) --config $(PROTO_ROOT ) /api-linter.yaml $(PROTO_FILES ) )
79+
80+ $(STAMPDIR ) :
81+ mkdir $@
82+
83+ $(STAMPDIR ) /buf-mod-prune : $(STAMPDIR ) buf.yaml
84+ printf $(COLOR ) " Pruning buf module"
85+ buf mod prune
86+ touch $@
6887
69- buf-lint :
88+ buf-lint : $( STAMPDIR ) /buf-mod-prune
7089 printf $(COLOR ) " Run buf linter..."
7190 (cd $( PROTO_ROOT) && buf lint)
7291
@@ -77,4 +96,4 @@ buf-breaking:
7796# #### Clean #####
7897clean :
7998 printf $(COLOR ) " Delete generated go files..."
80- rm -rf $(PROTO_OUT )
99+ rm -rf $(PROTO_OUT ) $( BUF_DEPS )
0 commit comments