mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
build: centralize pb2py usage
This commit is contained in:
parent
cf396e3661
commit
f8446c3e00
@ -333,8 +333,6 @@ class Descriptor:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
# fmt: off
|
||||
parser.add_argument("proto", nargs="+", help="Protobuf definition files")
|
||||
@ -343,9 +341,13 @@ if __name__ == "__main__":
|
||||
parser.add_argument("-l", "--no-init-py", action="store_true", help="Do not generate __init__.py with list of modules")
|
||||
parser.add_argument("--message-type", default="MessageType", help="Name of enum with message IDs")
|
||||
parser.add_argument("-I", "--protoc-include", action="append", help="protoc include path")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Print debug messages")
|
||||
# fmt: on
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.verbose:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
protoc_includes = args.protoc_include or (os.environ.get("PROTOC_INCLUDE"),)
|
||||
descriptor_proto = protoc(args.proto, protoc_includes)
|
||||
descriptor = Descriptor(descriptor_proto, args.message_type, args.protobuf_module)
|
||||
|
@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
cd $(dirname $0)
|
||||
|
||||
rm -f ../src/trezor/messages/[A-Z]*.py
|
||||
../vendor/trezor-common/protob/pb2py \
|
||||
--no-init-py \
|
||||
-o ../src/trezor/messages \
|
||||
../vendor/trezor-common/protob/messages.proto \
|
||||
../vendor/trezor-common/protob/messages-bitcoin.proto \
|
||||
../vendor/trezor-common/protob/messages-cardano.proto \
|
||||
../vendor/trezor-common/protob/messages-common.proto \
|
||||
../vendor/trezor-common/protob/messages-crypto.proto \
|
||||
../vendor/trezor-common/protob/messages-debug.proto \
|
||||
../vendor/trezor-common/protob/messages-eos.proto \
|
||||
../vendor/trezor-common/protob/messages-ethereum.proto \
|
||||
../vendor/trezor-common/protob/messages-lisk.proto \
|
||||
../vendor/trezor-common/protob/messages-management.proto \
|
||||
../vendor/trezor-common/protob/messages-monero.proto \
|
||||
../vendor/trezor-common/protob/messages-nem.proto \
|
||||
../vendor/trezor-common/protob/messages-ripple.proto \
|
||||
../vendor/trezor-common/protob/messages-stellar.proto \
|
||||
../vendor/trezor-common/protob/messages-tezos.proto
|
67
tools/build_protobuf
Executable file
67
tools/build_protobuf
Executable file
@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
cd $(dirname $0)/..
|
||||
|
||||
PROTOB=common/protob
|
||||
|
||||
CORE_PROTOBUF_SOURCES="\
|
||||
$PROTOB/messages.proto \
|
||||
$PROTOB/messages-bitcoin.proto \
|
||||
$PROTOB/messages-cardano.proto \
|
||||
$PROTOB/messages-common.proto \
|
||||
$PROTOB/messages-crypto.proto \
|
||||
$PROTOB/messages-debug.proto \
|
||||
$PROTOB/messages-eos.proto \
|
||||
$PROTOB/messages-ethereum.proto \
|
||||
$PROTOB/messages-lisk.proto \
|
||||
$PROTOB/messages-management.proto \
|
||||
$PROTOB/messages-monero.proto \
|
||||
$PROTOB/messages-nem.proto \
|
||||
$PROTOB/messages-ripple.proto \
|
||||
$PROTOB/messages-stellar.proto \
|
||||
$PROTOB/messages-tezos.proto \
|
||||
"
|
||||
|
||||
PYTHON_PROTOBUF_SOURCES=$PROTOB/*.proto
|
||||
|
||||
RETURN=0
|
||||
|
||||
do_rebuild() {
|
||||
# rebuild protobuf in specified directory
|
||||
local DESTDIR="$1"
|
||||
shift
|
||||
local SOURCES="$1"
|
||||
shift
|
||||
|
||||
mkdir -p "$DESTDIR"
|
||||
rm -f "$DESTDIR"/[A-Z]*.py
|
||||
|
||||
# note $SOURCES is unquoted - we want wildcard expansion and multiple args
|
||||
$PROTOB/pb2py "$@" -o "$DESTDIR" $SOURCES
|
||||
}
|
||||
|
||||
do_check() {
|
||||
# rebuild protobuf in tmpdir and check result against specified directory
|
||||
local TMPDIR=$(mktemp -d proto-check.XXXXXX)
|
||||
local DESTDIR="$1"
|
||||
shift
|
||||
|
||||
cp -rT "$DESTDIR" "$TMPDIR"
|
||||
do_rebuild "$TMPDIR" "$@"
|
||||
DIFF=$(diff -ur "$DESTDIR" "$TMPDIR")
|
||||
rm -r "$TMPDIR"
|
||||
if [ -n "$DIFF" ]; then
|
||||
echo "$DIFF"
|
||||
RETURN=1
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" == "--check" ]; then
|
||||
func=do_check
|
||||
else
|
||||
func=do_rebuild
|
||||
fi
|
||||
|
||||
$func core/src/trezor/messages "$CORE_PROTOBUF_SOURCES" --no-init-py
|
||||
$func python/trezorlib/messages "$PYTHON_PROTOBUF_SOURCES" -P ..protobuf
|
||||
|
||||
exit $RETURN
|
Loading…
Reference in New Issue
Block a user