Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Remove build time in binary
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysses Souza <[email protected]>
  • Loading branch information
ulyssessouza authored and ndeloof committed Jan 7, 2020
1 parent 31e76df commit df1c57e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 24 deletions.
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
include vars.mk

ifeq ($(BUILDTIME),)
BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" 2> /dev/null)
endif
ifeq ($(BUILDTIME),)
BUILDTIME := unknown
$(warning unable to set BUILDTIME. Set the value manually)
endif

LDFLAGS := "-s -w \
-X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \
-X $(PKG_NAME)/internal.Version=$(TAG) \
-X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)"
-X $(PKG_NAME)/internal.Version=$(TAG)"

EXEC_EXT :=
ifeq ($(OS),Windows_NT)
Expand Down
13 changes: 0 additions & 13 deletions internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,22 @@ import (
"fmt"
"runtime"
"strings"
"time"
)

var (
// Version is the git tag that this was built from.
Version = "unknown"
// GitCommit is the commit that this was built from.
GitCommit = "unknown"
// BuildTime is the time at which the binary was built.
BuildTime = "unknown"
)

// FullVersion returns a string of version information.
func FullVersion() string {
res := []string{
fmt.Sprintf("Version: %s", Version),
fmt.Sprintf("Git commit: %s", GitCommit),
fmt.Sprintf("Built: %s", reformatDate(BuildTime)),
fmt.Sprintf("OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH),
}

return strings.Join(res, "\n")
}

// FIXME(chris-crone): use function in docker/cli/cli/command/system/version.go.
func reformatDate(buildTime string) string {
t, errTime := time.Parse(time.RFC3339Nano, buildTime)
if errTime == nil {
return t.Format(time.ANSIC)
}
return buildTime
}
1 change: 0 additions & 1 deletion vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ifeq ($(SHELL),sh.exe)
rm = del /F /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
rmdir = rmdir /S /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
chmod =
BUILDTIME ?= unknown
NULL := nul
else
# The no-op redirection forces make to shell out the commands instead of spawning a process as
Expand Down

0 comments on commit df1c57e

Please sign in to comment.