diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 846de5a7924..40b19d579dc 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -114,7 +114,6 @@ kube::golang::test_targets() { cmd/linkcheck examples/k8petstore/web-server/src vendor/github.com/onsi/ginkgo/ginkgo - hack/cmd/teststale test/e2e/e2e.test test/e2e_node/e2e_node.test ) @@ -375,6 +374,25 @@ kube::golang::fallback_if_stdlib_not_installable() { use_go_build=true } +# Builds the toolchain necessary for building kube. This needs to be +# built only on the host platform. +# TODO: This builds only the `teststale` binary right now. As we expand +# this function's capabilities we need to find this a right home. +# Ideally, not a shell script because testing shell scripts is painful. +kube::golang::build_kube_toolchain() { + local targets=( + hack/cmd/teststale + ) + + local binaries + binaries=($(kube::golang::binaries_from_targets "${targets[@]}")) + + kube::log::status "Building the toolchain targets:" "${binaries[@]}" + go install "${goflags[@]:+${goflags[@]}}" \ + -ldflags "${goldflags}" \ + "${binaries[@]:+${binaries[@]}}" +} + # Try and replicate the native binary placement of go install without # calling go install. kube::golang::output_filename_for_binary() { @@ -444,15 +462,25 @@ kube::golang::build_binaries_for_platform() { fi fi - teststale=$(kube::golang::output_filename_for_binary "hack/cmd/teststale" "${platform}") for test in "${tests[@]:+${tests[@]}}"; do local outfile=$(kube::golang::output_filename_for_binary "${test}" \ "${platform}") local testpkg="$(dirname ${test})" - if ! ${teststale} -binary "${outfile}" -package "${testpkg}"; then + + # Staleness check always happens on the host machine, so we don't + # have to locate the `teststale` binaries for the other platforms. + # Since we place the host binaries in `$KUBE_GOPATH/bin`, we can + # assume that the binary exists there, if it exists at all. + # Otherwise, something has gone wrong with building the `teststale` + # binary and we should safely proceed building the test binaries + # assuming that they are stale. There is no good reason to error + # out. + if test -x "${KUBE_GOPATH}/bin/teststale" && ! "${KUBE_GOPATH}/bin/teststale" -binary "${outfile}" -package "${testpkg}" + then continue fi + # `go test -c` below directly builds the binary. It builds the packages, # but it never installs them. `go test -i` only installs the dependencies # of the test, but not the test package itself. So neither `go test -c` @@ -564,6 +592,9 @@ kube::golang::build_binaries() { fi fi + # First build the toolchain before building any other targets + kube::golang::build_kube_toolchain + if [[ "${parallel}" == "true" ]]; then kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}" local platform