Skip to content

Commit

Permalink
docker: proto (#7893)
Browse files Browse the repository at this point in the history
* migrate fully to buf

* run protoc-gen-cosmos in script

* migrate to docker container

* Update Makefile

Co-authored-by: Alessio Treglia <[email protected]>

* Update scripts/protocgen.sh

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2020
1 parent e9f1922 commit 104a203
Show file tree
Hide file tree
Showing 5 changed files with 622 additions and 631 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ proto-all: proto-tools proto-gen proto-lint proto-check-breaking proto-swagger-g
proto-gen:
@./scripts/protocgen.sh

proto-gen-docker:
@echo "Generating Protobuf files"
docker run -v $(shell pwd):/workspace --workdir /workspace tendermintdev/sdk-proto-gen sh ./scripts/protocgen.sh
.PHONY: proto-gen-docker

proto-format:
@echo "Formatting Protobuf files"
docker run -v $(shell pwd):/workspace \
Expand Down
29 changes: 1 addition & 28 deletions contrib/devtools/proto-tools-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ DESTDIR=${DESTDIR:-}
PREFIX=${PREFIX:-/usr/local}
UNAME_S="$(uname -s 2>/dev/null)"
UNAME_M="$(uname -m 2>/dev/null)"
BUF_VERSION=0.11.0
PROTOC_VERSION=3.13.0
BUF_VERSION=0.30.0
PROTOC_GRPC_GATEWAY_VERSION=1.14.7

f_abort() {
Expand Down Expand Up @@ -61,19 +60,6 @@ f_needs_install() {
return 0
}

f_install_protoc() {
f_print_installing_with_padding proto_c
f_needs_install "${DESTDIR}/${PREFIX}/bin/protoc" || return 0

pushd "${TEMPDIR}" >/dev/null
curl -o "${PROTOC_ZIP}" -sSL "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}"
unzip -q -o ${PROTOC_ZIP} -d ${DESTDIR}/${PREFIX} bin/protoc; \
unzip -q -o ${PROTOC_ZIP} -d ${DESTDIR}/${PREFIX} 'include/*'; \
rm -f ${PROTOC_ZIP}
popd >/dev/null
f_print_done
}

f_install_buf() {
f_print_installing_with_padding buf
f_needs_install "${DESTDIR}/${PREFIX}/bin/buf" || return 0
Expand All @@ -83,18 +69,6 @@ f_install_buf() {
f_print_done
}

f_install_protoc_gen_gocosmos() {
f_print_installing_with_padding 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

go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null
f_print_done
}

f_install_protoc_gen_grpc_gateway() {
f_print_installing_with_padding protoc-gen-grpc-gateway
f_needs_install "${DESTDIR}/${PREFIX}/bin/protoc-gen-grpc-gateway" || return 0
Expand All @@ -121,7 +95,6 @@ f_install_protoc_gen_swagger() {

f_ensure_tools
f_ensure_dirs
f_install_protoc
f_install_buf
f_install_protoc_gen_gocosmos
f_install_protoc_gen_grpc_gateway
Expand Down
2 changes: 1 addition & 1 deletion scripts/protocgen-any.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -eo pipefail

go install github.com/gogo/protobuf/protoc-gen-gogotypes

protoc -I. --gogotypes_out=./codec/types third_party/proto/google/protobuf/any.proto
buf protoc -I. --gogotypes_out=./codec/types third_party/proto/google/protobuf/any.proto
mv codec/types/third_party/proto/google/protobuf/any.pb.go codec/types
rm -rf codec/types/third_party

Expand Down
17 changes: 14 additions & 3 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

set -eo pipefail

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

go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 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
protoc \
buf protoc \
-I "proto" \
-I "third_party/proto" \
--gocosmos_out=plugins=interfacetype+grpc,\
Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')

# command to generate gRPC gateway (*.pb.gw.go in respective modules) files
protoc \
buf protoc \
-I "proto" \
-I "third_party/proto" \
--grpc-gateway_out=logtostderr=true:. \
Expand All @@ -21,7 +32,7 @@ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
done

# generate codec/testdata proto code
protoc -I "proto" -I "third_party/proto" -I "testutil/testdata" --gocosmos_out=plugins=interfacetype+grpc,\
buf protoc -I "proto" -I "third_party/proto" -I "testutil/testdata" --gocosmos_out=plugins=interfacetype+grpc,\
Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. ./testutil/testdata/*.proto

# move proto files to the right places
Expand Down
Loading

0 comments on commit 104a203

Please sign in to comment.