mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Re tab-ify golang.sh
This commit is contained in:
parent
44b4c9ff26
commit
0bbf4e99f6
@ -316,61 +316,61 @@ kube::golang::build_binaries() {
|
|||||||
kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}"
|
kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}"
|
||||||
local platform
|
local platform
|
||||||
for platform in "${platforms[@]}"; do (
|
for platform in "${platforms[@]}"; do (
|
||||||
kube::golang::set_platform_envs "${platform}"
|
kube::golang::set_platform_envs "${platform}"
|
||||||
kube::log::status "${platform}: Parallel go build started"
|
kube::log::status "${platform}: Parallel go build started"
|
||||||
|
|
||||||
local -a statics=()
|
|
||||||
local -a nonstatics=()
|
|
||||||
for binary in "${binaries[@]}"; do
|
|
||||||
if kube::golang::is_statically_linked_library "${binary}"; then
|
|
||||||
kube::golang::exit_if_stdlib_not_installed;
|
|
||||||
statics+=($binary)
|
|
||||||
else
|
|
||||||
nonstatics+=($binary)
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ -n ${use_go_build:-} ]]; then
|
|
||||||
# Try and replicate the native binary placement of go install without
|
|
||||||
# calling go install. This means we have to iterate each binary.
|
|
||||||
local output_path="${KUBE_GOPATH}/bin"
|
|
||||||
if [[ $platform != $host_platform ]]; then
|
|
||||||
output_path="${output_path}/${platform//\//_}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
local -a statics=()
|
||||||
|
local -a nonstatics=()
|
||||||
for binary in "${binaries[@]}"; do
|
for binary in "${binaries[@]}"; do
|
||||||
local bin=$(basename "${binary}")
|
|
||||||
if [[ ${GOOS} == "windows" ]]; then
|
|
||||||
bin="${bin}.exe"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if kube::golang::is_statically_linked_library "${binary}"; then
|
if kube::golang::is_statically_linked_library "${binary}"; then
|
||||||
kube::golang::exit_if_stdlib_not_installed;
|
kube::golang::exit_if_stdlib_not_installed;
|
||||||
CGO_ENABLED=0 go build -installsuffix cgo -o "${output_path}/${bin}" \
|
statics+=($binary)
|
||||||
"${goflags[@]:+${goflags[@]}}" \
|
|
||||||
-ldflags "${version_ldflags}" \
|
|
||||||
"${binary}"
|
|
||||||
else
|
else
|
||||||
go build -o "${output_path}/${bin}" \
|
nonstatics+=($binary)
|
||||||
"${goflags[@]:+${goflags[@]}}" \
|
|
||||||
-ldflags "${version_ldflags}" \
|
|
||||||
"${binary}"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
|
||||||
|
if [[ -n ${use_go_build:-} ]]; then
|
||||||
|
# Try and replicate the native binary placement of go install without
|
||||||
|
# calling go install. This means we have to iterate each binary.
|
||||||
|
local output_path="${KUBE_GOPATH}/bin"
|
||||||
|
if [[ $platform != $host_platform ]]; then
|
||||||
|
output_path="${output_path}/${platform//\//_}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for binary in "${binaries[@]}"; do
|
||||||
|
local bin=$(basename "${binary}")
|
||||||
|
if [[ ${GOOS} == "windows" ]]; then
|
||||||
|
bin="${bin}.exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if kube::golang::is_statically_linked_library "${binary}"; then
|
||||||
|
kube::golang::exit_if_stdlib_not_installed;
|
||||||
|
CGO_ENABLED=0 go build -installsuffix cgo -o "${output_path}/${bin}" \
|
||||||
|
"${goflags[@]:+${goflags[@]}}" \
|
||||||
|
-ldflags "${version_ldflags}" \
|
||||||
|
"${binary}"
|
||||||
|
else
|
||||||
|
go build -o "${output_path}/${bin}" \
|
||||||
|
"${goflags[@]:+${goflags[@]}}" \
|
||||||
|
-ldflags "${version_ldflags}" \
|
||||||
|
"${binary}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
# Use go install.
|
# Use go install.
|
||||||
if [[ "${#nonstatics[@]}" != 0 ]]; then
|
if [[ "${#nonstatics[@]}" != 0 ]]; then
|
||||||
go install "${goflags[@]:+${goflags[@]}}" \
|
go install "${goflags[@]:+${goflags[@]}}" \
|
||||||
-ldflags "${version_ldflags}" \
|
-ldflags "${version_ldflags}" \
|
||||||
"${nonstatics[@]:+${nonstatics[@]}}"
|
"${nonstatics[@]:+${nonstatics[@]}}"
|
||||||
fi
|
fi
|
||||||
if [[ "${#statics[@]}" != 0 ]]; then
|
if [[ "${#statics[@]}" != 0 ]]; then
|
||||||
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
|
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
|
||||||
-ldflags "${version_ldflags}" \
|
-ldflags "${version_ldflags}" \
|
||||||
"${statics[@]:+${statics[@]}}"
|
"${statics[@]:+${statics[@]}}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
kube::log::status "${platform}: Parallel go build finished"
|
kube::log::status "${platform}: Parallel go build finished"
|
||||||
) &> "/tmp//${platform//\//_}.build" &
|
) &> "/tmp//${platform//\//_}.build" &
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user