2017-04-18 08:46:40 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Generate all protobuf bindings.
|
|
|
|
# Run from repository root.
|
|
|
|
#
|
2017-04-18 10:54:01 +00:00
|
|
|
# Initial script taken from etcd under the Apache 2.0 license
|
2017-04-18 08:46:40 +00:00
|
|
|
# File: https://github.com/coreos/etcd/blob/78a5eb79b510eb497deddd1a76f5153bc4b202d2/scripts/genproto.sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
|
|
|
|
if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then
|
2019-01-22 10:48:37 +00:00
|
|
|
echo "must be run from repository root"
|
|
|
|
exit 255
|
2017-04-18 08:46:40 +00:00
|
|
|
fi
|
|
|
|
|
2021-04-22 08:20:26 +00:00
|
|
|
if ! [[ $(protoc --version) =~ "3.15.8" ]]; then
|
|
|
|
echo "could not find protoc 3.15.8, is it installed + in PATH?"
|
2019-01-22 10:48:37 +00:00
|
|
|
exit 255
|
2017-04-18 08:46:40 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-22 10:48:37 +00:00
|
|
|
echo "installing plugins"
|
2021-04-26 09:16:25 +00:00
|
|
|
|
|
|
|
# Since we run go mod download, the go.sum will change.
|
|
|
|
# Make a backup.
|
|
|
|
cp go.sum go.sum.bak
|
|
|
|
|
2020-05-18 13:00:36 +00:00
|
|
|
go mod download
|
2019-01-22 10:48:37 +00:00
|
|
|
|
|
|
|
INSTALL_PKGS="golang.org/x/tools/cmd/goimports github.com/gogo/protobuf/protoc-gen-gogofast"
|
|
|
|
for pkg in ${INSTALL_PKGS}; do
|
2021-04-22 08:20:26 +00:00
|
|
|
go install "$pkg"
|
2019-01-22 10:48:37 +00:00
|
|
|
done
|
|
|
|
|
2020-05-18 13:00:36 +00:00
|
|
|
GOGOPROTO_ROOT="$(go list -mod=readonly -f '{{ .Dir }}' -m github.com/gogo/protobuf)"
|
2017-04-18 08:46:40 +00:00
|
|
|
GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
|
|
|
|
|
2018-02-07 15:36:47 +00:00
|
|
|
DIRS="nflog/nflogpb silence/silencepb cluster/clusterpb"
|
2017-04-18 08:46:40 +00:00
|
|
|
|
2019-01-22 10:48:37 +00:00
|
|
|
echo "generating files"
|
2017-04-18 08:46:40 +00:00
|
|
|
for dir in ${DIRS}; do
|
2019-01-22 10:48:37 +00:00
|
|
|
pushd ${dir}
|
|
|
|
protoc --gogofast_out=:. -I=. \
|
2017-04-18 08:46:40 +00:00
|
|
|
-I="${GOGOPROTO_PATH}" \
|
|
|
|
*.proto
|
|
|
|
|
2019-01-22 10:48:37 +00:00
|
|
|
sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
|
|
|
|
sed -i.bak -E 's/import _ \"google\/protobuf\"//g' *.pb.go
|
2019-02-26 11:18:57 +00:00
|
|
|
sed -i.bak -E 's/\t_ \"google\/protobuf\"//g' -- *.pb.go
|
2019-01-22 10:48:37 +00:00
|
|
|
rm -f *.bak
|
|
|
|
goimports -w *.pb.go
|
|
|
|
popd
|
2017-04-18 08:46:40 +00:00
|
|
|
done
|
2021-04-26 09:16:25 +00:00
|
|
|
|
2021-04-29 08:43:24 +00:00
|
|
|
mv go.sum.bak go.sum
|