2019-09-12 13:42:04 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-05-16 11:28:20 +00:00
|
|
|
cd $(dirname $0)/..
|
|
|
|
|
|
|
|
PROTOB=common/protob
|
|
|
|
|
|
|
|
CORE_PROTOBUF_SOURCES="\
|
|
|
|
$PROTOB/messages.proto \
|
2019-07-31 15:02:41 +00:00
|
|
|
$PROTOB/messages-binance.proto \
|
2019-05-16 11:28:20 +00:00
|
|
|
$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-management.proto \
|
|
|
|
$PROTOB/messages-monero.proto \
|
|
|
|
$PROTOB/messages-nem.proto \
|
|
|
|
$PROTOB/messages-ripple.proto \
|
|
|
|
$PROTOB/messages-stellar.proto \
|
|
|
|
$PROTOB/messages-tezos.proto \
|
2019-09-01 20:54:34 +00:00
|
|
|
$PROTOB/messages-webauthn.proto \
|
2019-05-16 11:28:20 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
PYTHON_PROTOBUF_SOURCES=$PROTOB/*.proto
|
|
|
|
|
2019-07-01 13:52:36 +00:00
|
|
|
CORE_MESSAGES_IGNORE="\
|
|
|
|
CosiCommit \
|
|
|
|
CosiCommitment \
|
|
|
|
CosiSign \
|
|
|
|
CosiSignature \
|
|
|
|
DebugLinkFlashErase \
|
|
|
|
DebugLinkLog \
|
|
|
|
DebugLinkMemory \
|
|
|
|
DebugLinkMemoryRead \
|
|
|
|
DebugLinkMemoryWrite \
|
|
|
|
DebugLinkStop \
|
|
|
|
NEMDecryptMessage \
|
|
|
|
NEMDecryptedMessage \
|
|
|
|
PinMatrixAck \
|
|
|
|
PinMatrixRequest \
|
|
|
|
PinMatrixRequestType \
|
|
|
|
WordAck \
|
|
|
|
WordRequest \
|
|
|
|
WordRequestType \
|
|
|
|
"
|
|
|
|
|
|
|
|
PYTHON_MESSAGES_IGNORE=""
|
|
|
|
|
2019-05-16 11:28:20 +00:00
|
|
|
RETURN=0
|
|
|
|
|
|
|
|
do_rebuild() {
|
2021-03-23 12:31:34 +00:00
|
|
|
local FILE_OR_DIR="$1"
|
2019-05-16 11:28:20 +00:00
|
|
|
shift
|
2021-03-23 12:31:34 +00:00
|
|
|
local OUTPUT="$1"
|
2019-07-01 13:52:36 +00:00
|
|
|
shift
|
2021-03-23 12:31:34 +00:00
|
|
|
local SOURCES="$1"
|
2019-08-26 12:50:11 +00:00
|
|
|
shift
|
2019-05-16 11:28:20 +00:00
|
|
|
|
2021-03-23 12:31:34 +00:00
|
|
|
if [ "$FILE_OR_DIR" == file ]; then
|
|
|
|
local param="--outfile"
|
|
|
|
else
|
|
|
|
local param="--python-outdir"
|
2019-08-26 12:50:11 +00:00
|
|
|
fi
|
|
|
|
|
2021-03-23 12:31:34 +00:00
|
|
|
# note $SOURCES is unquoted - we want wildcard expansion and multiple args
|
|
|
|
$PROTOB/pb2py "$@" $param="$OUTPUT" $SOURCES
|
2019-05-16 11:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_check() {
|
|
|
|
# rebuild protobuf in tmpdir and check result against specified directory
|
|
|
|
local TMPDIR=$(mktemp -d proto-check.XXXXXX)
|
2021-03-23 12:31:34 +00:00
|
|
|
|
|
|
|
local FILE_OR_DIR="$1"
|
|
|
|
shift
|
|
|
|
local OUTPUT="$1"
|
2019-05-16 11:28:20 +00:00
|
|
|
shift
|
|
|
|
|
2021-03-23 12:31:34 +00:00
|
|
|
if [ "$FILE_OR_DIR" == file ]; then
|
|
|
|
local TMPDEST="$TMPDIR/testfile"
|
|
|
|
else
|
|
|
|
cp -rT "$OUTPUT" "$TMPDIR"
|
|
|
|
local TMPDEST="$TMPDIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
do_rebuild "$FILE_OR_DIR" "$TMPDEST" "$@"
|
|
|
|
DIFF=$(diff -ur --exclude __pycache__ "$OUTPUT" "$TMPDEST")
|
2019-05-16 11:28:20 +00:00
|
|
|
rm -r "$TMPDIR"
|
|
|
|
if [ -n "$DIFF" ]; then
|
|
|
|
echo "$DIFF"
|
|
|
|
RETURN=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" == "--check" ]; then
|
|
|
|
func=do_check
|
|
|
|
else
|
|
|
|
func=do_rebuild
|
|
|
|
fi
|
|
|
|
|
2021-03-23 12:31:34 +00:00
|
|
|
$func dir core/src/trezor/enums "$CORE_PROTOBUF_SOURCES"
|
|
|
|
$func file core/src/trezor/enums/__init__.py "$CORE_PROTOBUF_SOURCES" --template=core/src/trezor/enums/_proto_init.mako
|
|
|
|
$func file core/src/trezor/messages.py "$CORE_PROTOBUF_SOURCES" --template=core/src/trezor/_proto_messages.mako
|
|
|
|
|
|
|
|
$func file python/src/trezorlib/messages.py "$PYTHON_PROTOBUF_SOURCES" \
|
|
|
|
--template=python/src/trezorlib/_proto_messages.mako \
|
|
|
|
--include-deprecated
|
2019-05-16 11:28:20 +00:00
|
|
|
|
|
|
|
exit $RETURN
|