aboutsummaryrefslogtreecommitdiff
path: root/scripts/generate_tensorflow_protobuf.sh
blob: 5fd7c6b4b16b7d8f6b39205e1b95e496ccaf74f2 (plain)
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
#!/bin/sh
#
# Copyright © 2017 Arm Ltd. All rights reserved.
# SPDX-License-Identifier: MIT
#

THIS_SCRIPT=$0
OUTPUT_DIR=$1
PROTOBUF_INSTALL_DIR=$2

usage()
{
  echo
  echo "Usage: ${THIS_SCRIPT} <OUTPUT_DIR> [PROTOBUF_INSTALL_DIR]"
  echo
  echo "  <OUTPUT_DIR> is the location where the generated files will be placed"
  echo "  [PROTOBUF_INSTALL_DIR] the location of the protobuf installation"
  echo
}

if [ "x$OUTPUT_DIR" = "x" ]
then
  usage
  exit 1
fi

mkdir -p ${OUTPUT_DIR}
ERR=$?
if [ $ERR -ne 0 ]
then
  echo
  echo "Cannot create output dir: ${OUTPUT_DIR}"
  echo "mkdir returned: $ERR"
  echo
  usage
  exit 1
fi


if [ "x${PROTOBUF_INSTALL_DIR}" = "x" ]
then
  PROTOBUF_INSTALL_DIR=/usr/local
fi

if [ ! -x "${PROTOBUF_INSTALL_DIR}/bin/protoc" ]
then
  echo
  echo "No usable protocol buffer (protoc) compiler found in ${PROTOBUF_INSTALL_DIR}/bin/"
  echo "You can specify the location of the protobuf installation as the second"
  echo "argument of ${THIS_SCRIPT}."
  usage
  exit 1
fi

OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
#hardware_types.proto and autotuning.proto not required
find tensorflow -type f -name '*.proto' | grep -v autotuning | grep -v hardware_types | while read i; do
  LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH:${PROTOBUF_INSTALL_DIR}/lib $PROTOBUF_INSTALL_DIR/bin/protoc $i \
    --proto_path=. \
    --proto_path=${PROTOBUF_INSTALL_DIR}/include \
    --cpp_out $OUTPUT_DIR
  EXIT_CODE=$?
  if [ $EXIT_CODE -ne 0 ]; then
    echo "Failed to make proto files"
    exit 1
  fi
done