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
|
|
|
|
|
2018-09-05 12:04:44 -07:00
|
|
|
if ! [[ $(protoc --version) =~ "3.5.1" ]]; then
|
|
|
|
echo "could not find protoc 3.5.1, 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"
|
2019-01-15 06:32:05 -08:00
|
|
|
GOGOPROTO_ROOT="$(GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)"
|
2017-07-06 05:38:40 -07:00
|
|
|
GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
|
2019-01-15 06:32:05 -08:00
|
|
|
GRPC_GATEWAY_ROOT="$(GO111MODULE=on go list -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
|
|
|
|
2017-11-01 15:03:46 -07:00
|
|
|
protoc -I. \
|
|
|
|
-I="${GOGOPROTO_PATH}" \
|
|
|
|
-I="${PROM_PATH}" \
|
|
|
|
-I="${GRPC_GATEWAY_ROOT}/third_party/googleapis" \
|
|
|
|
--grpc-gateway_out=logtostderr=true:. \
|
|
|
|
--swagger_out=logtostderr=true:../documentation/dev/api/ \
|
|
|
|
rpc.proto
|
|
|
|
mv ../documentation/dev/api/rpc.swagger.json ../documentation/dev/api/swagger.json
|
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
|
2019-01-15 06:32:05 -08:00
|
|
|
sed -i.bak -E 's/golang\/protobuf/gogo\/protobuf/g' -- *.go
|
|
|
|
rm -f -- *.bak
|
|
|
|
goimports -w ./*.pb.go
|
2017-07-06 05:38:40 -07:00
|
|
|
popd
|
|
|
|
done
|