Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the build faster - call 'go install' once #6299

Merged
merged 1 commit into from
Apr 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,26 @@ kube::golang::build_binaries() {

local binaries
binaries=($(kube::golang::binaries_from_targets "${targets[@]}"))

local platform
for platform in "${platforms[@]}"; do
kube::golang::set_platform_envs "${platform}"
kube::log::status "Building go targets for ${platform}:" "${targets[@]}"

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
# 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//\//_}"
Expand All @@ -329,7 +342,7 @@ kube::golang::build_binaries() {
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}" \
Expand All @@ -344,18 +357,17 @@ kube::golang::build_binaries() {
fi
done
else
for binary in "${binaries[@]}"; do
if kube::golang::is_statically_linked_library "${binary}"; then
kube::golang::exit_if_stdlib_not_installed;
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
-ldflags "${version_ldflags}" \
"${binary}"
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}" \
"${binary}"
"${statics[@]:+${statics[@]}}"
fi
done
fi
done
)
Expand Down