2015-07-21 02:32:42 +03:00
|
|
|
#!/usr/bin/env bash
|
2014-09-24 23:19:18 +04:00
|
|
|
#
|
|
|
|
# Generate all etcd protobuf bindings.
|
|
|
|
# Run from repository root.
|
|
|
|
#
|
2015-07-21 02:32:42 +03:00
|
|
|
set -e
|
2014-09-24 23:19:18 +04:00
|
|
|
|
2015-11-06 18:13:24 +03:00
|
|
|
if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then
|
|
|
|
echo "must be run from repository root"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2014-10-14 11:35:28 +04:00
|
|
|
PREFIX="github.com/coreos/etcd/Godeps/_workspace/src"
|
2015-07-01 01:13:21 +03:00
|
|
|
DIRS="./wal/walpb ./etcdserver/etcdserverpb ./snap/snappb ./raft/raftpb ./storage/storagepb"
|
2014-09-24 23:19:18 +04:00
|
|
|
|
2015-09-04 01:32:25 +03:00
|
|
|
SHA="932b70afa8b0bf4a8e167fdf0c3367cebba45903"
|
2014-09-24 23:19:18 +04:00
|
|
|
|
|
|
|
if ! protoc --version > /dev/null; then
|
|
|
|
echo "could not find protoc, is it installed + in PATH?"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure we have the right version of protoc-gen-gogo by building it every time.
|
|
|
|
# TODO(jonboulle): vendor this instead of `go get`ting it.
|
|
|
|
export GOPATH=${PWD}/gopath
|
|
|
|
export GOBIN=${PWD}/bin
|
2015-03-25 20:02:00 +03:00
|
|
|
go get github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto}
|
|
|
|
pushd ${GOPATH}/src/github.com/gogo/protobuf/
|
2014-09-24 23:19:18 +04:00
|
|
|
git reset --hard ${SHA}
|
2015-09-03 19:57:59 +03:00
|
|
|
make install
|
2014-09-24 23:19:18 +04:00
|
|
|
popd
|
|
|
|
|
|
|
|
export PATH="${GOBIN}:${PATH}"
|
|
|
|
|
2015-06-30 04:59:24 +03:00
|
|
|
# copy all proto dependencies inside etcd to gopath
|
2015-07-21 02:32:42 +03:00
|
|
|
for dir in ${DIRS}; do
|
2015-06-30 04:59:24 +03:00
|
|
|
mkdir -p ${GOPATH}/src/github.com/coreos/etcd/${dir}
|
|
|
|
pushd ${dir}
|
|
|
|
cp *.proto ${GOPATH}/src/github.com/coreos/etcd/${dir}
|
|
|
|
popd
|
|
|
|
done
|
|
|
|
|
2015-09-03 19:57:59 +03:00
|
|
|
COREOS_ROOT="${GOPATH}/src/github.com/coreos"
|
|
|
|
GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf"
|
|
|
|
GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
|
|
|
|
|
|
|
|
ESCAPED_PREFIX=$(echo $PREFIX | sed -e 's/[\/&]/\\&/g')
|
|
|
|
|
2014-09-24 23:19:18 +04:00
|
|
|
for dir in ${DIRS}; do
|
|
|
|
pushd ${dir}
|
2015-09-03 19:57:59 +03:00
|
|
|
protoc --gogofast_out=plugins=grpc,import_prefix=github.com/coreos/:. -I=.:"${GOGOPROTO_PATH}":"${COREOS_ROOT}" *.proto
|
|
|
|
sed -i.bak -E "s/github\.com\/coreos\/(gogoproto|github\.com|golang\.org|google\.golang\.org)/${ESCAPED_PREFIX}\/\1/g" *.pb.go
|
|
|
|
sed -i.bak -E 's/github\.com\/coreos\/(errors|fmt|io)/\1/g' *.pb.go
|
2014-09-24 23:19:18 +04:00
|
|
|
rm -f *.bak
|
|
|
|
popd
|
|
|
|
done
|