proto_gen_go.sh 1.1 KB
Newer Older
1
#!/usr/bin/env bash
Z
zhenshan.cao 已提交
2
SCRIPTS_DIR=$(dirname "$0")
3

Z
zhenshan.cao 已提交
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
while getopts "p:h" arg; do
  case $arg in
  p)
    protoc=$(readlink -f "${OPTARG}")
    ;;
    h) # help
    echo "

parameter:
-p: protoc path default("protoc")
-h: help

usage:
./build.sh -p protoc [-h]
                "
    exit 0
    ;;
  ?)
    echo "ERROR! unknown argument"
    exit 1
    ;;
  esac
done


29
PROTO_DIR=$SCRIPTS_DIR/../internal/proto/
Z
zhenshan.cao 已提交
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

PROGRAM=$(basename "$0")
GOPATH=$(go env GOPATH)

if [ -z $GOPATH ]; then
    printf "Error: the environment variable GOPATH is not set, please set it before running %s\n" $PROGRAM > /dev/stderr
    exit 1
fi

export PATH=${GOPATH}/bin:$PATH
echo `which protoc-gen-go`


# Although eraftpb.proto is copying from raft-rs, however there is no
# official go code ship with the crate, so we need to generate it manually.
pushd ${PROTO_DIR}

PB_FILES=("message.proto" "master.proto")

ret=0

function gen_pb() {
    base_name=$(basename $1 ".proto")
    mkdir -p ./$base_name
    ${protoc} --go_out=plugins=grpc,paths=source_relative:./$base_name $1 || ret=$?
  }

for file in ${PB_FILES[@]}
    do
    echo $file
    gen_pb $file
done

popd

exit $ret