Yuchen Zeng | c84ed68 | 2016-05-04 16:30:11 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Yuchen Zeng | 0333a49 | 2016-05-04 19:14:10 -0700 | [diff] [blame] | 2 | |
| 3 | # Copyright 2016, Google Inc. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are |
| 8 | # met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above |
| 13 | # copyright notice, this list of conditions and the following disclaimer |
| 14 | # in the documentation and/or other materials provided with the |
| 15 | # distribution. |
| 16 | # * Neither the name of Google Inc. nor the names of its |
| 17 | # contributors may be used to endorse or promote products derived from |
| 18 | # this software without specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
Yuchen Zeng | c84ed68 | 2016-05-04 16:30:11 -0700 | [diff] [blame] | 32 | PROTO_DIR="src/proto/grpc/reflection/v1alpha" |
| 33 | PROTO_FILE="reflection" |
Yuchen Zeng | 0601df3 | 2016-06-06 13:08:06 -0700 | [diff] [blame] | 34 | HEADER_DIR="include/grpc++/ext" |
| 35 | SRC_DIR="src/cpp/ext" |
| 36 | INCLUDE_DIR="grpc++/ext" |
Yuchen Zeng | c84ed68 | 2016-05-04 16:30:11 -0700 | [diff] [blame] | 37 | TMP_DIR="tmp" |
| 38 | GRPC_PLUGIN="bins/opt/grpc_cpp_plugin" |
Yuchen Zeng | ea09adc | 2016-05-31 10:50:24 -0700 | [diff] [blame] | 39 | PROTOC=third_party/protobuf/src/protoc |
Yuchen Zeng | c84ed68 | 2016-05-04 16:30:11 -0700 | [diff] [blame] | 40 | |
| 41 | set -e |
| 42 | |
| 43 | TMP_DIR=${TMP_DIR}_${PROTO_FILE} |
| 44 | |
| 45 | cd $(dirname $0)/../../.. |
| 46 | |
| 47 | [ ! -d $HEADER_DIR ] && mkdir -p $HEADER_DIR || : |
| 48 | [ ! -d $SRC_DIR ] && mkdir -p $SRC_DIR || : |
| 49 | [ ! -d $TMP_DIR ] && mkdir -p $TMP_DIR || : |
| 50 | |
| 51 | $PROTOC -I$PROTO_DIR --cpp_out=$TMP_DIR ${PROTO_DIR}/${PROTO_FILE}.proto |
| 52 | $PROTOC -I$PROTO_DIR --grpc_out=$TMP_DIR --plugin=protoc-gen-grpc=${GRPC_PLUGIN} ${PROTO_DIR}/${PROTO_FILE}.proto |
| 53 | |
| 54 | sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.pb.cc |
Yuchen Zeng | 0333a49 | 2016-05-04 19:14:10 -0700 | [diff] [blame] | 55 | sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.h |
Yuchen Zeng | c84ed68 | 2016-05-04 16:30:11 -0700 | [diff] [blame] | 56 | sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc |
| 57 | sed -i "s/\"${PROTO_FILE}.grpc.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.grpc.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc |
Yuchen Zeng | 0333a49 | 2016-05-04 19:14:10 -0700 | [diff] [blame] | 58 | |
| 59 | /bin/cp LICENSE ${TMP_DIR}/TMP_LICENSE |
| 60 | sed -i -e "s/./ &/" -e "s/.*/ \*&/" ${TMP_DIR}/TMP_LICENSE |
| 61 | sed -i -r "\$a\ *\n *\/\n\n" ${TMP_DIR}/TMP_LICENSE |
| 62 | |
| 63 | sed -i -e "1s/^/ *\n/" -e "1s/^/\/*\n/" ${TMP_DIR}/*.pb.h |
| 64 | sed -i -e "1s/^/ *\n/" -e "1s/^/\/*\n/" ${TMP_DIR}/*.pb.cc |
| 65 | |
| 66 | sed -i "2r ${TMP_DIR}/TMP_LICENSE" ${TMP_DIR}/*.pb.h |
| 67 | sed -i "2r ${TMP_DIR}/TMP_LICENSE" ${TMP_DIR}/*.pb.cc |
Yuchen Zeng | c84ed68 | 2016-05-04 16:30:11 -0700 | [diff] [blame] | 68 | |
| 69 | /bin/mv ${TMP_DIR}/${PROTO_FILE}.pb.h ${HEADER_DIR} |
| 70 | /bin/mv ${TMP_DIR}/${PROTO_FILE}.grpc.pb.h ${HEADER_DIR} |
| 71 | /bin/mv ${TMP_DIR}/${PROTO_FILE}.pb.cc ${SRC_DIR} |
| 72 | /bin/mv ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc ${SRC_DIR} |
| 73 | /bin/rm -r $TMP_DIR |