2017-07-06 05:38:40 -07: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 02:08:38 -07:00
|
|
|
if ! [[ $(protoc --version) =~ "3.12.3" ]]; then
|
|
|
|
echo "could not find protoc 3.12.3, is it installed + in PATH?"
|
2017-07-06 05:38:40 -07:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2018-09-05 12:04:44 -07:00
|
|
|
echo "installing plugins"
|
2019-01-15 06:32:05 -08:00
|
|
|
GO111MODULE=on go mod download
|
2018-09-05 12:04:44 -07:00
|
|
|
|
2019-01-15 06:32:05 -08: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
|
|
|
|
GO111MODULE=on go install -mod=vendor "$pkg"
|
|
|
|
done
|
2018-09-05 12:04:44 -07:00
|
|
|
|
2019-01-15 06:32:05 -08:00
|
|
|
PROM_ROOT="${PWD}"
|
2017-07-06 05:38:40 -07:00
|
|
|
PROM_PATH="${PROM_ROOT}/prompb"
|
2020-07-27 02:08:38 -07:00
|
|
|
GOGOPROTO_ROOT="$(GO111MODULE=on go list -mod=readonly -f '{{ .Dir }}' -m github.com/gogo/protobuf)"
|
2017-07-06 05:38:40 -07:00
|
|
|
GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
|
2020-07-27 02:08:38 -07:00
|
|
|
GRPC_GATEWAY_ROOT="$(GO111MODULE=on go list -mod=readonly -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)"
|
2017-07-06 05:38:40 -07:00
|
|
|
|
|
|
|
DIRS="prompb"
|
|
|
|
|
2019-01-15 06:32:05 -08:00
|
|
|
echo "generating code"
|
2017-07-06 05:38:40 -07:00
|
|
|
for dir in ${DIRS}; do
|
|
|
|
pushd ${dir}
|
2018-03-01 01:57:31 -08:00
|
|
|
protoc --gogofast_out=plugins=grpc:. -I=. \
|
2017-07-06 05:38:40 -07:00
|
|
|
-I="${GOGOPROTO_PATH}" \
|
|
|
|
-I="${PROM_PATH}" \
|
|
|
|
-I="${GRPC_GATEWAY_ROOT}/third_party/googleapis" \
|
2019-01-15 06:32:05 -08:00
|
|
|
./*.proto
|
2017-07-06 05:38:40 -07:00
|
|
|
|
2019-01-15 06:32:05 -08: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 02:55:32 -07:00
|
|
|
sed -i.bak -E 's/\t_ \"google\/protobuf\"//g' -- *.pb.go
|
2020-02-17 13:13:33 -08:00
|
|
|
sed -i.bak -E 's/golang\/protobuf\/descriptor/gogo\/protobuf\/protoc-gen-gogo\/descriptor/g' -- *.go
|
2019-01-15 06:32:05 -08:00
|
|
|
sed -i.bak -E 's/golang\/protobuf/gogo\/protobuf/g' -- *.go
|
|
|
|
rm -f -- *.bak
|
2020-02-17 13:13:33 -08:00
|
|
|
goimports -w ./*.go
|
2017-07-06 05:38:40 -07:00
|
|
|
popd
|
|
|
|
done
|