Skip to content

Instantly share code, notes, and snippets.

@lix19937
Created June 5, 2025 01:11
Show Gist options
  • Save lix19937/b3fae407ab58ca4fcbe5c993df46a0a9 to your computer and use it in GitHub Desktop.
Save lix19937/b3fae407ab58ca4fcbe5c993df46a0a9 to your computer and use it in GitHub Desktop.
proto to cc and py
#!/bin/bash
set -e
SHELL_FOLDER=$(cd $(dirname "$0") && pwd)
export PROTO_INTERFACE_DIR=$SHELL_FOLDER/../interface/proto
# protoc --help
# build proto
function build_proto() {
cd $PROTO_INTERFACE_DIR
for proto_file in ./*/*.proto; do
if [ -f "$proto_file" ]; then
protoc --python_out=. $proto_file
protoc --cpp_out=. $proto_file
if [ $? -ne 0 ]; then
echo "protoc command failed"
exit 1
fi
fi
done
}
# clear .cc .h .py
function clear_proto_out() {
cd $PROTO_INTERFACE_DIR
for proto_file in ./*/*.py ./*/*.cc ./*/*.h; do
if [ -f "$proto_file" ]; then
rm -f "$proto_file"
if [ $? -ne 0 ]; then
echo "protoc command failed"
exit 1
fi
fi
done
}
build_proto "$@"
clear_proto_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment