forked from improbable-eng/grpc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotogen_go.sh
executable file
·33 lines (30 loc) · 1.07 KB
/
protogen_go.sh
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
#!/bin/bash
# Generates protobuf Go datastructures from the proto directory.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
PROTOBUF_DIR=${PROTOBUF_DIR-${SCRIPT_DIR}/proto}
PROTOGEN_DIR=go/_proto
GENERATION_DIR=${GENERATION_DIR-${SCRIPT_DIR}/${PROTOGEN_DIR}}
# Builds all .proto files in a given package dirctory.
# NOTE: All .proto files in a given package must be processed *together*, otherwise the self-referencing
# between files in the same proto package will not work.
function proto_build_dir {
DIR_FULL=${1}
DIR_REL=${1##${PROTOBUF_DIR}}
DIR_REL=${DIR_REL#/}
echo -n "protogen_go: $DIR_REL "
mkdir -p ${GENERATION_DIR}/${DIR_REL} 2> /dev/null
PATH=${GOPATH}/bin:$PATH protoc \
-I${PROTOBUF_DIR} \
--go_out=plugins=grpc:${GENERATION_DIR} \
${DIR_FULL}/*.proto || exit $?
echo "DONE"
}
# Generate files for each proto package directory.
for dir in `find -L ${PROTOBUF_DIR} -type d`; do
if [[ "$dir" == ${PROTOGEN_DIR} ]]; then
continue
fi
if [ -n "$(ls $dir/*.proto 2>/dev/null)" ]; then
proto_build_dir ${dir} || exit 1
fi
done