File reproducible.patch of Package golang-googlecode-mango-doc

From 1652e5119cfa364fd3fbff4d4766bed207558ddd Mon Sep 17 00:00:00 2001
From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
Date: Mon, 5 Mar 2018 21:09:02 +0100
Subject: [PATCH] Allow to override build date (boo#1047218)

in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
---
 man.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/man.go b/man.go
index f4e29b5..33deea0 100644
--- a/man.go
+++ b/man.go
@@ -6,6 +6,7 @@ import (
 	"go/ast"
 	"go/doc"
 	"go/token"
+	"os"
 	"sort"
 	"strconv"
 	"strings"
@@ -180,7 +181,17 @@ func (m *M) find_refs(extras []string) {
 }
 
 func (m *M) do_header(kind string) {
-	tm := time.Now().Format("2006-01-02")
+	source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH")
+	var tm string
+	if source_date_epoch == "" {
+		tm = time.Now().UTC().Format("2006-01-02")
+	} else {
+		sde, err := strconv.ParseInt(source_date_epoch, 10, 64)
+		if err != nil {
+			panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err))
+		}
+		tm = time.Unix(sde, 0).UTC().Format("2006-01-02")
+	}
 	version := m.version
 	if version == "" {
 		version = tm
-- 
2.13.6

openSUSE Build Service is sponsored by