From e76fb3e8e1960d9d77c2f66cf06d8bf4296b5ff7 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 9 Nov 2021 18:02:42 -0500 Subject: [PATCH] update the proto build script to add package name --- Makefile | 1 - scripts/protocgen.sh | 27 ++++++++++++++++++--------- scripts/protopackage.sh | 11 +++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100755 scripts/protopackage.sh diff --git a/Makefile b/Makefile index 2bac7f5bf..b313b1d07 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,6 @@ proto-all: proto-gen proto-lint proto-check-breaking .PHONY: proto-all proto-gen: - @docker pull -q tendermintdev/docker-build-proto @echo "Generating Protobuf files" @docker run -v $(shell pwd):/workspace --workdir /workspace tendermintdev/docker-build-proto sh ./scripts/protocgen.sh .PHONY: proto-gen diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 240570d61..c6ecfbae9 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -1,29 +1,37 @@ #!/usr/bin/env bash - -set -eo pipefail +set -euo pipefail : ${VERS:=master} -URL_PATH=archive/ +URL_PATH=tarball/ if [[ VERS -ne master ]]; then - URL_PATH=archive/refs/tags/v + URL_PATH=tarball/refs/tags/v fi +echo "fetching proto files" + +# Get shortened ref of commit +REF=`curl -H "Accept: application/vnd.github.v3.sha" -qL "https://api.github.com/repos/tendermint/spec/commits/${VERS}" | cut -c -7` # Edit this line to clone your branch, if you are modifying protobuf files -curl -qL "https://github.com/tendermint/spec/${URL_PATH}${VERS}.tar.gz" | tar -xjf - spec-"$VERS"/proto/ +curl -qL "https://api.github.com/repos/tendermint/spec/${URL_PATH}${REF}" | tar -xzf - tendermint-spec-"$REF"/ -cp -r ./spec-"$VERS"/proto/tendermint/** ./proto/tendermint +cp -r ./tendermint-spec-"$REF"/proto/tendermint/** ./proto/tendermint +cp -r ./tendermint-spec-"$REF"/third_party/** ./third_party -buf generate --path proto/tendermint +MODNAME=$(go list -m) +find ./proto/tendermint -name *.proto -exec sh ./scripts/protopackage.sh {} $MODNAME ';' + +buf generate --path proto/tendermint --template ./tendermint-spec-"$REF"/proto/buf.gen.yaml --config ./tendermint-spec-"$REF"/proto/buf.yaml mv ./proto/tendermint/abci/types.pb.go ./abci/types -echo "proto files have been generated" +echo "proto files have been compiled" echo "removing copied files" rm -rf ./proto/tendermint/abci rm -rf ./proto/tendermint/blocksync/types.proto rm -rf ./proto/tendermint/consensus/types.proto +rm -rf ./proto/tendermint/libs/bits/types.proto rm -rf ./proto/tendermint/mempool/types.proto rm -rf ./proto/tendermint/p2p/types.proto rm -rf ./proto/tendermint/p2p/conn.proto @@ -35,5 +43,6 @@ rm -rf ./proto/tendermint/types/params.proto rm -rf ./proto/tendermint/types/types.proto rm -rf ./proto/tendermint/types/validator.proto rm -rf ./proto/tendermint/version/types.proto +rm -rf ./thirdparty/proto/gogoproto/gogo.proto -rm -rf ./spec-"$VERS" +rm -rf ./tendermint-spec-"$REF" diff --git a/scripts/protopackage.sh b/scripts/protopackage.sh new file mode 100755 index 000000000..e55befe35 --- /dev/null +++ b/scripts/protopackage.sh @@ -0,0 +1,11 @@ +#!/usr/bin/sh +set -eo pipefail + +# This script appends the "option go_package" proto option to the file located at $FNAME + + +FNAME=$1 +MODNAME=$(echo $2| sed 's/\//\\\//g') +PACKAGE="$(dirname $FNAME | cut -c 2- | sed 's/\//\\\//g')" + +sed -i "s/\(package tendermint.*\)/\1\n\noption go_package = \"$MODNAME$PACKAGE\";/g" $FNAME