diff --git a/tools/build_protobuf b/tools/build_protobuf index e46db4c559..8a30407ed6 100755 --- a/tools/build_protobuf +++ b/tools/build_protobuf @@ -1,24 +1,31 @@ #!/bin/bash -CURDIR=$(pwd) -mkdir -p $CURDIR/pb2/ +set -e -mkdir -p ../trezorlib/messages +cd "$(dirname "$0")" -INDEX=../trezorlib/messages/__init__.py -rm -f $INDEX -echo '# Automatically generated by pb2py' >> $INDEX -echo '' >> $INDEX +GENPATH="../trezorlib/messages" +INDEX="$GENPATH/__init__.py" +PROTO_PATH="../../trezor-common/protob" +PROTO_FILES=(types messages storage) +PB2_OUT="pb2" -for i in types messages storage ; do +mkdir -p "$GENPATH" + +cat > "$INDEX" << EOF +# Automatically generated by pb2py + +EOF + +mkdir -p "$PB2_OUT" + +for file in "${PROTO_FILES[@]}"; do # Compile .proto files to python2 modules using google protobuf library - cd $CURDIR/../../trezor-common/protob - protoc --python_out=$CURDIR/pb2/ -I/usr/include -I. $i.proto + protoc --python_out="$PB2_OUT" -I"$PROTO_PATH" "$file.proto" done -for i in types messages storage ; do +for file in "${PROTO_FILES[@]}"; do # Convert google protobuf library to trezor's internal format - cd $CURDIR - ./pb2py -P "trezorlib.protobuf" -p $CURDIR/pb2 -l $INDEX $i ../trezorlib/messages/ + ./pb2py -P "trezorlib.protobuf" -p "$PB2_OUT" -l "$INDEX" "$file" "$GENPATH" done -rm -rf $CURDIR/pb2/ +rm -rf "$PB2_OUT"