mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Completely neutral commit that just factors each platform build out to
a function (to make it kinder on reviewers for the next piece).
This commit is contained in:
parent
04813f0dcd
commit
e159c02a2a
@ -263,6 +263,64 @@ kube::golang::exit_if_stdlib_not_installed() {
|
|||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kube::golang::build_binaries_for_platform() {
|
||||||
|
local platform=$1
|
||||||
|
local use_go_build=${2-}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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.
|
||||||
|
if [[ "${#nonstatics[@]}" != 0 ]]; then
|
||||||
|
go install "${goflags[@]:+${goflags[@]}}" \
|
||||||
|
-ldflags "${version_ldflags}" \
|
||||||
|
"${nonstatics[@]:+${nonstatics[@]}}"
|
||||||
|
fi
|
||||||
|
if [[ "${#statics[@]}" != 0 ]]; then
|
||||||
|
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
|
||||||
|
-ldflags "${version_ldflags}" \
|
||||||
|
"${statics[@]:+${statics[@]}}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
# Build binaries targets specified
|
# Build binaries targets specified
|
||||||
#
|
#
|
||||||
# Input:
|
# Input:
|
||||||
@ -318,58 +376,7 @@ kube::golang::build_binaries() {
|
|||||||
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"
|
||||||
|
kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}
|
||||||
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
|
|
||||||
|
|
||||||
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.
|
|
||||||
if [[ "${#nonstatics[@]}" != 0 ]]; then
|
|
||||||
go install "${goflags[@]:+${goflags[@]}}" \
|
|
||||||
-ldflags "${version_ldflags}" \
|
|
||||||
"${nonstatics[@]:+${nonstatics[@]}}"
|
|
||||||
fi
|
|
||||||
if [[ "${#statics[@]}" != 0 ]]; then
|
|
||||||
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
|
|
||||||
-ldflags "${version_ldflags}" \
|
|
||||||
"${statics[@]:+${statics[@]}}"
|
|
||||||
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