Skip to content

Commit

Permalink
Merge pull request kubernetes#122679 from bmwiedemann/automated-cherr…
Browse files Browse the repository at this point in the history
…y-pick-of-#121894-origin-release-1.27

Automated cherry pick of kubernetes#121894: build: use -trimpath in non-DBG mode
  • Loading branch information
k8s-ci-robot committed Apr 8, 2024
2 parents 8be2458 + 7840458 commit 1a7ed95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
28 changes: 9 additions & 19 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,14 @@ kube::golang::build_binaries_for_platform() {
done

V=2 kube::log::info "Env for ${platform}: GOOS=${GOOS-} GOARCH=${GOARCH-} GOROOT=${GOROOT-} CGO_ENABLED=${CGO_ENABLED-} CC=${CC-}"
V=3 kube::log::info "Building binaries with GCFLAGS=${gogcflags} ASMFLAGS=${goasmflags} LDFLAGS=${goldflags}"
V=3 kube::log::info "Building binaries with GCFLAGS=${gogcflags} LDFLAGS=${goldflags}"

local -a build_args
if [[ "${#statics[@]}" != 0 ]]; then
build_args=(
-installsuffix=static
${goflags:+"${goflags[@]}"}
-gcflags="${gogcflags}"
-asmflags="${goasmflags}"
-ldflags="${goldflags}"
-tags="${gotags:-}"
)
Expand All @@ -770,7 +769,6 @@ kube::golang::build_binaries_for_platform() {
build_args=(
${goflags:+"${goflags[@]}"}
-gcflags="${gogcflags}"
-asmflags="${goasmflags}"
-ldflags="${goldflags}"
-tags="${gotags:-}"
)
Expand All @@ -786,7 +784,6 @@ kube::golang::build_binaries_for_platform() {
go test -c \
${goflags:+"${goflags[@]}"} \
-gcflags="${gogcflags}" \
-asmflags="${goasmflags}" \
-ldflags="${goldflags}" \
-tags="${gotags:-}" \
-o "${outfile}" \
Expand Down Expand Up @@ -843,26 +840,19 @@ kube::golang::build_binaries() {
# These are "local" but are visible to and relied on by functions this
# function calls. They are effectively part of the calling API to
# build_binaries_for_platform.
local goflags goldflags goasmflags gogcflags gotags
local goflags goldflags gogcflags gotags

# This is $(pwd) because we use run-in-gopath to build. Once that is
# excised, this can become ${KUBE_ROOT}.
local trimroot # two lines to appease shellcheck SC2155
trimroot=$(pwd)

goasmflags="all=-trimpath=${trimroot}"
goflags=()
gogcflags="${GOGCFLAGS:-}"
goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}"

gogcflags="all=-trimpath=${trimroot} ${GOGCFLAGS:-}"
if [[ "${DBG:-}" == 1 ]]; then
# Debugging - disable optimizations and inlining and trimPath
gogcflags="${GOGCFLAGS:-} all=-N -l"
goasmflags=""
fi

goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}"
if [[ "${DBG:-}" != 1 ]]; then
# Not debugging - disable symbols and DWARF.
gogcflags="${gogcflags} all=-N -l"
else
# Not debugging - disable symbols and DWARF, trim embedded paths
goldflags="${goldflags} -s -w"
goflags+=("-trimpath")
fi

# Extract tags if any specified in GOFLAGS
Expand Down
7 changes: 6 additions & 1 deletion test/conformance/gen-specsummaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ KUBE_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
cd "${KUBE_ROOT}"

# build ginkgo and e2e.test
hack/make-rules/build.sh github.com/onsi/ginkgo/v2/ginkgo test/e2e/e2e.test
#
# Set DBG=1 to build with embedded filenames as filenames rather than
# module-relative names (e.g. /src/kube/foo/bar.go vs.
# k8s.io/kubernetes/foo/bar.go). These names are used by gingko in
# `--spec-dump` which is consumed later in conformance verification.
DBG=1 hack/make-rules/build.sh github.com/onsi/ginkgo/v2/ginkgo test/e2e/e2e.test

# dump spec
./_output/bin/ginkgo --dry-run=true --focus='[Conformance]' ./_output/bin/e2e.test -- --spec-dump "${KUBE_ROOT}/_output/specsummaries.json" > /dev/null

0 comments on commit 1a7ed95

Please sign in to comment.