-
-
Notifications
You must be signed in to change notification settings - Fork 665
/
build_protobuf
executable file
·70 lines (55 loc) · 1.69 KB
/
build_protobuf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
set -e
cd $(dirname $0)/..
PROTOB=common/protob
# Bootloader messages cannot end up in core
CORE_PROTOBUF_SOURCES=$(ls $PROTOB/*.proto | grep -v "bootloader")
# Taking all files for python
PYTHON_PROTOBUF_SOURCES=$PROTOB/*.proto
RETURN=0
do_rebuild() {
local FILE_OR_DIR="$1"
shift
local OUTPUT="$1"
shift
local SOURCES="$1"
shift
if [ "$FILE_OR_DIR" == file ]; then
local param="--outfile"
else
local param="--python-outdir"
fi
# note $SOURCES is unquoted - we want wildcard expansion and multiple args
$PROTOB/pb2py "$@" $param="$OUTPUT" $SOURCES
}
do_check() {
# rebuild protobuf in tmpdir and check result against specified directory
local TMPDIR=$(mktemp -d proto-check.XXXXXX)
trap "rm -r $TMPDIR" RETURN
local FILE_OR_DIR="$1"
shift
local OUTPUT="$1"
shift
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" "$@"
if ! diff -ur --exclude __pycache__ "$OUTPUT" "$TMPDEST"; then
RETURN=1
fi
}
if [ "$1" == "--check" ]; then
func=do_check
else
func=do_rebuild
fi
$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
exit $RETURN