From 09fb7caebd8a1b7d5a1e0c8e9d8f402a6218b2af Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Tue, 2 Mar 2021 20:41:18 -0600 Subject: [PATCH] Add build date to LDFLAGS --- Makefile | 9 +++++++-- cmd/main.go | 1 + cmd/version.go | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b04a7ae..1b6109e 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,19 @@ -LUME_VERSION ?= $(shell git describe --tags --always) -LDFLAGS := ${LDFLAGS} -X git.kill0.net/chill9/lume/cmd.Version=${LUME_VERSION} ifeq ($(OS), Windows_NT) EXE=lume.exe RM=del /f /q + BUILD_DATE=$(shell powershell Get-Date -Format "yyyy-MM-ddThh:mm:sszzz") else EXE=lume EXE=rm -f + BUILD_DATE=$(shell date --iso-8601=seconds) endif +LUME_VERSION ?= $(shell git describe --tags --always) +LDFLAGS := ${LDFLAGS} \ + -X git.kill0.net/chill9/lume/cmd.Version=${LUME_VERSION} \ + -X git.kill0.net/chill9/lume/cmd.BuildDate=${BUILD_DATE} + .PHONY: build build: go build -o ${EXE} -ldflags="${LDFLAGS}" ./cmd/lume diff --git a/cmd/main.go b/cmd/main.go index 527f040..95b2bbf 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -30,6 +30,7 @@ func init() { } var Version string = "0.1.0-pre" +var BuildDate string const lumercFile string = ".lumerc" diff --git a/cmd/version.go b/cmd/version.go index b02aa14..983a912 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -19,5 +19,8 @@ func VersionCmd(args CmdArgs) (int, error) { fmt.Printf("lume %s\n", Version) fmt.Printf(" os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) fmt.Printf(" go version: %s\n", runtime.Version()) + if BuildDate != "" { + fmt.Printf(" build date: %s\n", BuildDate) + } return ExitSuccess, nil }