1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

pb2py: Add pb2/ to sys.path

This removes the need for sed (which was problematic on OS X as it ships
with BSD Sed instead of GNU Sed)
This commit is contained in:
Saleem Rashid 2017-12-24 12:04:36 +00:00
parent fd5f232fdd
commit ff5999162a
2 changed files with 8 additions and 10 deletions

View File

@ -1,7 +1,6 @@
#!/bin/bash
CURDIR=$(pwd)
mkdir -p $CURDIR/pb2/
touch $CURDIR/pb2/__init__.py
mkdir -p ../trezorlib/messages
@ -16,14 +15,10 @@ for i in types messages storage ; do
protoc --python_out=$CURDIR/pb2/ -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
sed -i 's/^import types_pb2/from . import types_pb2/g' $CURDIR/pb2/storage_pb2.py
for i in types messages storage ; do
# Convert google protobuf library to trezor's internal format
cd $CURDIR
./pb2py -P "trezorlib.protobuf" -p $CURDIR -l $INDEX $i ../trezorlib/messages/
./pb2py -P "trezorlib.protobuf" -p $CURDIR/pb2 -l $INDEX $i ../trezorlib/messages/
done
rm -rf $CURDIR/pb2/

View File

@ -9,7 +9,7 @@ import argparse
def import_pb2(name):
return importlib.import_module("pb2.%s_pb2" % name)
return importlib.import_module("%s_pb2" % name)
def create_message_import(name):
@ -163,8 +163,8 @@ def write_to_file(genpath, t, out):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('module', type=import_pb2, help="Name of module to generate")
parser.add_argument('genpath', type=str, help="Directory for generated source code")
parser.add_argument('module', help="Name of module to generate")
parser.add_argument('genpath', help="Directory for generated source code")
parser.add_argument('-P', '--protobuf-module', default="protobuf", help="Name of protobuf module")
parser.add_argument('-i', '--indexfile', type=argparse.FileType('a'), help="Generate index file of wire types")
parser.add_argument('-l', '--modlist', type=argparse.FileType('a'), help="Generate list of modules")
@ -175,4 +175,7 @@ if __name__ == '__main__':
if args.protopath:
sys.path.append(args.protopath)
process_file(args.module.DESCRIPTOR, args.protobuf_module, args.genpath, args.indexfile, args.modlist, args.micropython)
# This must be done after sys.path.append
module = import_pb2(args.module)
process_file(module.DESCRIPTOR, args.protobuf_module, args.genpath, args.indexfile, args.modlist, args.micropython)