refactor(proto): host module proto files within modules (#18758)

This commit is contained in:
Julien Robert
2024-02-20 23:17:13 +00:00
committed by GitHub
parent 8cb798d7bf
commit 0cf0c285ea
198 changed files with 1575 additions and 55 deletions
-14
View File
@@ -1,14 +0,0 @@
# this script is for generating protobuf files for the new google.golang.org/protobuf API
set -eo pipefail
echo "Cleaning API directory"
(cd api; find ./ -type f \( -iname \*.pulsar.go -o -iname \*.pb.go -o -iname \*.cosmos_orm.go -o -iname \*.pb.gw.go \) -delete; find . -empty -type d -delete; cd ..)
echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)
echo "Generate Pulsar Test Data"
(cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml)
echo "Generate x/tx"
(cd x/tx; make codegen)
+43 -23
View File
@@ -9,32 +9,52 @@ find ./ -name "*.proto" -exec clang-format -i {} \;
set -e
echo "Generating gogo proto code"
cd proto
proto_dirs=$(find ./cosmos ./amino -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq | grep -v '^./cosmos/store/')
home=$PWD
echo "Generating proto code"
proto_dirs=$(find ./ -name 'buf.yaml' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
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
echo "Generating proto code for $dir"
cd $dir
# check if buf.gen.pulsar.yaml exists in the proto directory
if [ -f "buf.gen.pulsar.yaml" ]; then
buf generate --template buf.gen.pulsar.yaml
# move generated files to the right places
if [ -d "../cosmos" -a "$dir" != "./proto" ]; then
cp -r ../cosmos $home/api
rm -rf ../cosmos
fi
done
fi
# check if buf.gen.gogo.yaml exists in the proto directory
if [ -f "buf.gen.gogo.yaml" ]; then
for file in $(find . -maxdepth 5 -name '*.proto' | grep -v '^./cosmos/store/'); 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
# move generated files to the right places
if [ -d "../cosmossdk.io" -a "$dir" != "./proto" ]; then
cp -r ../cosmossdk.io/* $home
rm -rf ../cosmossdk.io
fi
if [ -d "../github.com" -a "$dir" != "./proto" ]; then
cp -r ../github.com/cosmos/cosmos-sdk/* $home
rm -rf ../github.com
fi
fi
cd $home
done
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
# move generated files to the right places
cp -r github.com/cosmos/cosmos-sdk/* ./
cp -r cosmossdk.io/** ./
rm -rf github.com cosmossdk.io
rm -rf github.com
go mod tidy
./scripts/protocgen-pulsar.sh
go mod tidy