forked from pingcap/kvproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_cpp.sh
executable file
·70 lines (53 loc) · 1.49 KB
/
generate_cpp.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
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
68
69
#!/bin/bash
set -ex
check_protoc_version() {
version=$(protoc --version)
major=$(echo ${version} | sed -n -e 's/.*\([0-9]\{1,\}\)\.[0-9]\{1,\}\.[0-9]\{1,\}.*/\1/p')
minor=$(echo ${version} | sed -n -e 's/.*[0-9]\{1,\}\.\([0-9]\{1,\}\)\.[0-9]\{1,\}.*/\1/p')
if [ "$major" -gt 3 ]; then
return 0
fi
if [ "$major" -eq 3 ] && [ "$minor" -ge 1 ]; then
return 0
fi
echo "protoc version not match, version 3.1.x is needed, current version: ${version}"
return 1
}
push () {
pushd $1 >/dev/null 2>&1
}
pop () {
popd $1 >/dev/null 2>&1
}
cmd_exists () {
which "$1" 1>/dev/null 2>&1
}
if ! check_protoc_version; then
exit 1
fi
echo "generate cpp code..."
KVPROTO_ROOT=`pwd`
GOGO_ROOT=${KVPROTO_ROOT}/_vendor/src/github.com/gogo/protobuf
GRPC_INCLUDE=.:${GOGO_ROOT}:${GOGO_ROOT}/protobuf:../include
rm -rf proto-cpp && mkdir -p proto-cpp
rm -rf cpp/kvproto && mkdir cpp/kvproto
cp proto/* proto-cpp/
function sed_inplace()
{
if [ `uname` == "Darwin" ]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
sed_inplace '/gogo.proto/d' proto-cpp/*
sed_inplace '/option\ (gogoproto/d' proto-cpp/*
sed_inplace -e 's/\[.*gogoproto.*\]//g' proto-cpp/*
push proto-cpp
protoc -I${GRPC_INCLUDE} --cpp_out ../cpp/kvproto *.proto || exit $?
protoc -I${GRPC_INCLUDE} --grpc_out ../cpp/kvproto --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` *.proto || exit $?
pop
push include
protoc -I${GRPC_INCLUDE} --cpp_out ../cpp/kvproto *.proto || exit $?
pop
rm -rf proto-cpp