Merge pull request #3513 from thaJeztah/fix_ldflags

use GO_LDFLAGS instead of LDFLAGS to prevent inheriting unrelated options
This commit is contained in:
Nicolas De loof 2022-03-31 11:50:04 +02:00 committed by GitHub
commit abe41ad309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -63,23 +63,23 @@ if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
fi
export GO_BUILDMODE
LDFLAGS="${LDFLAGS:-} -w"
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\""
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\""
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.Version=${VERSION}\""
GO_LDFLAGS="${GO_LDFLAGS:-} -w"
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\""
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\""
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.Version=${VERSION}\""
if test -n "${PLATFORM}"; then
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
fi
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
LDFLAGS="$LDFLAGS -extldflags -static"
GO_LDFLAGS="$GO_LDFLAGS -extldflags -static"
fi
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ]; then
# compiling statically with CGO enabled requires osusergo to be set.
GO_BUILDTAGS="$GO_BUILDTAGS osusergo"
fi
if [ -n "$GO_STRIP" ]; then
LDFLAGS="$LDFLAGS -s"
GO_LDFLAGS="$GO_LDFLAGS -s"
fi
export LDFLAGS="$LDFLAGS" # https://github.com/koalaman/shellcheck/issues/2064
export GO_LDFLAGS="$GO_LDFLAGS" # https://github.com/koalaman/shellcheck/issues/2064
export SOURCE="github.com/docker/cli/cmd/docker"

View File

@ -24,6 +24,6 @@ if [ "$(go env GOOS)" = "windows" ]; then
fi
fi
(set -x ; go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" -ldflags "${LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}")
(set -x ; go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}")
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"

View File

@ -15,5 +15,5 @@ for p in cli-plugins/examples/* "$@" ; do
mkdir -p "$(dirname "${TARGET_PLUGIN}")"
echo "Building $GO_LINKMODE $(basename "${TARGET_PLUGIN}")"
(set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}")
(set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}")
done