2017-07-06 12:38:40 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Generate all protobuf bindings.
|
|
|
|
# Run from repository root.
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
|
|
|
|
if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then
|
|
|
|
echo "must be run from repository root"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2020-07-27 09:08:38 +00:00
|
|
|
if ! [[ $(protoc --version) =~ "3.12.3" ]]; then
|
|
|
|
echo "could not find protoc 3.12.3, is it installed + in PATH?"
|
2017-07-06 12:38:40 +00:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2018-09-05 19:04:44 +00:00
|
|
|
echo "installing plugins"
|
2019-01-15 14:32:05 +00:00
|
|
|
GO111MODULE=on go mod download
|
2018-09-05 19:04:44 +00:00
|
|
|
|
2019-01-15 14:32:05 +00:00
|
|
|
INSTALL_PKGS="golang.org/x/tools/cmd/goimports github.com/gogo/protobuf/protoc-gen-gogofast github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger"
|
|
|
|
for pkg in ${INSTALL_PKGS}; do
|
2020-10-08 07:38:28 +00:00
|
|
|
GO111MODULE=on go install "$pkg"
|
2019-01-15 14:32:05 +00:00
|
|
|
done
|
2018-09-05 19:04:44 +00:00
|
|
|
|
2019-01-15 14:32:05 +00:00
|
|
|
PROM_ROOT="${PWD}"
|
2017-07-06 12:38:40 +00:00
|
|
|
PROM_PATH="${PROM_ROOT}/prompb"
|
2020-07-27 09:08:38 +00:00
|
|
|
GOGOPROTO_ROOT="$(GO111MODULE=on go list -mod=readonly -f '{{ .Dir }}' -m github.com/gogo/protobuf)"
|
2017-07-06 12:38:40 +00:00
|
|
|
GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
|
2020-07-27 09:08:38 +00:00
|
|
|
GRPC_GATEWAY_ROOT="$(GO111MODULE=on go list -mod=readonly -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)"
|
2017-07-06 12:38:40 +00:00
|
|
|
|
|
|
|
DIRS="prompb"
|
|
|
|
|
2019-01-15 14:32:05 +00:00
|
|
|
echo "generating code"
|
2017-07-06 12:38:40 +00:00
|
|
|
for dir in ${DIRS}; do
|
|
|
|
pushd ${dir}
|
2018-03-01 09:57:31 +00:00
|
|
|
protoc --gogofast_out=plugins=grpc:. -I=. \
|
2017-07-06 12:38:40 +00:00
|
|
|
-I="${GOGOPROTO_PATH}" \
|
|
|
|
-I="${PROM_PATH}" \
|
|
|
|
-I="${GRPC_GATEWAY_ROOT}/third_party/googleapis" \
|
2019-01-15 14:32:05 +00:00
|
|
|
./*.proto
|
2017-07-06 12:38:40 +00:00
|
|
|
|
2019-01-15 14:32:05 +00:00
|
|
|
sed -i.bak -E 's/import _ \"github.com\/gogo\/protobuf\/gogoproto\"//g' -- *.pb.go
|
|
|
|
sed -i.bak -E 's/import _ \"google\/protobuf\"//g' -- *.pb.go
|
2019-04-04 09:55:32 +00:00
|
|
|
sed -i.bak -E 's/\t_ \"google\/protobuf\"//g' -- *.pb.go
|
2020-02-17 21:13:33 +00:00
|
|
|
sed -i.bak -E 's/golang\/protobuf\/descriptor/gogo\/protobuf\/protoc-gen-gogo\/descriptor/g' -- *.go
|
2019-01-15 14:32:05 +00:00
|
|
|
sed -i.bak -E 's/golang\/protobuf/gogo\/protobuf/g' -- *.go
|
|
|
|
rm -f -- *.bak
|
2020-02-17 21:13:33 +00:00
|
|
|
goimports -w ./*.go
|
2017-07-06 12:38:40 +00:00
|
|
|
popd
|
|
|
|
done
|