1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-17 01:52:02 +00:00

build_protobuf: Refactor

* Use `set -e` to fail on error
* Change into script directory automatically
This commit is contained in:
Saleem Rashid 2017-12-24 12:14:29 +00:00
parent ff5999162a
commit bbed79f658

View File

@ -1,24 +1,31 @@
#!/bin/bash #!/bin/bash
CURDIR=$(pwd) set -e
mkdir -p $CURDIR/pb2/
mkdir -p ../trezorlib/messages cd "$(dirname "$0")"
INDEX=../trezorlib/messages/__init__.py GENPATH="../trezorlib/messages"
rm -f $INDEX INDEX="$GENPATH/__init__.py"
echo '# Automatically generated by pb2py' >> $INDEX PROTO_PATH="../../trezor-common/protob"
echo '' >> $INDEX PROTO_FILES=(types messages storage)
PB2_OUT="pb2"
for i in types messages storage ; do mkdir -p "$GENPATH"
cat > "$INDEX" << EOF
# Automatically generated by pb2py
EOF
mkdir -p "$PB2_OUT"
for file in "${PROTO_FILES[@]}"; do
# Compile .proto files to python2 modules using google protobuf library # Compile .proto files to python2 modules using google protobuf library
cd $CURDIR/../../trezor-common/protob protoc --python_out="$PB2_OUT" -I"$PROTO_PATH" "$file.proto"
protoc --python_out=$CURDIR/pb2/ -I/usr/include -I. $i.proto
done done
for i in types messages storage ; do for file in "${PROTO_FILES[@]}"; do
# Convert google protobuf library to trezor's internal format # Convert google protobuf library to trezor's internal format
cd $CURDIR ./pb2py -P "trezorlib.protobuf" -p "$PB2_OUT" -l "$INDEX" "$file" "$GENPATH"
./pb2py -P "trezorlib.protobuf" -p $CURDIR/pb2 -l $INDEX $i ../trezorlib/messages/
done done
rm -rf $CURDIR/pb2/ rm -rf "$PB2_OUT"