@@ -345,12 +345,13 @@ kube::golang::unset_platform_envs() {
345
345
# Create the GOPATH tree under $KUBE_OUTPUT
346
346
kube::golang::create_gopath_tree () {
347
347
local go_pkg_dir=" ${KUBE_GOPATH} /src/${KUBE_GO_PACKAGE} "
348
- local go_pkg_basedir=$( dirname " ${go_pkg_dir} " )
348
+ local go_pkg_basedir
349
+ go_pkg_basedir=$( dirname " ${go_pkg_dir} " )
349
350
350
351
mkdir -p " ${go_pkg_basedir} "
351
352
352
353
# TODO: This symlink should be relative.
353
- if [[ ! -e " ${go_pkg_dir} " || " $( readlink ${go_pkg_dir} ) " != " ${KUBE_ROOT} " ]]; then
354
+ if [[ ! -e " ${go_pkg_dir} " || " $( readlink " ${go_pkg_dir} " ) " != " ${KUBE_ROOT} " ]]; then
354
355
ln -snf " ${KUBE_ROOT} " " ${go_pkg_dir} "
355
356
fi
356
357
@@ -427,10 +428,11 @@ kube::golang::setup_env() {
427
428
# cross-compiling, and `go install -o <file>` only works for a single pkg.
428
429
local subdir
429
430
subdir=$( kube::realpath . | sed " s|${KUBE_ROOT} ||" )
430
- cd " ${KUBE_GOPATH} /src/${KUBE_GO_PACKAGE} /${subdir} "
431
+ cd " ${KUBE_GOPATH} /src/${KUBE_GO_PACKAGE} /${subdir} " || return 1
431
432
432
433
# Set GOROOT so binaries that parse code can work properly.
433
- export GOROOT=$( go env GOROOT)
434
+ GOROOT=$( go env GOROOT)
435
+ export GOROOT
434
436
435
437
# Unset GOBIN in case it already exists in the current session.
436
438
unset GOBIN
@@ -479,10 +481,11 @@ kube::golang::outfile_for_binary() {
479
481
local binary=$1
480
482
local platform=$2
481
483
local output_path=" ${KUBE_GOPATH} /bin"
484
+ local bin
485
+ bin=$( basename " ${binary} " )
482
486
if [[ " ${platform} " != " ${host_platform} " ]]; then
483
487
output_path=" ${output_path} /${platform// \/ / _} "
484
488
fi
485
- local bin=$( basename " ${binary} " )
486
489
if [[ ${GOOS} == " windows" ]]; then
487
490
bin=" ${bin} .exe"
488
491
fi
@@ -493,15 +496,16 @@ kube::golang::outfile_for_binary() {
493
496
# Returns 0 if the binary can be built with coverage, 1 otherwise.
494
497
# NB: this ignores whether coverage is globally enabled or not.
495
498
kube::golang::is_instrumented_package () {
496
- return $( kube::util::array_contains " $1 " " ${KUBE_COVERAGE_INSTRUMENTED_PACKAGES[@]} " )
499
+ return " $( kube::util::array_contains " $1 " " ${KUBE_COVERAGE_INSTRUMENTED_PACKAGES[@]} " ) "
497
500
}
498
501
499
502
# Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler)
500
503
# Echos the path to a dummy test used for coverage information.
501
504
kube::golang::path_for_coverage_dummy_test () {
502
505
local package=" $1 "
503
506
local path=" ${KUBE_GOPATH} /src/${package} "
504
- local name=$( basename " ${package} " )
507
+ local name
508
+ name=$( basename " ${package} " )
505
509
echo " ${path} /zz_generated_${name} _test.go"
506
510
}
507
511
@@ -510,8 +514,9 @@ kube::golang::path_for_coverage_dummy_test() {
510
514
# This unit test will invoke the package's standard entry point when run.
511
515
kube::golang::create_coverage_dummy_test () {
512
516
local package=" $1 "
513
- local name=" $( basename " ${package} " ) "
514
- cat << EOF > $( kube::golang::path_for_coverage_dummy_test " ${package} " )
517
+ local name
518
+ name=" $( basename " ${package} " ) "
519
+ cat << EOF > "$( kube::golang::path_for_coverage_dummy_test " ${package} " ) "
515
520
package main
516
521
import (
517
522
"testing"
539
544
# It is not an error to call this for a nonexistent test.
540
545
kube::golang::delete_coverage_dummy_test () {
541
546
local package=" $1 "
542
- rm -f $( kube::golang::path_for_coverage_dummy_test " ${package} " )
547
+ rm -f " $( kube::golang::path_for_coverage_dummy_test " ${package} " ) "
543
548
}
544
549
545
550
# Arguments: a list of kubernetes packages to build.
@@ -572,7 +577,7 @@ kube::golang::build_some_binaries() {
572
577
fi
573
578
done
574
579
if [[ " ${# uncovered[@]} " != 0 ]]; then
575
- V=2 kube::log::info " Building ${uncovered[@ ]} without coverage..."
580
+ V=2 kube::log::info " Building ${uncovered[* ]} without coverage..."
576
581
go install " ${build_args[@]} " " ${uncovered[@]} "
577
582
else
578
583
V=2 kube::log::info " Nothing to build without coverage."
@@ -594,11 +599,11 @@ kube::golang::build_binaries_for_platform() {
594
599
595
600
for binary in " ${binaries[@]} " ; do
596
601
if [[ " ${binary} " =~ " .test" $ ]]; then
597
- tests+=(${binary} )
602
+ tests+=(" ${binary} " )
598
603
elif kube::golang::is_statically_linked_library " ${binary} " ; then
599
- statics+=(${binary} )
604
+ statics+=(" ${binary} " )
600
605
else
601
- nonstatics+=(${binary} )
606
+ nonstatics+=(" ${binary} " )
602
607
fi
603
608
done
604
609
@@ -625,10 +630,11 @@ kube::golang::build_binaries_for_platform() {
625
630
fi
626
631
627
632
for test in " ${tests[@]: +${tests[@]} } " ; do
628
- local outfile=$( kube::golang::outfile_for_binary " ${test} " " ${platform} " )
629
- local testpkg=" $( dirname ${test} ) "
633
+ local outfile testpkg
634
+ outfile=$( kube::golang::outfile_for_binary " ${test} " " ${platform} " )
635
+ testpkg=$( dirname " ${test} " )
630
636
631
- mkdir -p " $( dirname ${outfile} ) "
637
+ mkdir -p " $( dirname " ${outfile} " ) "
632
638
go test -c \
633
639
${goflags: +" ${goflags[@]} " } \
634
640
-gcflags " ${gogcflags:- } " \
@@ -645,13 +651,13 @@ kube::golang::get_physmem() {
645
651
646
652
# Linux kernel version >=3.14, in kb
647
653
if mem=$( grep MemAvailable /proc/meminfo | awk ' { print $2 }' ) ; then
648
- echo $(( ${ mem} / 1048576 ))
654
+ echo $(( mem / 1048576 ))
649
655
return
650
656
fi
651
657
652
658
# Linux, in kb
653
659
if mem=$( grep MemTotal /proc/meminfo | awk ' { print $2 }' ) ; then
654
- echo $(( ${ mem} / 1048576 ))
660
+ echo $(( mem / 1048576 ))
655
661
return
656
662
fi
657
663
@@ -660,7 +666,7 @@ kube::golang::get_physmem() {
660
666
# platform case, which is a Dockerized build), but this is provided
661
667
# for completeness.
662
668
if mem=$( sysctl -n hw.memsize 2> /dev/null) ; then
663
- echo $(( ${ mem} / 1073741824 ))
669
+ echo $(( mem / 1073741824 ))
664
670
return
665
671
fi
666
672
@@ -713,7 +719,7 @@ kube::golang::build_binaries() {
713
719
fi
714
720
715
721
local binaries
716
- binaries=( $ ( kube::golang::binaries_from_targets " ${targets[@]} " ) )
722
+ while IFS= " " read -r binary ; do binaries+=( " $binary " ) ; done < < ( kube::golang::binaries_from_targets " ${targets[@]} " )
717
723
718
724
local parallel=false
719
725
if [[ ${# platforms[@]} -gt 1 ]]; then
@@ -735,14 +741,14 @@ kube::golang::build_binaries() {
735
741
for platform in " ${platforms[@]} " ; do (
736
742
kube::golang::set_platform_envs " ${platform} "
737
743
kube::log::status " ${platform} : build started"
738
- kube::golang::build_binaries_for_platform ${platform}
744
+ kube::golang::build_binaries_for_platform " ${platform} "
739
745
kube::log::status " ${platform} : build finished"
740
746
) & > " /tmp//${platform// \/ / _} .build" &
741
747
done
742
748
743
749
local fails=0
744
750
for job in $( jobs -p) ; do
745
- wait ${job} || let " fails+=1"
751
+ wait " ${job} " || (( fails+= 1 ))
746
752
done
747
753
748
754
for platform in " ${platforms[@]} " ; do
@@ -755,7 +761,7 @@ kube::golang::build_binaries() {
755
761
kube::log::status " Building go targets for ${platform} :" " ${targets[@]} "
756
762
(
757
763
kube::golang::set_platform_envs " ${platform} "
758
- kube::golang::build_binaries_for_platform ${platform}
764
+ kube::golang::build_binaries_for_platform " ${platform} "
759
765
)
760
766
done
761
767
fi
0 commit comments