From 005da75f4a0f082adecb74e2dc980183c9f4e327 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Wed, 1 Apr 2015 10:10:16 -0700 Subject: [PATCH] Make the build faster - call 'go install' once --- hack/lib/golang.sh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 3683ef28c598b..fc21bfd5636a7 100644 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -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//\//_}" @@ -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}" \ @@ -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 )