forked from scrtlabs/SecretNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update protobuf generation infrastructure
- Loading branch information
1 parent
8d271ab
commit 543d0ee
Showing
11 changed files
with
163 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -565,45 +565,30 @@ aesm-image: | |
docker build -f deployment/dockerfiles/aesm.Dockerfile -t enigmampc/aesm . | ||
|
||
############################################################################### | ||
### Swagger & Protobuf ### | ||
### Protobuf ### | ||
############################################################################### | ||
|
||
.PHONY: update-swagger-openapi-docs statik statik-install proto-swagger-openapi-gen | ||
protoVer=0.14.0 | ||
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) | ||
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) | ||
|
||
statik-install: | ||
@echo "Installing statik..." | ||
@go install github.com/rakyll/[email protected] | ||
|
||
statik: | ||
statik -src=client/docs/static/ -dest=client/docs -f -m | ||
|
||
proto-swagger-openapi-gen: | ||
cp go.mod /tmp/go.mod.bak | ||
cp go.sum /tmp/go.sum.bak | ||
@./scripts/protoc-swagger-openapi-gen.sh | ||
cp /tmp/go.mod.bak go.mod | ||
cp /tmp/go.sum.bak go.sum | ||
|
||
# Example `CHAIN_VERSION=v1.4.0 make update-swagger-openapi-docs` | ||
update-swagger-openapi-docs: statik-install proto-swagger-openapi-gen statik | ||
|
||
protoVer=v0.2 | ||
|
||
proto-all: proto-lint proto-gen proto-swagger-openapi-gen | ||
proto-all: proto-format proto-gen proto-swagger-gen | ||
|
||
proto-gen: | ||
cp go.mod /tmp/go.mod.bak | ||
cp go.sum /tmp/go.sum.bak | ||
@echo "Generating Protobuf files" | ||
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen:$(protoVer) sh ./scripts/protocgen.sh | ||
cp /tmp/go.mod.bak go.mod | ||
cp /tmp/go.sum.bak go.sum | ||
go mod tidy | ||
@$(protoImage) sh ./scripts/protocgen.sh | ||
|
||
proto-swagger-gen: | ||
@echo "Generating Protobuf Swagger" | ||
@$(protoImage) sh ./scripts/protoc-swagger-gen.sh | ||
|
||
proto-format: | ||
@$(protoImage) find ./proto -name "*.proto" -exec clang-format -i {} \; | ||
|
||
proto-lint: | ||
@$(DOCKER_BUF) lint --error-format=json | ||
@$(protoImage) buf lint --error-format=json | ||
|
||
.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking | ||
.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint | ||
|
||
.PHONY: check-hw | ||
check-hw: build-linux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version: v1 | ||
directories: | ||
- proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: v1beta1 | ||
plugins: | ||
- name: gocosmos | ||
out: .. | ||
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm | ||
- name: grpc-gateway | ||
out: .. | ||
opt: logtostderr=true,allow_colon_final_segments=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: v1 | ||
plugins: | ||
- name: swagger | ||
out: ../tmp-swagger-gen | ||
opt: logtostderr=true,fqn_for_swagger_name=true,simple_operation_ids=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by buf. DO NOT EDIT. | ||
version: v1 | ||
deps: | ||
- remote: buf.build | ||
owner: cosmos | ||
repository: cosmos-proto | ||
commit: 1935555c206d4afb9e94615dfd0fad31 | ||
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 | ||
- remote: buf.build | ||
owner: cosmos | ||
repository: cosmos-sdk | ||
commit: 05419252bcc241ea8023acf1ed4cadc5 | ||
digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5 | ||
- remote: buf.build | ||
owner: cosmos | ||
repository: gogo-proto | ||
commit: 88ef6483f90f478fb938c37dde52ece3 | ||
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba | ||
- remote: buf.build | ||
owner: googleapis | ||
repository: googleapis | ||
commit: ee48893a270147348e3edc6c1a03de0e | ||
digest: shake256:a35b0576a2b55dad72747e786af05c03539c2b96be236c9de39fe10d551931ac252eb68445c0cef6bbd27fa20e8c26eee5b8a9fe9c2fde6f63a03e18f8cf980d | ||
- remote: buf.build | ||
owner: protocolbuffers | ||
repository: wellknowntypes | ||
commit: 657250e6a39648cbb169d079a60bd9ba | ||
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb | ||
- remote: buf.build | ||
owner: tendermint | ||
repository: tendermint | ||
commit: 33ed361a90514289beabf3189e1d7665 | ||
digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This module represents buf.build/cosmos/cosmos-sdk | ||
version: v1 | ||
deps: | ||
- buf.build/cosmos/cosmos-proto | ||
- buf.build/cosmos/cosmos-sdk | ||
- buf.build/cosmos/gogo-proto | ||
- buf.build/googleapis/googleapis | ||
breaking: | ||
use: | ||
- FILE | ||
lint: | ||
use: | ||
- DEFAULT | ||
- COMMENTS | ||
- FILE_LOWER_SNAKE_CASE | ||
except: | ||
- UNARY_RPC | ||
- COMMENT_FIELD | ||
- SERVICE_SUFFIX | ||
- PACKAGE_VERSION_SUFFIX | ||
- RPC_REQUEST_STANDARD_NAME | ||
ignore: | ||
- tendermint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
mkdir -p ./tmp-swagger-gen | ||
cd proto | ||
proto_dirs=$(find ./secret -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) | ||
for dir in $proto_dirs; do | ||
# generate swagger files (filter query files) | ||
query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \)) | ||
if [[ ! -z "$query_file" ]]; then | ||
buf generate --template buf.gen.swagger.yaml $query_file | ||
fi | ||
done | ||
|
||
cd .. | ||
# combine swagger files | ||
# uses nodejs package `swagger-combine`. | ||
# all the individual swagger files need to be configured in `config.json` for merging | ||
swagger-combine ./client/docs/config.json -o ./client/docs/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true | ||
|
||
# clean swagger files | ||
rm -rf ./tmp-swagger-gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
# How to run manually: | ||
# docker build --pull --rm -f "contrib/devtools/Dockerfile" -t cosmossdk-proto:latest "contrib/devtools" | ||
# docker run --rm -v $(pwd):/workspace --workdir /workspace cosmossdk-proto sh ./scripts/protocgen.sh | ||
|
||
protoc_gen_gocosmos() { | ||
if ! grep "github.com/gogo/protobuf => github.com/regen-network/protobuf" go.mod &>/dev/null ; then | ||
echo -e "\tPlease run this command from somewhere inside the cosmos-sdk folder." | ||
return 1 | ||
fi | ||
echo "Formatting protobuf files" | ||
# find ./ -name "*.proto" -exec clang-format -i {} \; | ||
|
||
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest | ||
} | ||
set -e | ||
|
||
protoc_gen_gocosmos | ||
|
||
proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) | ||
echo "Generating gogo proto code" | ||
cd proto | ||
proto_dirs=$(find ./secret -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) | ||
for dir in $proto_dirs; do | ||
buf protoc \ | ||
-I "proto" \ | ||
-I "third_party/proto" \ | ||
--gocosmos_out=plugins=interfacetype+grpc,\ | ||
Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ | ||
--grpc-gateway_out=logtostderr=true:. \ | ||
$(find "${dir}" -maxdepth 1 -name '*.proto') | ||
|
||
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do | ||
# this regex checks if a proto file has its go_package set to cosmossdk.io/api/... | ||
# gogo proto files SHOULD ONLY be generated if this is false | ||
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf | ||
# if grep -q "option go_package" "$file" && grep -H -o -c 'option go_package.*cosmossdk.io/api' "$file" | grep -q ':0$'; then | ||
buf generate --template buf.gen.gogo.yaml $file | ||
# fi | ||
done | ||
done | ||
|
||
# command to generate docs using protoc-gen-doc | ||
#buf protoc \ | ||
#-I "proto" \ | ||
#-I "third_party/proto" \ | ||
#--doc_out=./docs/proto \ | ||
#--doc_opt=./docs/proto/protodoc-markdown.tmpl,proto-docs.md \ | ||
#$(find "$(pwd)/proto" -maxdepth 5 -name '*.proto') \ | ||
#$(find "$(pwd)/third_party/proto/cosmos" -maxdepth 4 -name '*.proto') \ | ||
#$(find "$(pwd)/third_party/proto/ibc" -maxdepth 4 -name '*.proto') | ||
cd .. | ||
|
||
# generate tests proto code | ||
# (cd testutil/testdata; buf generate) | ||
# (cd baseapp/testutil; buf generate) | ||
# (cd tests/integration/tx/internal; make codegen) | ||
|
||
# move proto files to the right places | ||
cp -r github.com/scrtlabs/SecretNetwork/* ./ | ||
rm -rf github.com | ||
# cp -r github.com/cosmos/cosmos-sdk/* ./ | ||
# cp -r cosmossdk.io/** ./ | ||
# rm -rf github.com cosmossdk.io | ||
|
||
go mod tidy | ||
|
||
# ./scripts/protocgen-pulsar.sh |