mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-23 07:58:09 +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:
parent
fd5f232fdd
commit
ff5999162a
@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
CURDIR=$(pwd)
|
CURDIR=$(pwd)
|
||||||
mkdir -p $CURDIR/pb2/
|
mkdir -p $CURDIR/pb2/
|
||||||
touch $CURDIR/pb2/__init__.py
|
|
||||||
|
|
||||||
mkdir -p ../trezorlib/messages
|
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
|
protoc --python_out=$CURDIR/pb2/ -I/usr/include -I. $i.proto
|
||||||
done
|
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
|
for i in types messages storage ; do
|
||||||
# Convert google protobuf library to trezor's internal format
|
# Convert google protobuf library to trezor's internal format
|
||||||
cd $CURDIR
|
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
|
done
|
||||||
|
|
||||||
rm -rf $CURDIR/pb2/
|
rm -rf $CURDIR/pb2/
|
||||||
|
11
tools/pb2py
11
tools/pb2py
@ -9,7 +9,7 @@ import argparse
|
|||||||
|
|
||||||
|
|
||||||
def import_pb2(name):
|
def import_pb2(name):
|
||||||
return importlib.import_module("pb2.%s_pb2" % name)
|
return importlib.import_module("%s_pb2" % name)
|
||||||
|
|
||||||
|
|
||||||
def create_message_import(name):
|
def create_message_import(name):
|
||||||
@ -163,8 +163,8 @@ def write_to_file(genpath, t, out):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('module', type=import_pb2, help="Name of module to generate")
|
parser.add_argument('module', help="Name of module to generate")
|
||||||
parser.add_argument('genpath', type=str, help="Directory for generated source code")
|
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('-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('-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")
|
parser.add_argument('-l', '--modlist', type=argparse.FileType('a'), help="Generate list of modules")
|
||||||
@ -175,4 +175,7 @@ if __name__ == '__main__':
|
|||||||
if args.protopath:
|
if args.protopath:
|
||||||
sys.path.append(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)
|
||||||
|
Loading…
Reference in New Issue
Block a user