63 lines
2.0 KiB
Makefile
63 lines
2.0 KiB
Makefile
# This makefile can be used to-regenerate the protobuf files.
|
|
#
|
|
# Prerequisites:
|
|
# "protoc" from https://github.com/protocolbuffers/protobuf
|
|
# go get github.com/cockroachdb/protoc-gen-gogoroach
|
|
# go get github.com/gogo/protobuf/types
|
|
# go get github.com/gogo/protobuf/protoc-gen-gogo
|
|
#
|
|
# Note: as of 2021-04-13, we like to use a custom protoc-gen-gogo
|
|
# with additional options, to stabilize the marshalled
|
|
# encoding of objects (so that they are deterministic
|
|
# across marshal/unmarshal cycles) and reduce the memory footprint
|
|
# of objects:
|
|
#
|
|
# vanity.TurnOnStable_MarshalerAll,
|
|
# vanity.TurnOffGoUnrecognizedAll,
|
|
# vanity.TurnOffGoUnkeyedAll,
|
|
# vanity.TurnOffGoSizecacheAll,
|
|
#
|
|
# Until this is resolved, the "go get" commands above are not
|
|
# adequate; instead:
|
|
#
|
|
# 1. set the PATH env var to point to CockroachDB's `bin`
|
|
# sub-directory (after a successful CockroachDB build), where a
|
|
# suitable version of protoc-gen-gogoroach is provided.
|
|
#
|
|
# 2. run `make -f Makefile.update-protos` with this PATH active.
|
|
|
|
export SHELL := env PWD=$(CURDIR) bash
|
|
|
|
PROTOS := $(wildcard \
|
|
errbase/internal/*.proto \
|
|
errorspb/*.proto \
|
|
extgrpc/*.proto \
|
|
exthttp/*.proto \
|
|
grpc/*.proto \
|
|
markers/internal/*.proto \
|
|
)
|
|
GO_SOURCES = $(PROTOS:.proto=.pb.go)
|
|
|
|
SED = sed
|
|
SED_INPLACE := $(shell $(SED) --version 2>&1 | grep -q GNU && echo -i || echo "-i ''")
|
|
|
|
all: $(PROTOS)
|
|
set -e; for dir in $(sort $(dir $(PROTOS))); do \
|
|
protoc \
|
|
-I. \
|
|
-I$$GOPATH/src/ \
|
|
-I$$GOPATH/src/github.com \
|
|
-I$$GOPATH/src/github.com/cockroachdb/errors \
|
|
-I$$GOPATH/src/github.com/gogo/protobuf \
|
|
-I$$GOPATH/src/github.com/gogo/protobuf/protobuf \
|
|
--gogoroach_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,plugins=grpc,import_prefix=:. \
|
|
$$dir/*.proto; \
|
|
done
|
|
$(SED) $(SED_INPLACE) -E \
|
|
-e '/import _ /d' \
|
|
-e 's!import (fmt|math) "github.com/(fmt|math)"! !g' \
|
|
-e 's!github.com/((bytes|encoding/binary|errors|fmt|io|math|github\.com|(google\.)?golang\.org)([^a-z]|$$))!\1!g' \
|
|
-e 's!golang.org/x/net/context!context!g' \
|
|
$(GO_SOURCES)
|
|
gofmt -s -w $(GO_SOURCES)
|