From ac2890df45ded9d9f16174cfece88d4cd875ed99 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 21 Jan 2023 12:26:05 -0800 Subject: [PATCH] Make protobindings gen a bit safer --- hack/lib/protoc.sh | 2 +- ...ate-generated-proto-bindings-dockerized.sh | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hack/lib/protoc.sh b/hack/lib/protoc.sh index 0874ca07b17..1b02310f544 100644 --- a/hack/lib/protoc.sh +++ b/hack/lib/protoc.sh @@ -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 diff --git a/hack/update-generated-proto-bindings-dockerized.sh b/hack/update-generated-proto-bindings-dockerized.sh index 0076d249bc7..cd5dab862cb 100755 --- a/hack/update-generated-proto-bindings-dockerized.sh +++ b/hack/update-generated-proto-bindings-dockerized.sh @@ -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 ..." 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