1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00
trezor-firmware/tools/build_protobuf

31 lines
927 B
Plaintext
Raw Normal View History

2016-04-26 23:32:57 +00:00
#!/bin/bash
CURDIR=$(pwd)
mkdir -p $CURDIR/pb2/
2017-09-25 14:01:22 +00:00
touch $CURDIR/pb2/__init__.py
2016-04-26 23:32:57 +00:00
2017-06-13 17:35:14 +00:00
mkdir -p ../src/trezor/messages
2016-09-21 12:12:46 +00:00
INDEX=../src/trezor/messages/wire_types.py
rm -f $INDEX
2017-06-07 17:06:26 +00:00
echo '# Automatically generated by pb2py' >> $INDEX
echo 'from micropython import const' >> $INDEX
echo '' >> $INDEX
2016-09-21 12:12:46 +00:00
2016-04-27 20:44:37 +00:00
for i in types messages storage ; do
2016-04-26 23:32:57 +00:00
# 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
done
2016-04-26 23:32:57 +00:00
2017-09-25 14:01:22 +00:00
# hack to make output python 3 compatible
sed -i 's/^import types_pb2/from . import types_pb2/g' $CURDIR/pb2/messages_pb2.py
sed -i 's/^import types_pb2/from . import types_pb2/g' $CURDIR/pb2/storage_pb2.py
for i in types messages storage ; do
2016-04-26 23:32:57 +00:00
# Convert google protobuf library to trezor's internal format
cd $CURDIR
2017-06-13 17:35:14 +00:00
./pb2py -m -p $CURDIR -i $INDEX $i ../src/trezor/messages/
2016-04-26 23:32:57 +00:00
done
rm -rf $CURDIR/pb2/