Restructure protobuf files (#466)
* Restructure protobuf dir and generation * Format protobuf definitions
This commit is contained in:
7
scripts/README.md
Normal file
7
scripts/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Scripts
|
||||
|
||||
These scripts are copied from the [Cosmos-SDK](https://github.com/cosmos/cosmos-sdk/tree/v0.42.1/scripts) respository
|
||||
with minor modifications. All credits and big thanks go to the original authors.
|
||||
|
||||
Please note that a custom [fork](github.com/regen-network/protobuf) by the Regen network team is used.
|
||||
See [`go.mod`](../go.mod) for version.
|
||||
19
scripts/protoc-swagger-gen.sh
Executable file
19
scripts/protoc-swagger-gen.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
mkdir -p ./docs/client
|
||||
proto_dirs=$(find ./proto -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 protoc \
|
||||
-I "proto" \
|
||||
-I "third_party/proto" \
|
||||
"$query_file" \
|
||||
--swagger_out=./docs/client \
|
||||
--swagger_opt=logtostderr=true --swagger_opt=fqn_for_swagger_name=true --swagger_opt=simple_operation_ids=true
|
||||
fi
|
||||
done
|
||||
@@ -1,19 +1,38 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
PROJECT_PROTO_DIR=x/wasm/types/
|
||||
COSMOS_SDK_DIR=${COSMOS_SDK_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk)}
|
||||
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
|
||||
|
||||
# Generate Go types from protobuf
|
||||
protoc \
|
||||
-I=. \
|
||||
-I="$COSMOS_SDK_DIR/third_party/proto" \
|
||||
-I="$COSMOS_SDK_DIR/proto" \
|
||||
--gocosmos_out=Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,plugins=interfacetype+grpc,paths=source_relative:. \
|
||||
--grpc-gateway_out .\
|
||||
--grpc-gateway_opt logtostderr=true \
|
||||
--grpc-gateway_opt paths=Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,paths=source_relative \
|
||||
--doc_out=./doc \
|
||||
--doc_opt=markdown,proto.md \
|
||||
$(find "${PROJECT_PROTO_DIR}" -maxdepth 1 -name '*.proto')
|
||||
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest 2>/dev/null
|
||||
}
|
||||
|
||||
protoc_gen_gocosmos
|
||||
|
||||
proto_dirs=$(find ./proto -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')
|
||||
|
||||
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')
|
||||
|
||||
# move proto files to the right places
|
||||
cp -r github.com/CosmWasm/wasmd/* ./
|
||||
rm -rf github.com
|
||||
|
||||
Reference in New Issue
Block a user