1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00
trezor-firmware/tools/build_protobuf

33 lines
840 B
Plaintext
Raw Normal View History

#!/bin/bash
CURDIR=$(pwd)
2018-01-12 11:54:06 +00:00
PB2DIR=$CURDIR/pb2
2018-01-12 11:58:39 +00:00
OUTDIR=../trezorlib/messages
INDEX=$OUTDIR/__init__.py
2018-01-12 12:10:36 +00:00
rm -f $OUTDIR/[A-Z]*.py
2018-01-12 11:58:39 +00:00
mkdir -p $OUTDIR
2018-01-12 11:54:06 +00:00
mkdir -p $PB2DIR
touch $PB2DIR/__init__.py
rm -f $INDEX
echo '# Automatically generated by pb2py' >> $INDEX
echo 'from __future__ import absolute_import' >> $INDEX
echo '' >> $INDEX
for i in types messages ; do
# Compile .proto files to python2 modules using google protobuf library
cd $CURDIR/../../trezor-common/protob
2018-01-12 11:54:06 +00:00
protoc --python_out=$PB2DIR -I/usr/include -I. $i.proto
done
# hack to make output python 3 compatible
sed -i 's/^import types_pb2/from . import types_pb2/g' $CURDIR/pb2/messages_pb2.py
for i in types messages ; do
# Convert google protobuf library to trezor's internal format
cd $CURDIR
2018-01-12 11:58:39 +00:00
./pb2py -p $CURDIR -l $INDEX $i $OUTDIR
done
2018-01-12 11:54:06 +00:00
rm -rf $PB2DIR