update-codegen.sh: automatically install protoc

This commit is contained in:
Benjamin Elder
2025-04-24 21:02:54 -07:00
parent 8a2f367ec3
commit d5bf33e7d7
2 changed files with 19 additions and 12 deletions

View File

@@ -101,19 +101,20 @@ function kube::protoc::diff() {
}
function kube::protoc::install() {
local os
local arch
local download_folder
local download_file
local third_party_dir
os=$(kube::util::host_os)
arch=$(kube::util::host_arch)
download_folder="protoc-v${PROTOC_VERSION}-${os}-${arch}"
download_file="${download_folder}.zip"
third_party_dir="${KUBE_ROOT}/third_party"
# run in a subshell to isolate caller from directory changes
(
local os
local arch
local download_folder
local download_file
os=$(kube::util::host_os)
arch=$(kube::util::host_arch)
download_folder="protoc-v${PROTOC_VERSION}-${os}-${arch}"
download_file="${download_folder}.zip"
cd "${KUBE_ROOT}/third_party" || return 1
cd "${third_party_dir}" || return 1
if [[ $(readlink protoc) != "${download_folder}" ]]; then
local url
if [[ ${os} == "darwin" ]]; then
@@ -136,8 +137,12 @@ function kube::protoc::install() {
rm "${download_file}"
fi
kube::log::info "protoc v${PROTOC_VERSION} installed. To use:"
kube::log::info "export PATH=\"$(pwd)/protoc:\${PATH}\""
kube::log::info "export PATH=\"${third_party_dir}/protoc:\${PATH}\""
)
# export updated PATH so install-protoc.sh can be sourced
# CLI callers will need to use the export indicated above
PATH="${third_party_dir}/protoc:${PATH}"
export PATH
}
# Marker function to indicate protoc.sh has been fully sourced

View File

@@ -52,6 +52,8 @@ fi
echo "installing goimports from hack/tools"
go -C "${KUBE_ROOT}/hack/tools" install golang.org/x/tools/cmd/goimports
kube::protoc::install
# Generate a list of directories we don't want to play in.
DIRS_TO_AVOID=()
kube::util::read-array DIRS_TO_AVOID < <(