1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 09:28:13 +00:00
trezor-firmware/tools/build_protobuf
matejcik 67b879ac07 python: restructure package
This deserves some explanation.

* tests were moved to separate python/tests subdir
* trezorlib was moved to python/src, so that it does not exist on
PYTHONPATH by default
(see https://blog.ionelmc.ro/2014/05/25/python-packaging/ for details)
* everything was updated to understand the new structure
* trezorctl was changed from a top-level executable script to a module
`trezorlib.cli.trezorctl` and is installed via the entry_points
mechanism.
This should make it work normally on Windows!

The package should be installable as normal through pip and pipenv, no
changes are needed on that side.

The source package from pypi will include unit tests. (Device tests were
completely moved out). Wheel will exclude them, because users don't need
them.
That shrinks the .whl from 520 kB to 270 - nice!

python: reorganize remaining unit tests
2019-08-12 12:57:25 +02:00

99 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
cd $(dirname $0)/..
PROTOB=common/protob
CORE_PROTOBUF_SOURCES="\
$PROTOB/messages.proto \
$PROTOB/messages-binance.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
CORE_MESSAGES_IGNORE="\
CosiCommit \
CosiCommitment \
CosiSign \
CosiSignature \
DebugLinkFlashErase \
DebugLinkLog \
DebugLinkMemory \
DebugLinkMemoryRead \
DebugLinkMemoryWrite \
DebugLinkStop \
NEMDecryptMessage \
NEMDecryptedMessage \
PinMatrixAck \
PinMatrixRequest \
PinMatrixRequestType \
WordAck \
WordRequest \
WordRequestType \
"
PYTHON_MESSAGES_IGNORE=""
RETURN=0
do_rebuild() {
# rebuild protobuf in specified directory
local DESTDIR="$1"
shift
local SOURCES="$1"
shift
local IGNORE="$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
# delete unused messages
for F in $IGNORE; do
rm -f "$DESTDIR"/"$F".py
done
}
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" "$CORE_MESSAGES_IGNORE" --no-init-py
$func python/src/trezorlib/messages "$PYTHON_PROTOBUF_SOURCES" "$PYTHON_MESSAGES_IGNORE" -P ..protobuf
exit $RETURN