From ff564380a71b607821de4eca4afa0865f3c7e51c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 15 Nov 2024 10:51:45 -0600 Subject: [PATCH] fix ldflags --- Makefile | 5 +++-- argv.go | 2 +- buildPackage.go | 15 ++++++++++----- main.go | 3 +-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 1e7f3b0..f758bec 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: debian VERSION = $(shell git describe --tags) +DATE = $(shell date +%Y.%m.%d) run: build ./go-deb --repo go.wit.com/apps/autotypist @@ -17,11 +18,11 @@ build: touch resources/blank.so -cp -a ~/go/src/go.wit.com/toolkits/*.so resources/ # embed the toolkit plugins GO111MODULE="off" go build -v \ - -ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}" + -ldflags "-X main.VERSION=${VERSION} -X main.DATE=${DATE} -X gui.GUIVERSION=${VERSION}" install: GO111MODULE="off" go install -v \ - -ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}" + -ldflags "-X main.VERSION=${VERSION} -X main.DATE=${DATE} -X gui.GUIVERSION=${VERSION}" goimports: goimports -w *.go diff --git a/argv.go b/argv.go index f7697d3..db8134e 100644 --- a/argv.go +++ b/argv.go @@ -34,5 +34,5 @@ func init() { } func (args) Version() string { - return "go-clone " + VERSION + return "go-clone " + VERSION + " Built on " + DATE } diff --git a/buildPackage.go b/buildPackage.go index 498662e..8d3bba2 100644 --- a/buildPackage.go +++ b/buildPackage.go @@ -72,14 +72,19 @@ func (c *controlBox) buildPackage() (bool, error) { os.Setenv("GO111MODULE", "off") cmd := []string{"go", "build", "-v", "-x"} + // set standard ldflag options + now := time.Now() + datestamp := now.UTC().Format("2006/01/02_1504_UTC") + log.Info("datestamp =", datestamp) // add some standard golang flags - vldflag := "-X main.VERSION=" + version - gldflag := "-X main.GUIVERSION=" + version // todo: git this from the filesystem - // timeflag := "-X main.BUILDTIME='${BUILDTIME}'" - cmd = append(cmd, "-ldflags", vldflag) - cmd = append(cmd, "-ldflags", gldflag) + ldflags := "-X main.VERSION=" + version + " " + ldflags += "-X main.BUILDTIME=" + datestamp + " " + ldflags += "-X main.GUIVERSION=" + version + "" // todo: git this from the filesystem + cmd = append(cmd, "-ldflags", ldflags) // add any flags from the command line + // this might not actually work + // todo: test this for _, flag := range argv.Ldflags { cmd = append(cmd, "-ldflags", "-X "+flag) } diff --git a/main.go b/main.go index 4f30d19..26bc80a 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( // sent from -ldflags var VERSION string +var DATE string // This is the beginning of the binary tree of GUI widgets var myGui *gui.Node @@ -27,8 +28,6 @@ var basicWindow *gadgets.BasicWindow var resources embed.FS func main() { - // RunTest() - // os.Exit(0) if argv.Repo == "" { log.Info("You need to tell me what repo you want to work on") println("")