mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
build: generate protobuf messages in tempdir
This way, if the process fails, the files in trezorlib/messages remain untouched. This is important because "setup.py build" now runs the build_protobuf tool, and it can easily fail on a system without protoc.
This commit is contained in:
parent
3f35475e7b
commit
04326749f4
@ -3,30 +3,46 @@ set -e
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# set up paths
|
||||
INDEX="__init__.py"
|
||||
GENPATH="../trezorlib/messages"
|
||||
INDEX="$GENPATH/__init__.py"
|
||||
PROTO_PATH="../vendor/trezor-common/protob"
|
||||
PROTO_FILES="types messages"
|
||||
PB2_OUT="pb2"
|
||||
|
||||
rm -f "$GENPATH/[A-Z]*.py"
|
||||
mkdir -p "$GENPATH"
|
||||
# set up temporary directory & cleanup
|
||||
TMPDIR=$(mktemp -d)
|
||||
function cleanup {
|
||||
rm -r $TMPDIR
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
cat > "$INDEX" << EOF
|
||||
# set up pb2 outdir
|
||||
PB2_OUT="$TMPDIR/pb2"
|
||||
mkdir -p "$PB2_OUT"
|
||||
|
||||
# compile .proto files to python2 modules using google protobuf library
|
||||
for file in $PROTO_FILES; do
|
||||
protoc --python_out="$PB2_OUT" -I/usr/include -I"$PROTO_PATH" "$PROTO_PATH/$file.proto"
|
||||
done
|
||||
|
||||
# create index (__init__.py)
|
||||
cat > "$TMPDIR/$INDEX" << EOF
|
||||
# Automatically generated by pb2py
|
||||
|
||||
EOF
|
||||
|
||||
mkdir -p "$PB2_OUT"
|
||||
|
||||
# convert google protobuf library to trezor's internal format
|
||||
for file in $PROTO_FILES; do
|
||||
# Compile .proto files to python2 modules using google protobuf library
|
||||
protoc --python_out="$PB2_OUT" -I/usr/include -I"$PROTO_PATH" "$PROTO_PATH/$file.proto"
|
||||
./pb2py -P "trezorlib.protobuf" -p "$PB2_OUT" -l "$TMPDIR/$INDEX" "$file" "$TMPDIR"
|
||||
done
|
||||
|
||||
for file in $PROTO_FILES; do
|
||||
# Convert google protobuf library to trezor's internal format
|
||||
./pb2py -P "trezorlib.protobuf" -p "$PB2_OUT" -l "$INDEX" "$file" "$GENPATH"
|
||||
done
|
||||
# ensure $GENPATH exists and is empty of messages
|
||||
mkdir -p "$GENPATH"
|
||||
# only remove messages - there could possibly be other files not starting with capital letter
|
||||
rm -f "$GENPATH"/[A-Z]*.py
|
||||
|
||||
rm -rf "$PB2_OUT"
|
||||
# move generated files to the destination
|
||||
# (this assumes $INDEX is *.py, otherwise we'd have to add $INDEX separately)
|
||||
mv "$TMPDIR"/*.py "$GENPATH"
|
||||
|
||||
# the exit trap handles removing the tmp directory
|
||||
|
Loading…
Reference in New Issue
Block a user