git » gofer » commit 68f5b11

debug: Simplify version/timestamp parsing

author Alberto Bertogli
2023-08-03 19:48:43 UTC
committer Alberto Bertogli
2023-08-23 17:10:24 UTC
parent aeb3e58ee993d7e2f3960dc1e3f0c9175e82bcca

debug: Simplify version/timestamp parsing

Remove code for custom version and source timestamp because at the
moment it is unused it just adds unnecessary complexity.

It can be added back if we need it.

Makefile +1 -4
debug/debug.go +8 -31
gofer.go +3 -1

diff --git a/Makefile b/Makefile
index 0329401..84bd0ea 100644
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,7 @@ default: gofer
 # https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal
 
 gofer:
-	go build -ldflags="\
-		-X blitiri.com.ar/go/gofer/debug.Version=${VERSION} \
-		-X blitiri.com.ar/go/gofer/debug.SourceDateTs=${SOURCE_DATE_EPOCH} \
-		" ${GOFLAGS}
+	go build ${GOFLAGS}
 
 vet: config/gofer.yaml etc/gofer.yaml test/01-be.yaml test/01-fe.yaml
 	go vet ./...
diff --git a/debug/debug.go b/debug/debug.go
index 45044a4..24995d2 100644
--- a/debug/debug.go
+++ b/debug/debug.go
@@ -7,7 +7,6 @@ import (
 	"os"
 	"runtime"
 	"runtime/debug"
-	"strconv"
 	"time"
 
 	// Remote profiling support.
@@ -19,15 +18,9 @@ import (
 	"blitiri.com.ar/go/log"
 )
 
-// Build information, overridden at build time using
-// -ldflags="-X blitiri.com.ar/go/gofer/debug.Version=blah".
 var (
-	Version      = ""
-	SourceDateTs = ""
-
-	// Derived from SourceDateTs.
-	SourceDate    = time.Time{}
-	SourceDateStr = ""
+	Version    = ""
+	SourceDate = time.Time{}
 )
 
 func init() {
@@ -38,7 +31,6 @@ func init() {
 
 	dirty := false
 	gitRev := ""
-	gitTime := ""
 	for _, s := range bi.Settings {
 		switch s.Key {
 		case "vcs.modified":
@@ -46,33 +38,18 @@ func init() {
 				dirty = true
 			}
 		case "vcs.time":
-			gitTime = s.Value
+			SourceDate, _ = time.Parse(time.RFC3339, s.Value)
 		case "vcs.revision":
 			gitRev = s.Value
 		}
 	}
 
-	if SourceDateTs != "" {
-		sdts, err := strconv.ParseInt(SourceDateTs, 10, 0)
-		if err != nil {
-			panic(err)
-		}
-
-		SourceDate = time.Unix(sdts, 0)
-	} else {
-		SourceDate, _ = time.Parse(time.RFC3339, gitTime)
+	Version = SourceDate.Format("20060102")
+	if gitRev != "" {
+		Version += fmt.Sprintf("-%.9s", gitRev)
 	}
-	SourceDateStr = SourceDate.Format("2006-01-02 15:04:05 -0700")
-
-	if Version == "" {
-		Version = SourceDate.Format("20060102")
-
-		if gitRev != "" {
-			Version += fmt.Sprintf("-%.9s", gitRev)
-		}
-		if dirty {
-			Version += "-dirty"
-		}
+	if dirty {
+		Version += "-dirty"
 	}
 }
 
diff --git a/gofer.go b/gofer.go
index ec74846..954384c 100644
--- a/gofer.go
+++ b/gofer.go
@@ -28,7 +28,9 @@ var (
 func main() {
 	flag.Parse()
 	log.Init()
-	log.Infof("gofer starting (%s, %s)", debug.Version, debug.SourceDateStr)
+	log.Infof("gofer starting (%s, %s)",
+		debug.Version,
+		debug.SourceDate.Format("2006-01-02 15:04:05 -0700"))
 
 	conf, err := config.Load(*configFile)
 	if err != nil {