| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #!/usr/bin/env bash
- #
- # Generate all etcd protobuf bindings.
- # Run from repository root.
- #
- set -e
- if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then
- echo "must be run from repository root"
- exit 255
- fi
- # for now, be conservative about what version of protoc we expect
- if ! [[ $(protoc --version) =~ "3.0.0" ]]; then
- echo "could not find protoc 3.0.0, is it installed + in PATH?"
- exit 255
- fi
- # directories containing protos to be built
- DIRS="./wal/walpb ./etcdserver/etcdserverpb ./snap/snappb ./raft/raftpb ./storage/storagepb ./lease/leasepb ./auth/authpb"
- # exact version of protoc-gen-gogo to build
- SHA="c57e439bad574c2e0877ff18d514badcfced004d"
- # set up self-contained GOPATH for building
- export GOPATH=${PWD}/gopath
- export GOBIN=${PWD}/bin
- export PATH="${GOBIN}:${PATH}"
- COREOS_ROOT="${GOPATH}/src/github.com/coreos"
- ETCD_ROOT="${COREOS_ROOT}/etcd"
- GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf"
- GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
- rm -f "${ETCD_ROOT}"
- mkdir -p "${COREOS_ROOT}"
- ln -s "${PWD}" "${ETCD_ROOT}"
- # 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.
- go get github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto}
- go get golang.org/x/tools/cmd/goimports
- pushd "${GOGOPROTO_ROOT}"
- git reset --hard "${SHA}"
- make install
- popd
- for dir in ${DIRS}; do
- pushd ${dir}
- 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)/\1/g" *.pb.go
- sed -i.bak -E 's/github\.com\/coreos\/(errors|fmt|io)/\1/g' *.pb.go
- sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
- sed -i.bak -E 's/import fmt \"fmt\"//g' *.pb.go
- rm -f *.bak
- goimports -w *.pb.go
- popd
- done
- # install protodoc
- # go get -v -u github.com/coreos/protodoc
- #
- # by default, do not run this option.
- # only run when './scripts/genproto.sh -g'
- #
- if [ "$1" = "-g" ]; then
- echo "protodoc is auto-generating Protocol Buffer documentation..."
- go get -v -u github.com/coreos/protodoc
- SHA_PROTODOC="4cd8db83c5595ac514169fda607d1ccb5eef669b"
- PROTODOC_PATH="${GOPATH}/src/github.com/coreos/protodoc"
- pushd "${PROTODOC_PATH}"
- git reset --hard "${SHA_PROTODOC}"
- go install
- echo "protodoc is updated"
- popd
- protodoc --directories="etcdserver/etcdserverpb=service_message,storage/storagepb=service_message,lease/leasepb=service_message,auth/authpb=service_message" \
- --title="etcd API Reference" \
- --output="Documentation/api_reference_v3.md" \
- --message-only-from-this-file="etcdserver/etcdserverpb/rpc.proto"
- echo "protodoc is finished..."
- else
- echo "skipping Protocol Buffer document auto-generation..."
- fi
|