mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
build_protobuf: Refactor
* Use `set -e` to fail on error * Change into script directory automatically
This commit is contained in:
parent
ff5999162a
commit
bbed79f658
@ -1,24 +1,31 @@
|
||||
#!/bin/bash
|
||||
CURDIR=$(pwd)
|
||||
mkdir -p $CURDIR/pb2/
|
||||
set -e
|
||||
|
||||
mkdir -p ../trezorlib/messages
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
INDEX=../trezorlib/messages/__init__.py
|
||||
rm -f $INDEX
|
||||
echo '# Automatically generated by pb2py' >> $INDEX
|
||||
echo '' >> $INDEX
|
||||
GENPATH="../trezorlib/messages"
|
||||
INDEX="$GENPATH/__init__.py"
|
||||
PROTO_PATH="../../trezor-common/protob"
|
||||
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
|
||||
cd $CURDIR/../../trezor-common/protob
|
||||
protoc --python_out=$CURDIR/pb2/ -I/usr/include -I. $i.proto
|
||||
protoc --python_out="$PB2_OUT" -I"$PROTO_PATH" "$file.proto"
|
||||
done
|
||||
|
||||
for i in types messages storage ; do
|
||||
for file in "${PROTO_FILES[@]}"; do
|
||||
# Convert google protobuf library to trezor's internal format
|
||||
cd $CURDIR
|
||||
./pb2py -P "trezorlib.protobuf" -p $CURDIR/pb2 -l $INDEX $i ../trezorlib/messages/
|
||||
./pb2py -P "trezorlib.protobuf" -p "$PB2_OUT" -l "$INDEX" "$file" "$GENPATH"
|
||||
done
|
||||
|
||||
rm -rf $CURDIR/pb2/
|
||||
rm -rf "$PB2_OUT"
|
||||
|
Loading…
Reference in New Issue
Block a user