-
Notifications
You must be signed in to change notification settings - Fork 19
/
protobuf.mk
75 lines (59 loc) · 3.07 KB
/
protobuf.mk
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
ifndef PROJECT_NAME
$(error PROJECT_NAME must be defined)
endif
ifndef PROJECT_DIR
$(error PROJECT_DIR must be defined)
endif
DOCKER ?= docker
DOCKER_FLAGS := -v $(PROJECT_DIR):/workspace --workdir /workspace
DOCKER_BUF := $(DOCKER) run --rm $(DOCKER_FLAGS) bufbuild/buf
RSYNC ?= rsync
protoVer := v0.3
protoImageName := tendermintdev/sdk-proto-gen:$(protoVer)
containerProtoGen := $(PROJECT_NAME)-proto-gen-$(protoVer)
containerProtoGenSwagger := $(PROJECT_NAME)-proto-gen-swagger-$(protoVer)
containerProtoFmt := $(PROJECT_NAME)-proto-fmt-$(protoVer)
define docker_run
if $(DOCKER) ps -a --format '{{.Names}}' | grep -Eq "^${1}$$"; then $(DOCKER) start -a $(1); else $(DOCKER) run --name $(1) $(DOCKER_FLAGS) $(protoImageName) $(2); fi
endef
define sync_proto_deps
$(RSYNC) -r --chmod 644 --include "*.proto" --include='*/' --exclude='*' --prune-empty-dirs $(1) $(2)
endef
.PHONY: proto-all
proto-all: proto-gen proto-format proto-lint proto-swagger-gen ## Run all protobuf targets
.PHONY: proto-gen
proto-gen: ## Generate protobuf files
@echo "Generating Protobuf files"
@$(call docker_run,$(containerProtoGen),sh ./scripts/protocgen.sh)
.PHONY: proto-swagger-gen
proto-swagger-gen: ## Generate protobuf swagger
@echo "Generating Protobuf Swagger"
@$(call docker_run,$(containerProtoGenSwagger),sh ./scripts/protoc-swagger-gen.sh)
.PHONY: proto-format
proto-format: ## Format protobuf files
@echo "Formatting Protobuf files"
@$(call docker_run,$(containerProtoFmt),find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -style=file -i {} \;)
.PHONY: proto-lint
proto-lint: ## Lint protobuf files
@$(DOCKER_BUF) lint --error-format=json --exclude-path ./third_party/proto/cosmos_proto,./third_party/proto/gogoproto,./third_party/proto/google,./third_party/proto/tendermint,./third_party/proto/cosmos
PROTO_CHECK_REF ?= .git\#branch=main
.PHONY: proto-check-breaking
proto-check-breaking: ## Check for breaking changes against master
@$(DOCKER_BUF) breaking --against $(PROTO_CHECK_REF)
GOOGLE_PROTO_URL = https://raw.githubusercontent.com/googleapis/googleapis/master/google/api
GOOGLE_PROTO_TYPES = third_party/proto/google/api
COSMOS_PROTO_PATH := $(shell go list -m -f '{{.Dir}}' github.com/cosmos/cosmos-proto)
GOGO_PROTO_PATH := $(shell go list -m -f '{{.Dir}}' github.com/gogo/protobuf)
COSMOS_SDK_PATH := $(shell go list -m -f '{{.Dir}}' github.com/cosmos/cosmos-sdk)
TENDERMINT_SDK_PATH := $(shell go list -m -f '{{.Dir}}' github.com/tendermint/tendermint)
.PHONY: proto-update-deps
proto-update-deps: ## Update proto
mkdir -p third_party/proto
$(call sync_proto_deps,$(COSMOS_PROTO_PATH)/proto third_party)
$(call sync_proto_deps,$(GOGO_PROTO_PATH)/gogoproto third_party/proto)
$(call sync_proto_deps,$(COSMOS_SDK_PATH)/proto third_party)
$(call sync_proto_deps,$(TENDERMINT_SDK_PATH)/proto third_party)
mkdir -p $(GOOGLE_PROTO_TYPES)
curl -sSL $(GOOGLE_PROTO_URL)/annotations.proto > $(GOOGLE_PROTO_TYPES)/annotations.proto
curl -sSL $(GOOGLE_PROTO_URL)/http.proto > $(GOOGLE_PROTO_TYPES)/http.proto
curl -sSL $(GOOGLE_PROTO_URL)/httpbody.proto > $(GOOGLE_PROTO_TYPES)/httpbody.proto