mirror of https://github.com/docker/cli.git
Merge pull request #3514 from thaJeztah/20.10_backport_fix_ldflags
[20.10] use GO_LDFLAGS instead of LDFLAGS to prevent inheriting unrelated options
This commit is contained in:
commit
81d965569d
|
@ -13,13 +13,13 @@ if test -n "${PLATFORM}"; then
|
||||||
PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export LDFLAGS="\
|
export GO_LDFLAGS="\
|
||||||
-w \
|
-w \
|
||||||
${PLATFORM_LDFLAGS} \
|
${PLATFORM_LDFLAGS} \
|
||||||
-X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\" \
|
-X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\" \
|
||||||
-X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\" \
|
-X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\" \
|
||||||
-X \"github.com/docker/cli/cli/version.Version=${VERSION}\" \
|
-X \"github.com/docker/cli/cli/version.Version=${VERSION}\" \
|
||||||
${LDFLAGS:-} \
|
${GO_LDFLAGS:-} \
|
||||||
"
|
"
|
||||||
|
|
||||||
GOOS="$(go env GOOS)"
|
GOOS="$(go env GOOS)"
|
||||||
|
|
|
@ -47,11 +47,11 @@ if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
||||||
LDFLAGS="$LDFLAGS -extldflags -static"
|
GO_LDFLAGS="$GO_LDFLAGS -extldflags -static"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$GO_STRIP" ]; then
|
if [ -n "$GO_STRIP" ]; then
|
||||||
LDFLAGS="$LDFLAGS -s -w"
|
GO_LDFLAGS="$GO_LDFLAGS -s -w"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(go env GOOS)" = "windows" ]; then
|
if [ "$(go env GOOS)" = "windows" ]; then
|
||||||
|
@ -75,6 +75,6 @@ echo "Building $GO_LINKMODE $(basename "${TARGET}")"
|
||||||
|
|
||||||
export GO111MODULE=auto
|
export GO111MODULE=auto
|
||||||
|
|
||||||
go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}"
|
go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}"
|
||||||
|
|
||||||
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"
|
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"
|
||||||
|
|
|
@ -17,5 +17,5 @@ for p in cli-plugins/examples/* "$@" ; do
|
||||||
|
|
||||||
echo "Building statically linked $TARGET"
|
echo "Building statically linked $TARGET"
|
||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
GO111MODULE=auto go build -o "${TARGET}" --ldflags "${LDFLAGS}" "github.com/docker/cli/${p}"
|
GO111MODULE=auto go build -o "${TARGET}" --ldflags "${GO_LDFLAGS}" "github.com/docker/cli/${p}"
|
||||||
done
|
done
|
||||||
|
|
|
@ -12,7 +12,7 @@ export GOOS=darwin
|
||||||
export GOARCH=amd64
|
export GOARCH=amd64
|
||||||
export CC=o64-clang
|
export CC=o64-clang
|
||||||
export CXX=o64-clang++
|
export CXX=o64-clang++
|
||||||
export LDFLAGS="$LDFLAGS -linkmode external -s"
|
export GO_LDFLAGS="$GO_LDFLAGS -linkmode external -s"
|
||||||
export LDFLAGS_STATIC_DOCKER='-extld='${CC}
|
export LDFLAGS_STATIC_DOCKER='-extld='${CC}
|
||||||
|
|
||||||
source ./scripts/build/plugins
|
source ./scripts/build/plugins
|
||||||
|
|
|
@ -109,12 +109,12 @@ Function Execute-Build($additionalBuildTags, $directory) {
|
||||||
Write-Host "INFO: Building..."
|
Write-Host "INFO: Building..."
|
||||||
|
|
||||||
$buildTime=$(Get-Date).ToUniversalTime()
|
$buildTime=$(Get-Date).ToUniversalTime()
|
||||||
$env:LDFLAGS="-linkmode=internal `
|
$env:GO_LDFLAGS="-linkmode=internal `
|
||||||
-X \""github.com/docker/cli/cli/version.Version=$dockerVersion\"" `
|
-X \""github.com/docker/cli/cli/version.Version=$dockerVersion\"" `
|
||||||
-X \""github.com/docker/cli/cli/version.GitCommit=$gitCommit\"" `
|
-X \""github.com/docker/cli/cli/version.GitCommit=$gitCommit\"" `
|
||||||
-X \""github.com/docker/cli/cli/version.BuildTime=$buildTime\"""
|
-X \""github.com/docker/cli/cli/version.BuildTime=$buildTime\"""
|
||||||
if ($env:PLATFORM) {
|
if ($env:PLATFORM) {
|
||||||
$env:LDFLAGS="$env:LDFLAGS -X \""github.com/docker/cli/cli/version.PlatformName=$env:PLATFORM\"""
|
$env:GO_LDFLAGS="$env:GO_LDFLAGS -X \""github.com/docker/cli/cli/version.PlatformName=$env:PLATFORM\"""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate a version in the form major,minor,patch,build
|
# Generate a version in the form major,minor,patch,build
|
||||||
|
@ -138,7 +138,7 @@ Function Execute-Build($additionalBuildTags, $directory) {
|
||||||
# By using --% we can use \"key=%foo%\" and have a environment variable foo that contains spaces
|
# By using --% we can use \"key=%foo%\" and have a environment variable foo that contains spaces
|
||||||
go build $raceParm $verboseParm $allParm $optParm -tags "$buildTags" `
|
go build $raceParm $verboseParm $allParm $optParm -tags "$buildTags" `
|
||||||
-o "$root\build\$directory.exe" `
|
-o "$root\build\$directory.exe" `
|
||||||
-ldflags --% "%LDFLAGS%"
|
-ldflags --% "%GO_LDFLAGS%"
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) { Throw "Failed to compile" }
|
if ($LASTEXITCODE -ne 0) { Throw "Failed to compile" }
|
||||||
Pop-Location; $global:pushed=$False
|
Pop-Location; $global:pushed=$False
|
||||||
|
|
Loading…
Reference in New Issue