Build flags: use all= syntax

This has somewhat subtle implications.  For a concrete example, this
changes the `-trimpath` behavior from only affecting the named pkg to
affecting all pkgs, which broke ginkgo, which seems to try to strip its
own `pwd` prefix.  But since that runs in run-in-gopath, and not in
KUBE_ROOT, it fails to strip anything.

e.g.

before this, strings in the binary would be like
    /home/user/kube/_output/local/go/src/k8s.io/kubernetes/vendor/github.com/onsi/ginkgo/...
Ginkgo would find its own root as
    /home/user/kube/_output/local/go/src/k8s.io/kubernetes/
so it would produce
    vendor/github.com/onsi/ginkgo/...
in logs.

after this, strings in the binary strip the KUBE_ROOT and be like:
    _output/local/go/src/k8s.io/kubernetes/vendor/github.com/onsi/ginkgo/...
Ginkgo would find its own root as
    /home/user/kube/_output/local/go/src/k8s.io/kubernetes/
so it would not strip anything, and produce
    _output/local/go/src/k8s.io/kubernetes/vendor/github.com/onsi/ginkgo/...
in logs.
This commit is contained in:
Tim Hockin 2022-02-26 23:28:49 -08:00
parent ed5e549cde
commit bf27cad256

View File

@ -803,15 +803,20 @@ kube::golang::build_binaries() {
# build_binaries_for_platform.
local goflags goldflags goasmflags gogcflags gotags
goasmflags="-trimpath=${KUBE_ROOT}"
# 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)
gogcflags="-trimpath=${KUBE_ROOT} ${GOGCFLAGS:-}"
goasmflags="all=-trimpath=${trimroot}"
gogcflags="all=-trimpath=${trimroot} ${GOGCFLAGS:-}"
if [[ "${DBG:-}" == 1 ]]; then
# Debugging - disable optimizations and inlining.
gogcflags="${gogcflags} -N -l"
fi
goldflags="$(kube::version::ldflags) ${GOLDFLAGS:-}"
goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}"
if [[ "${DBG:-}" != 1 ]]; then
# Not debugging - disable symbols and DWARF.
goldflags="${goldflags} -s -w"