@@ -237,10 +237,13 @@ kube::golang::build_binaries() {
237
237
local goflags
238
238
eval " goflags=(${KUBE_GOFLAGS:- } )"
239
239
240
+ local use_go_build
240
241
local -a targets=()
241
242
local arg
242
243
for arg; do
243
- if [[ " ${arg} " == -* ]]; then
244
+ if [[ " ${arg} " == " --use_go_build" ]]; then
245
+ use_go_build=true
246
+ elif [[ " ${arg} " == -* ]]; then
244
247
# Assume arguments starting with a dash are flags to pass to go.
245
248
goflags+=(" ${arg} " )
246
249
else
@@ -264,9 +267,25 @@ kube::golang::build_binaries() {
264
267
for platform in " ${platforms[@]} " ; do
265
268
kube::golang::set_platform_envs " ${platform} "
266
269
kube::log::status " Building go targets for ${platform} :" " ${targets[@]} "
267
- go install " ${goflags[@]: +${goflags[@]} } " \
268
- -ldflags " ${version_ldflags} " \
269
- " ${binaries[@]} "
270
+ if [[ -n ${use_go_build:- } ]]; then
271
+ # Try and replicate the native binary placement of go install without calling go install
272
+ local output_path=" ${KUBE_GOPATH} /bin"
273
+ if [[ $platform != $host_platform ]]; then
274
+ output_path=" ${output_path} /${platform// \/ / _} "
275
+ fi
276
+
277
+ for binary in " ${binaries[@]} " ; do
278
+ local bin=$( basename " ${binary} " )
279
+ go build -o " ${output_path} /${bin} " \
280
+ " ${goflags[@]: +${goflags[@]} } " \
281
+ -ldflags " ${version_ldflags} " \
282
+ " ${binary} "
283
+ done
284
+ else
285
+ go install " ${goflags[@]: +${goflags[@]} } " \
286
+ -ldflags " ${version_ldflags} " \
287
+ " ${binaries[@]} "
288
+ fi
270
289
done
271
290
)
272
291
}
0 commit comments