build: use -trimpath in non-DBG mode

This commit is contained in:
Tim Hockin 2023-11-14 18:57:34 -08:00
parent ad9b60e2c9
commit 37b7ae6b93
No known key found for this signature in database

View File

@ -773,7 +773,7 @@ kube::golang::build_binaries_for_platform() {
done done
V=2 kube::log::info "Env for ${platform}: GOOS=${GOOS-} GOARCH=${GOARCH-} GOROOT=${GOROOT-} CGO_ENABLED=${CGO_ENABLED-} CC=${CC-}" 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 local -a build_args
if [[ "${#statics[@]}" != 0 ]]; then if [[ "${#statics[@]}" != 0 ]]; then
@ -781,7 +781,6 @@ kube::golang::build_binaries_for_platform() {
-installsuffix=static -installsuffix=static
${goflags:+"${goflags[@]}"} ${goflags:+"${goflags[@]}"}
-gcflags="${gogcflags}" -gcflags="${gogcflags}"
-asmflags="${goasmflags}"
-ldflags="${goldflags}" -ldflags="${goldflags}"
-tags="${gotags:-}" -tags="${gotags:-}"
) )
@ -792,7 +791,6 @@ kube::golang::build_binaries_for_platform() {
build_args=( build_args=(
${goflags:+"${goflags[@]}"} ${goflags:+"${goflags[@]}"}
-gcflags="${gogcflags}" -gcflags="${gogcflags}"
-asmflags="${goasmflags}"
-ldflags="${goldflags}" -ldflags="${goldflags}"
-tags="${gotags:-}" -tags="${gotags:-}"
) )
@ -808,7 +806,6 @@ kube::golang::build_binaries_for_platform() {
go test -c \ go test -c \
${goflags:+"${goflags[@]}"} \ ${goflags:+"${goflags[@]}"} \
-gcflags="${gogcflags}" \ -gcflags="${gogcflags}" \
-asmflags="${goasmflags}" \
-ldflags="${goldflags}" \ -ldflags="${goldflags}" \
-tags="${gotags:-}" \ -tags="${gotags:-}" \
-o "${outfile}" \ -o "${outfile}" \
@ -865,26 +862,19 @@ kube::golang::build_binaries() {
# These are "local" but are visible to and relied on by functions this # These are "local" but are visible to and relied on by functions this
# function calls. They are effectively part of the calling API to # function calls. They are effectively part of the calling API to
# build_binaries_for_platform. # 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 goflags=()
# excised, this can become ${KUBE_ROOT}. gogcflags="${GOGCFLAGS:-}"
local trimroot # two lines to appease shellcheck SC2155 goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}"
trimroot=$(pwd)
goasmflags="all=-trimpath=${trimroot}"
gogcflags="all=-trimpath=${trimroot} ${GOGCFLAGS:-}"
if [[ "${DBG:-}" == 1 ]]; then if [[ "${DBG:-}" == 1 ]]; then
# Debugging - disable optimizations and inlining and trimPath # Debugging - disable optimizations and inlining and trimPath
gogcflags="${GOGCFLAGS:-} all=-N -l" gogcflags="${gogcflags} all=-N -l"
goasmflags="" else
fi # Not debugging - disable symbols and DWARF, trim embedded paths
goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}"
if [[ "${DBG:-}" != 1 ]]; then
# Not debugging - disable symbols and DWARF.
goldflags="${goldflags} -s -w" goldflags="${goldflags} -s -w"
goflags+=("-trimpath")
fi fi
# Extract tags if any specified in GOFLAGS # Extract tags if any specified in GOFLAGS