Skip to content

Commit

Permalink
Use -X ldflags to set dockerversion package vars
Browse files Browse the repository at this point in the history
This eliminates the need to lay down an auto-generated file.
IIRC this was originally hadded for gccgo which we no longer support.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Dec 2, 2019
1 parent ccb0b0a commit 675b414
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ autogen/
bundles/
cmd/dockerd/dockerd
contrib/builder/rpm/*/changelog
dockerversion/version_autogen.go
dockerversion/version_autogen_unix.go
vendor/pkg/
go-test-report.json
profile.out
Expand Down
4 changes: 2 additions & 2 deletions dockerversion/version_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package dockerversion // import "github.com/docker/docker/dockerversion"

// Default build-time variable for library-import.
// This file is overridden on build with build-time information.
const (
// These variables are overridden on build with build-time information.
var (
GitCommit = "library-import"
Version = "library-import"
BuildTime = "library-import"
Expand Down
2 changes: 1 addition & 1 deletion hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ LDFLAGS_STATIC=''
EXTLDFLAGS_STATIC='-static'
# ORIG_BUILDFLAGS is necessary for the cross target which cannot always build
# with options like -race.
ORIG_BUILDFLAGS=( -tags "autogen netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo )
ORIG_BUILDFLAGS=( -tags "netgo osusergo static_build $DOCKER_BUILDTAGS" -installsuffix netgo )
# see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here

BUILDFLAGS=( ${BUILDFLAGS} "${ORIG_BUILDFLAGS[@]}" )
Expand Down
45 changes: 10 additions & 35 deletions hack/make/.go-autogen
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,16 @@ source hack/dockerfile/install/runc.installer
source hack/dockerfile/install/tini.installer
source hack/dockerfile/install/containerd.installer

cat > dockerversion/version_autogen.go <<DVEOF
// +build autogen
// Package dockerversion is auto-generated at build-time
package dockerversion
// Default build-time variable for library-import.
// This file is overridden on build with build-time information.
const (
GitCommit string = "$GITCOMMIT"
Version string = "$VERSION"
BuildTime string = "$BUILDTIME"
IAmStatic string = "${IAMSTATIC:-true}"
PlatformName string = "${PLATFORM}"
ProductName string = "${PRODUCT}"
DefaultProductLicense string = "${DEFAULT_PRODUCT_LICENSE}"
)
// Code generated by hack/make/.go-autogen. DO NOT EDIT.
DVEOF

cat > dockerversion/version_autogen_unix.go <<DVEOF
// +build autogen,!windows
// Package dockerversion is auto-generated at build-time
package dockerversion
// Default build-time variable for library-import.
// This file is overridden on build with build-time information.
const (
InitCommitID string = "${TINI_COMMIT}"
)
// Code generated by hack/make/.go-autogen. DO NOT EDIT.
DVEOF
LDFLAGS="${LDFALGS} \
-X github.com/docker/docker/dockerversion.Version=${VERSION} \
-X github.com/docker/docker/dockerversion.GitCommit=${GITCOMMIT} \
-X github.com/docker/docker/dockerversion.BuildTime=${BUILDTIME} \
-X github.com/docker/docker/dockerversion.IAmStatic=${IAMSTATIC:-true} \
-X github.com/docker/docker/dockerversion.PlatformName=${PLATFORM} \
-X github.com/docker/docker/dockerversion.ProductName=${PRODUCT} \
-X github.com/docker/docker/dockerversion.DefaultProductLicense=${DEFAULT_PRODUCT_LICENSE} \
-X github.com/docker/docker/dockerversion.InitCommitID=${TINI_COMMIT} \
"

# Compile the Windows resources into the sources
if [ "$(go env GOOS)" = "windows" ]; then
Expand Down

0 comments on commit 675b414

Please sign in to comment.