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
|
|
|
|
2017-09-06 20:38:08 +03:00
|
|
|
if ! [[ "$0" =~ scripts/genproto.sh ]]; then
|
2015-11-06 18:13:24 +03:00
|
|
|
echo "must be run from repository root"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2019-05-29 00:58:43 +03:00
|
|
|
if [[ $(protoc --version | cut -f2 -d' ') != "3.7.1" ]]; then
|
|
|
|
echo "could not find protoc 3.7.1, is it installed + in PATH?"
|
2015-11-17 01:59:14 +03:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
|
|
|
# directories containing protos to be built
|
2018-05-21 11:27:52 +03:00
|
|
|
DIRS="./wal/walpb ./etcdserver/etcdserverpb ./etcdserver/api/snap/snappb ./raft/raftpb ./mvcc/mvccpb ./lease/leasepb ./auth/authpb ./etcdserver/api/v3lock/v3lockpb ./etcdserver/api/v3election/v3electionpb"
|
2014-09-24 23:19:18 +04:00
|
|
|
|
2019-01-22 19:55:01 +03:00
|
|
|
# disable go mod
|
|
|
|
export GO111MODULE=off
|
|
|
|
|
2017-06-10 19:02:12 +03:00
|
|
|
# exact version of packages to build
|
2018-05-22 23:42:43 +03:00
|
|
|
GOGO_PROTO_SHA="1adfc126b41513cc696b209667c8656ea7aac67c"
|
2018-05-23 14:46:54 +03:00
|
|
|
GRPC_GATEWAY_SHA="92583770e3f01b09a0d3e9bdf64321d8bebd48f2"
|
2017-06-10 19:02:12 +03:00
|
|
|
SCHWAG_SHA="b7d0fc9aadaaae3d61aaadfc12e4a2f945514912"
|
2014-09-24 23:19:18 +04:00
|
|
|
|
2015-11-17 01:59:14 +03:00
|
|
|
# set up self-contained GOPATH for building
|
2016-10-04 00:42:45 +03:00
|
|
|
export GOPATH=${PWD}/gopath.proto
|
2014-09-24 23:19:18 +04:00
|
|
|
export GOBIN=${PWD}/bin
|
|
|
|
export PATH="${GOBIN}:${PATH}"
|
|
|
|
|
2018-08-29 03:32:43 +03:00
|
|
|
ETCD_IO_ROOT="${GOPATH}/src/go.etcd.io"
|
|
|
|
ETCD_ROOT="${ETCD_IO_ROOT}/etcd"
|
2015-09-03 19:57:59 +03:00
|
|
|
GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf"
|
2017-06-10 19:02:12 +03:00
|
|
|
SCHWAG_ROOT="${GOPATH}/src/github.com/hexfusion/schwag"
|
2015-09-03 19:57:59 +03:00
|
|
|
GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
|
2016-07-15 23:21:41 +03:00
|
|
|
GRPC_GATEWAY_ROOT="${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway"
|
2015-09-03 19:57:59 +03:00
|
|
|
|
2019-07-16 15:00:36 +03:00
|
|
|
function cleanup {
|
|
|
|
# Remove the whole fake GOPATH which can really confuse go mod.
|
|
|
|
rm -rf "${PWD}/gopath.proto"
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2018-08-29 03:32:43 +03:00
|
|
|
mkdir -p "${ETCD_IO_ROOT}"
|
2015-11-17 01:59:14 +03:00
|
|
|
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.
|
2016-05-18 05:35:06 +03:00
|
|
|
go get -u github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto}
|
|
|
|
go get -u golang.org/x/tools/cmd/goimports
|
2015-11-17 01:59:14 +03:00
|
|
|
pushd "${GOGOPROTO_ROOT}"
|
2016-06-17 20:21:18 +03:00
|
|
|
git reset --hard "${GOGO_PROTO_SHA}"
|
2015-11-17 01:59:14 +03:00
|
|
|
make install
|
|
|
|
popd
|
2015-09-03 19:57:59 +03:00
|
|
|
|
2016-06-07 05:49:17 +03:00
|
|
|
# generate gateway code
|
2016-07-15 23:21:41 +03:00
|
|
|
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
|
|
|
|
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
|
2016-06-07 05:49:17 +03:00
|
|
|
pushd "${GRPC_GATEWAY_ROOT}"
|
|
|
|
git reset --hard "${GRPC_GATEWAY_SHA}"
|
|
|
|
go install ./protoc-gen-grpc-gateway
|
|
|
|
popd
|
|
|
|
|
2014-09-24 23:19:18 +04:00
|
|
|
for dir in ${DIRS}; do
|
2017-09-06 20:38:08 +03:00
|
|
|
pushd "${dir}"
|
2018-08-29 03:32:43 +03:00
|
|
|
protoc --gofast_out=plugins=grpc,import_prefix=go.etcd.io/:. -I=".:${GOGOPROTO_PATH}:${ETCD_IO_ROOT}:${GRPC_GATEWAY_ROOT}/third_party/googleapis" ./*.proto
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2018-08-29 03:32:43 +03:00
|
|
|
sed -i.bak -E 's/go\.etcd\.io\/(gogoproto|github\.com|golang\.org|google\.golang\.org)/\1/g' ./*.pb.go
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2018-08-29 03:32:43 +03:00
|
|
|
sed -i.bak -E 's/go\.etcd\.io\/(errors|fmt|io)/\1/g' ./*.pb.go
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2017-09-06 20:38:08 +03:00
|
|
|
sed -i.bak -E 's/import _ \"gogoproto\"//g' ./*.pb.go
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2017-09-06 20:38:08 +03:00
|
|
|
sed -i.bak -E 's/import fmt \"fmt\"//g' ./*.pb.go
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2018-08-29 03:32:43 +03:00
|
|
|
sed -i.bak -E 's/import _ \"go\.etcd\.io\/google\/api\"//g' ./*.pb.go
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2017-09-06 20:38:08 +03:00
|
|
|
sed -i.bak -E 's/import _ \"google\.golang\.org\/genproto\/googleapis\/api\/annotations\"//g' ./*.pb.go
|
|
|
|
rm -f ./*.bak
|
|
|
|
goimports -w ./*.pb.go
|
2014-09-24 23:19:18 +04:00
|
|
|
popd
|
|
|
|
done
|
2016-04-22 02:56:19 +03:00
|
|
|
|
2017-06-02 20:51:49 +03:00
|
|
|
# remove old swagger files so it's obvious whether the files fail to generate
|
|
|
|
rm -rf Documentation/dev-guide/apispec/swagger/*json
|
2017-04-10 23:45:56 +03:00
|
|
|
for pb in etcdserverpb/rpc api/v3lock/v3lockpb/v3lock api/v3election/v3electionpb/v3election; do
|
2017-04-19 08:25:57 +03:00
|
|
|
protobase="etcdserver/${pb}"
|
2017-04-10 23:45:56 +03:00
|
|
|
protoc -I. \
|
2017-09-06 20:38:08 +03:00
|
|
|
-I"${GRPC_GATEWAY_ROOT}"/third_party/googleapis \
|
|
|
|
-I"${GOGOPROTO_PATH}" \
|
2018-08-29 03:32:43 +03:00
|
|
|
-I"${ETCD_IO_ROOT}" \
|
2017-04-10 23:45:56 +03:00
|
|
|
--grpc-gateway_out=logtostderr=true:. \
|
|
|
|
--swagger_out=logtostderr=true:./Documentation/dev-guide/apispec/swagger/. \
|
2017-04-19 08:25:57 +03:00
|
|
|
${protobase}.proto
|
|
|
|
# hack to move gw files around so client won't include them
|
2017-09-06 20:38:08 +03:00
|
|
|
pkgpath=$(dirname "${protobase}")
|
|
|
|
pkg=$(basename "${pkgpath}")
|
2017-04-19 08:25:57 +03:00
|
|
|
gwfile="${protobase}.pb.gw.go"
|
|
|
|
sed -i.bak -E "s/package $pkg/package gw/g" ${gwfile}
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2017-04-19 08:25:57 +03:00
|
|
|
sed -i.bak -E "s/protoReq /&$pkg\./g" ${gwfile}
|
|
|
|
sed -i.bak -E "s/, client /, client $pkg./g" ${gwfile}
|
|
|
|
sed -i.bak -E "s/Client /, client $pkg./g" ${gwfile}
|
|
|
|
sed -i.bak -E "s/[^(]*Client, runtime/${pkg}.&/" ${gwfile}
|
|
|
|
sed -i.bak -E "s/New[A-Za-z]*Client/${pkg}.&/" ${gwfile}
|
|
|
|
# darwin doesn't like newlines in sed...
|
2018-03-22 20:39:31 +03:00
|
|
|
# shellcheck disable=SC1117
|
2018-08-29 03:32:43 +03:00
|
|
|
sed -i.bak -E "s|import \(|& \"go.etcd.io/etcd/${pkgpath}\"|" ${gwfile}
|
2017-09-06 20:38:08 +03:00
|
|
|
mkdir -p "${pkgpath}"/gw/
|
2017-04-19 08:25:57 +03:00
|
|
|
go fmt ${gwfile}
|
2017-09-06 20:38:08 +03:00
|
|
|
mv ${gwfile} "${pkgpath}/gw/"
|
2017-04-19 08:25:57 +03:00
|
|
|
rm -f ./etcdserver/${pb}*.bak
|
2017-09-06 20:38:08 +03:00
|
|
|
swaggerName=$(basename ${pb})
|
2017-04-10 23:45:56 +03:00
|
|
|
mv Documentation/dev-guide/apispec/swagger/etcdserver/${pb}.swagger.json \
|
2017-09-06 20:38:08 +03:00
|
|
|
Documentation/dev-guide/apispec/swagger/"${swaggerName}".swagger.json
|
2017-04-10 23:45:56 +03:00
|
|
|
done
|
|
|
|
rm -rf Documentation/dev-guide/apispec/swagger/etcdserver/
|
2016-04-22 02:56:19 +03:00
|
|
|
|
2017-06-10 19:02:12 +03:00
|
|
|
# append security to swagger spec
|
|
|
|
go get -u "github.com/hexfusion/schwag"
|
|
|
|
pushd "${SCHWAG_ROOT}"
|
|
|
|
git reset --hard "${SCHWAG_SHA}"
|
|
|
|
go install .
|
|
|
|
popd
|
|
|
|
schwag -input=Documentation/dev-guide/apispec/swagger/rpc.swagger.json
|
|
|
|
|
2016-04-22 02:56:19 +03:00
|
|
|
# install protodoc
|
2018-08-29 03:32:43 +03:00
|
|
|
# go get -v -u go.etcd.io/protodoc
|
2016-04-22 02:56:19 +03:00
|
|
|
#
|
2018-02-14 00:42:48 +03:00
|
|
|
# run './scripts/genproto.sh --skip-protodoc'
|
|
|
|
# to skip protodoc generation
|
2016-04-22 02:56:19 +03:00
|
|
|
#
|
2018-02-14 00:42:48 +03:00
|
|
|
if [ "$1" != "--skip-protodoc" ]; then
|
2016-04-23 02:55:00 +03:00
|
|
|
echo "protodoc is auto-generating grpc API reference documentation..."
|
2018-08-29 03:32:43 +03:00
|
|
|
go get -v -u go.etcd.io/protodoc
|
|
|
|
SHA_PROTODOC="484ab544e116302a9a6021cc7c427d334132e94a"
|
|
|
|
PROTODOC_PATH="${GOPATH}/src/go.etcd.io/protodoc"
|
2016-04-22 02:56:19 +03:00
|
|
|
pushd "${PROTODOC_PATH}"
|
|
|
|
git reset --hard "${SHA_PROTODOC}"
|
|
|
|
go install
|
|
|
|
echo "protodoc is updated"
|
|
|
|
popd
|
|
|
|
|
2018-02-26 22:13:43 +03:00
|
|
|
protodoc --directories="etcdserver/etcdserverpb=service_message,mvcc/mvccpb=service_message,lease/leasepb=service_message,auth/authpb=service_message" \
|
2016-04-22 05:58:41 +03:00
|
|
|
--title="etcd API Reference" \
|
2016-04-23 02:55:00 +03:00
|
|
|
--output="Documentation/dev-guide/api_reference_v3.md" \
|
2016-06-16 21:57:05 +03:00
|
|
|
--message-only-from-this-file="etcdserver/etcdserverpb/rpc.proto" \
|
|
|
|
--disclaimer="This is a generated documentation. Please read the proto files for more."
|
2016-04-22 02:56:19 +03:00
|
|
|
|
2018-02-26 22:13:43 +03:00
|
|
|
protodoc --directories="etcdserver/api/v3lock/v3lockpb=service_message,etcdserver/api/v3election/v3electionpb=service_message,mvcc/mvccpb=service_message" \
|
2017-04-10 23:45:56 +03:00
|
|
|
--title="etcd concurrency API Reference" \
|
|
|
|
--output="Documentation/dev-guide/api_concurrency_reference_v3.md" \
|
|
|
|
--disclaimer="This is a generated documentation. Please read the proto files for more."
|
|
|
|
|
2016-04-22 02:56:19 +03:00
|
|
|
echo "protodoc is finished..."
|
|
|
|
else
|
2016-04-23 02:55:00 +03:00
|
|
|
echo "skipping grpc API reference document auto-generation..."
|
2016-04-22 02:56:19 +03:00
|
|
|
fi
|