Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix protobuf regeneration script. #5291

Merged
merged 7 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions protos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
# limitations under the License.
#

PROTO_PATH := ${GOPATH}/src:.
PROTO_PATH := ${PROTO_PATH}:${GOPATH}/src/github.com/dgraph-io/dgraph
PROTO_PATH := ${PROTO_PATH}:${GOPATH}/src/github.com/dgraph-io/dgo/protos
PROTO_PATH := ${PROTO_PATH}:${GOPATH}/src/github.com/dgraph-io/badger/pb
DGO_PATH := github.com/dgraph-io/dgo/v200
BADGER_PATH := github.com/dgraph-io/badger/v2
GOGO_PATH := github.com/gogo/protobuf

TMPDIR := $(shell mktemp -d)
PROTO_PATH := ${TMPDIR}/src:.
PROTO_PATH := ${PROTO_PATH}:${TMPDIR}/src/${DGO_PATH}/protos
PROTO_PATH := ${PROTO_PATH}:${TMPDIR}/src/${BADGER_PATH}/pb

.PHONY: help
help:
Expand All @@ -30,21 +34,25 @@ clean:
.PHONY: check
check:
@./depcheck.sh && \
(echo "Upgrading proto libraries before regenerating." ; \
GO111MODULE=off go get -u github.com/golang/protobuf/protoc-gen-go ; \
GO111MODULE=off go get -u github.com/gogo/protobuf/protoc-gen-gofast)
(echo "Installing proto libraries to versions in go.mod." ; \
go install github.com/golang/protobuf/protoc-gen-go ; \
go install github.com/gogo/protobuf/protoc-gen-gofast)

.PHONY: copy-protos
copy-protos:
@mkdir -p ${TMPDIR}/src/${DGO_PATH}/protos
@mkdir -p ${TMPDIR}/src/${BADGER_PATH}/pb
@mkdir -p ${TMPDIR}/src/${GOGO_PATH}/gogoproto
@cp $(shell go list -m -f "{{.Dir}}" ${BADGER_PATH})/pb/pb.proto ${TMPDIR}/src/${BADGER_PATH}/pb/pb.proto
@cp $(shell go list -m -f "{{.Dir}}" ${DGO_PATH})/protos/api.proto ${TMPDIR}/src/${DGO_PATH}/protos/api.proto
@cp $(shell go list -m -f "{{.Dir}}" ${GOGO_PATH})/gogoproto/gogo.proto ${TMPDIR}/src/${GOGO_PATH}/gogoproto/gogo.proto

.PHONY: regenerate
regenerate: check clean
# These sed replacements are necessary to use Badger v2 via Go modules.
# The protoc tool doesn't recognize Go module import paths, so we need to
# specify the filesystem-level import path (without "v2") to generate the
# protos and then set "v2" in the generated code (pb/pb.pb.go).
@sed -i'' -e 's;github.com/dgraph-io/badger/v2/pb/pb.proto;github.com/dgraph-io/badger/pb/pb.proto;' pb.proto
regenerate: copy-protos check clean
@protoc \
--proto_path=/usr/local/include \
--proto_path=${PROTO_PATH} \
--gofast_out=plugins=grpc,Mapi.proto=github.com/dgraph-io/dgo/v200/protos/api:pb \
--gofast_out=plugins=grpc,Mapi.proto=${DGO_PATH}/protos/api:pb \
pb.proto
@sed -i'' -e 's;github.com/dgraph-io/badger/pb/pb.proto;github.com/dgraph-io/badger/v2/pb/pb.proto;' pb.proto
@sed -i'' -e 's;github.com/dgraph-io/badger/pb;github.com/dgraph-io/badger/v2/pb;' pb/pb.pb.go
@rm -rf ${TMPDIR}
@echo Done.
22 changes: 17 additions & 5 deletions protos/depcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

readonly PROTOCMINVER="3.6.1"

which protoc &>/dev/null || (echo "Error: protoc not found" ; exit 1)
which protoc &>/dev/null || (echo "Error: protoc not found" >&2; exit 1)

PROTOCVER=`protoc --version | awk '{printf $2}'`

Expand All @@ -14,22 +14,34 @@ function CompareSemVer() {
local minver=(${1//./ })
local curver=(${2//./ })

echo "Checking for semantic version $1 or newer"
echo -n "Checking protoc for semantic version $1 or newer... "

for i in 0 1 2; do
if [ ${minver[$i]} -gt ${curver[$i]} ]; then
echo "Error: version $2 is lower than the required version $1"
echo "FAIL" >&2
echo "Error: version $2 is lower than the required version $1" >&2
exit 1
elif [ ${curver[$i]} -gt ${minver[$i]} ]; then
break
fi
done
}

CompareSemVer $PROTOCMINVER $PROTOCVER
function CheckProtobufIncludes() {
echo -n "Checking for directory /usr/local/include/google/protobuf... "
if [ ! -d /usr/local/include/google/protobuf ]; then
echo "FAIL" >&2
echo "Missing protobuf types in /usr/local/include/google/protobuf: directory not found" >&2
echo "Download and install protoc and the protobuf types from protobuf releases page:" >&2
echo "https://github.com/protocolbuffers/protobuf/releases/" >&2
exit 1
fi
}

# TODO: check proto api versions
CompareSemVer $PROTOCMINVER $PROTOCVER
echo "OK"

CheckProtobufIncludes
echo "OK"

exit 0
Loading