Skip to content

Commit d5bf33e

Browse files
committed
update-codegen.sh: automatically install protoc
1 parent 8a2f367 commit d5bf33e

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

hack/lib/protoc.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,20 @@ function kube::protoc::diff() {
101101
}
102102

103103
function kube::protoc::install() {
104+
local os
105+
local arch
106+
local download_folder
107+
local download_file
108+
local third_party_dir
109+
110+
os=$(kube::util::host_os)
111+
arch=$(kube::util::host_arch)
112+
download_folder="protoc-v${PROTOC_VERSION}-${os}-${arch}"
113+
download_file="${download_folder}.zip"
114+
third_party_dir="${KUBE_ROOT}/third_party"
104115
# run in a subshell to isolate caller from directory changes
105116
(
106-
local os
107-
local arch
108-
local download_folder
109-
local download_file
110-
111-
os=$(kube::util::host_os)
112-
arch=$(kube::util::host_arch)
113-
download_folder="protoc-v${PROTOC_VERSION}-${os}-${arch}"
114-
download_file="${download_folder}.zip"
115-
116-
cd "${KUBE_ROOT}/third_party" || return 1
117+
cd "${third_party_dir}" || return 1
117118
if [[ $(readlink protoc) != "${download_folder}" ]]; then
118119
local url
119120
if [[ ${os} == "darwin" ]]; then
@@ -136,8 +137,12 @@ function kube::protoc::install() {
136137
rm "${download_file}"
137138
fi
138139
kube::log::info "protoc v${PROTOC_VERSION} installed. To use:"
139-
kube::log::info "export PATH=\"$(pwd)/protoc:\${PATH}\""
140+
kube::log::info "export PATH=\"${third_party_dir}/protoc:\${PATH}\""
140141
)
142+
# export updated PATH so install-protoc.sh can be sourced
143+
# CLI callers will need to use the export indicated above
144+
PATH="${third_party_dir}/protoc:${PATH}"
145+
export PATH
141146
}
142147

143148
# Marker function to indicate protoc.sh has been fully sourced

hack/update-codegen.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ fi
5252
echo "installing goimports from hack/tools"
5353
go -C "${KUBE_ROOT}/hack/tools" install golang.org/x/tools/cmd/goimports
5454

55+
kube::protoc::install
56+
5557
# Generate a list of directories we don't want to play in.
5658
DIRS_TO_AVOID=()
5759
kube::util::read-array DIRS_TO_AVOID < <(

0 commit comments

Comments
 (0)