blob: 45a1a9f4ec10fb78154a08e51d5eb4814bf32b10 [file] [log] [blame]
Yuchen Zengc84ed682016-05-04 16:30:11 -07001#!/bin/bash
Yuchen Zeng0333a492016-05-04 19:14:10 -07002
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 Zengc84ed682016-05-04 16:30:11 -070032PROTO_DIR="src/proto/grpc/reflection/v1alpha"
33PROTO_FILE="reflection"
Yuchen Zeng0601df32016-06-06 13:08:06 -070034HEADER_DIR="include/grpc++/ext"
35SRC_DIR="src/cpp/ext"
36INCLUDE_DIR="grpc++/ext"
Yuchen Zengc84ed682016-05-04 16:30:11 -070037TMP_DIR="tmp"
38GRPC_PLUGIN="bins/opt/grpc_cpp_plugin"
Yuchen Zengea09adc2016-05-31 10:50:24 -070039PROTOC=third_party/protobuf/src/protoc
Yuchen Zengc84ed682016-05-04 16:30:11 -070040
41set -e
42
43TMP_DIR=${TMP_DIR}_${PROTO_FILE}
44
45cd $(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
54sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.pb.cc
Yuchen Zeng0333a492016-05-04 19:14:10 -070055sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.h
Yuchen Zengc84ed682016-05-04 16:30:11 -070056sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc
57sed -i "s/\"${PROTO_FILE}.grpc.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.grpc.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc
Yuchen Zeng0333a492016-05-04 19:14:10 -070058
59/bin/cp LICENSE ${TMP_DIR}/TMP_LICENSE
60sed -i -e "s/./ &/" -e "s/.*/ \*&/" ${TMP_DIR}/TMP_LICENSE
61sed -i -r "\$a\ *\n *\/\n\n" ${TMP_DIR}/TMP_LICENSE
62
63sed -i -e "1s/^/ *\n/" -e "1s/^/\/*\n/" ${TMP_DIR}/*.pb.h
64sed -i -e "1s/^/ *\n/" -e "1s/^/\/*\n/" ${TMP_DIR}/*.pb.cc
65
66sed -i "2r ${TMP_DIR}/TMP_LICENSE" ${TMP_DIR}/*.pb.h
67sed -i "2r ${TMP_DIR}/TMP_LICENSE" ${TMP_DIR}/*.pb.cc
Yuchen Zengc84ed682016-05-04 16:30:11 -070068
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