From 58beddfae32ca5f75d6568a3ebcf23195f69fe52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20V=C3=A1zquez=20P=C3=BAa?= Date: Wed, 2 May 2018 08:32:26 +0200 Subject: [PATCH] Make build reproducible by implementing SOURCE_DATE_EPOCH env variable --- make.sh | 3 +++ src/toplevel.lisp | 31 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/make.sh b/make.sh index 452a7f29..e32783c3 100755 --- a/make.sh +++ b/make.sh @@ -15,4 +15,7 @@ done shift `expr $OPTIND - 1` OPTIND=1 +# Unix timestamp of the commit we are building +export SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD) + sbcl --load "$BASE/jscl.lisp" --eval "(jscl:bootstrap $VERBOSE)" --eval '(quit)' diff --git a/src/toplevel.lisp b/src/toplevel.lisp index 3898c6a2..8b9365b5 100644 --- a/src/toplevel.lisp +++ b/src/toplevel.lisp @@ -255,16 +255,27 @@ (defun compilation-notice () - #.(multiple-value-bind (second minute hour date month year) - (get-decoded-time) - (declare (ignore second minute hour)) - (format nil "built on ~d ~a ~d" - date - (elt #("" "January" "February" "March" "April" "May" "June" - "July" "August" "September" "October" "November" - "December") - month) - year))) + #.(let ((build-time + ;; The variable SOURCE_DATE_EPOCH specifies the point in + ;; time of the project. It is usually set to the unix + ;; timestamp of the GIT commit being built, to make the + ;; build artifact reproducible. Variable is specified at + ;; + ;; https://reproducible-builds.org/specs/source-date-epoch/ + ;; + (if (sb-posix:getenv "SOURCE_DATE_EPOCH") + (+ (parse-integer (sb-posix:getenv "SOURCE_DATE_EPOCH")) 2208988800) + (get-universal-time)))) + (multiple-value-bind (second minute hour date month year) + (decode-universal-time build-time) + (declare (ignore second minute hour)) + (format nil "built on ~d ~a ~d" + date + (elt #("" "January" "February" "March" "April" "May" "June" + "July" "August" "September" "October" "November" + "December") + month) + year)))) (when (and (string/= (%js-typeof |module|) "undefined") (string= (%js-typeof |phantom|) "undefined"))