Skip to content

Commit 652a0ce

Browse files
committed
Merge pull request kubernetes#2106 from eparis/go-build
add --use_go_build option when building binaries
2 parents d7f98b2 + 7403de8 commit 652a0ce

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

hack/lib/golang.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,13 @@ kube::golang::build_binaries() {
237237
local goflags
238238
eval "goflags=(${KUBE_GOFLAGS:-})"
239239

240+
local use_go_build
240241
local -a targets=()
241242
local arg
242243
for arg; do
243-
if [[ "${arg}" == -* ]]; then
244+
if [[ "${arg}" == "--use_go_build" ]]; then
245+
use_go_build=true
246+
elif [[ "${arg}" == -* ]]; then
244247
# Assume arguments starting with a dash are flags to pass to go.
245248
goflags+=("${arg}")
246249
else
@@ -264,9 +267,25 @@ kube::golang::build_binaries() {
264267
for platform in "${platforms[@]}"; do
265268
kube::golang::set_platform_envs "${platform}"
266269
kube::log::status "Building go targets for ${platform}:" "${targets[@]}"
267-
go install "${goflags[@]:+${goflags[@]}}" \
268-
-ldflags "${version_ldflags}" \
269-
"${binaries[@]}"
270+
if [[ -n ${use_go_build:-} ]]; then
271+
# Try and replicate the native binary placement of go install without calling go install
272+
local output_path="${KUBE_GOPATH}/bin"
273+
if [[ $platform != $host_platform ]]; then
274+
output_path="${output_path}/${platform//\//_}"
275+
fi
276+
277+
for binary in "${binaries[@]}"; do
278+
local bin=$(basename "${binary}")
279+
go build -o "${output_path}/${bin}" \
280+
"${goflags[@]:+${goflags[@]}}" \
281+
-ldflags "${version_ldflags}" \
282+
"${binary}"
283+
done
284+
else
285+
go install "${goflags[@]:+${goflags[@]}}" \
286+
-ldflags "${version_ldflags}" \
287+
"${binaries[@]}"
288+
fi
270289
done
271290
)
272291
}

hack/test-integration.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# any command line arguments will be passed to hack/build_go.sh to build the
18+
# cmd/integration binary. --use_go_build is a legitimate argument, as are
19+
# any other build time arguments.
20+
1721
set -o errexit
1822
set -o nounset
1923
set -o pipefail
@@ -26,9 +30,7 @@ cleanup() {
2630
kube::log::status "Integration test cleanup complete"
2731
}
2832

29-
if [[ -z ${KUBE_NO_BUILD_INTEGRATION-} ]]; then
30-
"${KUBE_ROOT}/hack/build-go.sh" cmd/integration
31-
fi
33+
"${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration
3234

3335
# Run cleanup to stop etcd on interrupt or other kill signal.
3436
trap cleanup HUP INT QUIT TERM

0 commit comments

Comments
 (0)