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
|
|
|
|
|
2021-05-06 13:53:52 -07:00
|
|
|
if ! [[ $(protoc --version) =~ "3.15.8" ]]; then
|
|
|
|
echo "could not find protoc 3.15.8, is it installed + in PATH?"
|
2017-07-06 05:38:40 -07:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2021-02-25 13:25:25 -08:00
|
|
|
# Since we run go get, go mod download, the go.sum will change.
|
|
|
|
# Make a backup.
|
|
|
|
cp go.sum go.sum.bak
|
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
|
2020-10-08 00:38:28 -07:00
|
|
|
GO111MODULE=on go install "$pkg"
|
2019-01-15 06:32:05 -08:00
|
|
|
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
|
2021-06-28 03:16:06 -07:00
|
|
|
protoc --gogofast_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,paths=source_relative:. -I=. \
|
|
|
|
-I="${GOGOPROTO_PATH}" \
|
|
|
|
./io/prometheus/client/*.proto
|
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
|
2021-06-28 03:16:06 -07:00
|
|
|
goimports -w ./*.go ./io/prometheus/client/*.go
|
2017-07-06 05:38:40 -07:00
|
|
|
popd
|
|
|
|
done
|
2021-02-25 13:25:25 -08:00
|
|
|
|
|
|
|
mv go.sum.bak go.sum
|