Make protobindings gen a bit safer

This commit is contained in:
Tim Hockin 2023-01-21 12:26:05 -08:00
parent afae402865
commit ac2890df45
No known key found for this signature in database
2 changed files with 16 additions and 7 deletions

View File

@ -64,7 +64,7 @@ function kube::protoc::protoc() {
# isn't). The inputs to this function do not all have a common root, so
# this works best for all inputs.
PATH="${gogopath}:${PATH}" protoc \
--proto_path="${package}" \
--proto_path="$(pwd -P)" \
--proto_path="${KUBE_ROOT}/vendor" \
--gogo_out=paths=source_relative,plugins=grpc:. \
api.proto

View File

@ -23,8 +23,9 @@ set -o pipefail
KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)"
source "${KUBE_ROOT}/hack/lib/protoc.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"
if [ "$#" = 0 ]; then
if [ "$#" == 0 ]; then
echo "usage: $0 <api_dir>..."
exit 1
fi
@ -32,9 +33,17 @@ fi
for api; do
# This can't use `git ls-files` because it runs in a container without the
# .git dir synced.
find "${api}" -type f -name "api.proto" \
| while read -r F; do
D="$(dirname "${F}")"
kube::protoc::generate_proto "${KUBE_ROOT}/${D}"
done
protos=()
kube::util::read-array protos < <( \
find "${api}" -type f -name "api.proto")
if [ "${#protos[@]}" == 0 ]; then
echo "ERROR: no 'api.proto' files under '${api}'"
exit 1
fi
for file in "${protos[@]}"; do
dir="$(dirname "${file}")"
kube::protoc::generate_proto "${dir}"
done
done