mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: "Baeuerle, Florian" <Florian.Baeuerle@allegion.com>
To: "ptxdist@pengutronix.de" <ptxdist@pengutronix.de>
Subject: [ptxdist] [PATCH 1/4] config/setup: make reproducible builds configurable
Date: Fri, 26 Oct 2018 13:46:56 +0000	[thread overview]
Message-ID: <20181026134644.22900-2-florian.baeuerle@allegion.com> (raw)
In-Reply-To: <20181026134644.22900-1-florian.baeuerle@allegion.com>

Some of ptxdist's packages use SOURCE_DATE_EPOCH to make the build
results predictable. Make this behaviour more configurable via a newly
introduced ptxdist setup options.

By default, this will set SOURCE_DATE_EPOCH to the year and month of the
used OSELAS Toolchain version. If the used toolchain is not an
OSELAS-Toolchain, the PTXdist version is used as a fallback.

Signed-off-by: Florian Bäuerle <florian.baeuerle@allegion.com>
---
 config/setup/Kconfig                 | 47 ++++++++++++++++++++++++++
 config/setup/ptxdistrc.default       |  5 +++
 scripts/lib/ptxd_lib_reproducible.sh | 49 +++++++++++++++++++++++++++-
 3 files changed, 100 insertions(+), 1 deletion(-)

diff --git a/config/setup/Kconfig b/config/setup/Kconfig
index 990da03a1..10adb970d 100644
--- a/config/setup/Kconfig
+++ b/config/setup/Kconfig
@@ -264,6 +264,53 @@ config SETUP_DISABLE_LOCAL_CHECK
 	  may fail under certain circumstances.
 	  Disable this check at your own risk.
 
+config SETUP_DISABLE_REPRODUCIBLE
+	bool
+	prompt "disable reproducible builds"
+	help
+	  By default ptxdist will build some packages in a
+	  reproducible way by injecting fake timestamps, user and
+	  host name into the build.
+
+if !SETUP_DISABLE_REPRODUCIBLE
+
+choice
+	prompt "Fake timestamps source"
+	default SETUP_REPRODUCIBLE_TIMESTAMP_TOOLCHAIN
+
+	config SETUP_REPRODUCIBLE_TIMESTAMP_TOOLCHAIN
+		bool
+		prompt "toolchain version"
+
+	config SETUP_REPRODUCIBLE_TIMESTAMP_PTXDIST
+		bool
+		prompt "ptxdist version"
+
+	config SETUP_REPRODUCIBLE_TIMESTAMP_CUSTOM
+		bool
+		prompt "custom timestamp"
+
+endchoice
+
+config SETUP_REPRODUCIBLE_TIMESTAMP
+	string
+	default "toolchain" if SETUP_REPRODUCIBLE_TIMESTAMP_TOOLCHAIN
+	default "ptxdist" if SETUP_REPRODUCIBLE_TIMESTAMP_PTXDIST
+	default "custom" if SETUP_REPRODUCIBLE_TIMESTAMP_CUSTOM
+
+if SETUP_REPRODUCIBLE_TIMESTAMP_CUSTOM
+
+config SETUP_REPRODUCIBLE_TIMESTAMP_STRING
+	string
+	prompt "Fake timestamp"
+	default "2018-11-01 UTC"
+	help
+	  Supply a custom fake timestamp to be injected to the build.
+	  The timestamp is passed to 'date --date'.
+
+endif
+endif
+
 config SETUP_ENV_WHITELIST
 	string "environment variable whitelist (space separated)"
 	help
diff --git a/config/setup/ptxdistrc.default b/config/setup/ptxdistrc.default
index 397b78eb7..8aa7dcc9a 100644
--- a/config/setup/ptxdistrc.default
+++ b/config/setup/ptxdistrc.default
@@ -61,6 +61,11 @@ PTXCONF_SETUP_JAVA_SDK="/usr/lib/jvm/default-java"
 # Developer Options 
 #
 # PTXCONF_SETUP_DISABLE_LOCAL_CHECK is not set
+# PTXCONF_SETUP_DISABLE_REPRODUCIBLE is not set
+PTXCONF_SETUP_REPRODUCIBLE_TIMESTAMP_TOOLCHAIN=y
+# PTXCONF_SETUP_REPRODUCIBLE_TIMESTAMP_PTXDIST is not set
+# PTXCONF_SETUP_REPRODUCIBLE_TIMESTAMP_CUSTOM is not set
+PTXCONF_SETUP_REPRODUCIBLE_TIMESTAMP="toolchain"
 PTXCONF_SETUP_ENV_WHITELIST=""
 # PTXCONF_SETUP_COMMON_CACHE is not set
 # PTXCONF_SETUP_GEN_DEP_TREE is not set
diff --git a/scripts/lib/ptxd_lib_reproducible.sh b/scripts/lib/ptxd_lib_reproducible.sh
index f0c1bcf8f..06e00e00b 100644
--- a/scripts/lib/ptxd_lib_reproducible.sh
+++ b/scripts/lib/ptxd_lib_reproducible.sh
@@ -8,8 +8,55 @@
 # see the README file.
 #
 
+ptxd_timestamp_ptxdist() {
+    ptxd_reply="${PTXDIST_VERSION_YEAR}-${PTXDIST_VERSION_MONTH}-01 UTC"
+}
+
+ptxd_timestamp_toolchain() {
+    local oselas_ptxconfig="$(readlink -f "${PTXDIST_TOOLCHAIN}/ptxconfig")"
+
+    if [ -e "${oselas_ptxconfig}" ]; then
+        local oselas_version="$(source "${oselas_ptxconfig}" && echo ${PTXCONF_CONFIGFILE_VERSION})"
+        local orig_IFS="${IFS}"
+        local IFS="."
+        set -- ${oselas_version}
+        IFS="${orig_IFS}"
+        ptxd_reply="${1}-${2}-01 UTC"
+    else
+        echo "${PTXDIST_LOG_PROMPT}warning: cannot deduce timestamp from toolchain, falling back to PTXdist version for reproducible timestamp"
+        ptxd_timestamp_ptxdist
+    fi
+}
+
+ptxd_timestamp_custom() {
+    local ts="${PTXCONF_SETUP_REPRODUCIBLE_TIMESTAMP_STRING}"
+
+    if ! date --date "${ts}" > /dev/null 2>&1; then
+        echo "${PTXDIST_LOG_PROMPT}warning: '${ts}' is not a valid timestamp, falling back to toolchain for reproducible timestamp"
+        ptxd_timestamp_toolchain
+    else
+        ptxd_reply="${ts}"
+    fi
+}
+
 ptxd_lib_reproducible() {
-    SOURCE_DATE_EPOCH="$(echo $(date --date="${PTXDIST_VERSION_YEAR}-${PTXDIST_VERSION_MONTH}-01 UTC" "+%s"))"
+    if [ "${PTXCONF_SETUP_DISABLE_REPRODUCIBLE}" = "y" ]; then
+        ptxd_timestamp_ptxdist
+    else
+        case "${PTXCONF_SETUP_REPRODUCIBLE_TIMESTAMP}" in
+            "custom")
+                ptxd_timestamp_custom
+                ;;
+            "ptxdist")
+                ptxd_timestamp_ptxdist
+                ;;
+            *)
+                ptxd_timestamp_toolchain
+                ;;
+        esac
+    fi
+
+    SOURCE_DATE_EPOCH="$(echo $(date --date="${ptxd_reply}" "+%s"))"
     export SOURCE_DATE_EPOCH
 }
 export -f ptxd_lib_reproducible
-- 
2.19.0

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

  reply	other threads:[~2018-10-26 13:47 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11 14:19 [ptxdist] [PATCH 1/3] host-faketime: new package Baeuerle, Florian
2018-10-11 14:19 ` [ptxdist] [PATCH 2/3] barebox: add option for building barebox reproducibly Baeuerle, Florian
2018-10-12  7:59   ` Baeuerle, Florian
2018-10-12 12:01   ` Michael Olbrich
2018-10-12 12:21     ` Baeuerle, Florian
2018-10-24  8:19       ` Michael Olbrich
2018-10-26 13:46         ` [ptxdist] [PATCH 0/2] Barebox reproducible build + ptxdist setup configuration Baeuerle, Florian
2018-10-26 13:46           ` Baeuerle, Florian [this message]
2018-10-26 13:46           ` [ptxdist] [PATCH 2/4] barebox: depend on HOST_LZOP Baeuerle, Florian
2018-10-26 13:46           ` [ptxdist] [PATCH 3/4] lzop: add patch that allows overriding mtime Baeuerle, Florian
2018-10-26 13:46           ` [ptxdist] [PATCH 4/4] barebox: add support for reproducible build Baeuerle, Florian
2018-10-12 12:28     ` [ptxdist] [PATCH 2/3] barebox: add option for building barebox reproducibly Baeuerle, Florian
2018-10-16  8:59       ` Michael Olbrich
2018-10-16 11:06         ` Baeuerle, Florian
2018-10-16 12:51           ` Michael Olbrich
2018-10-16 14:11             ` Baeuerle, Florian
2018-10-16 19:06               ` Michael Olbrich
2018-10-16 10:09   ` Michael Olbrich
2018-10-16 10:57     ` Baeuerle, Florian
2018-10-16 12:38       ` Michael Olbrich
2018-10-16 14:27         ` Baeuerle, Florian
2018-10-16 19:20           ` Michael Olbrich
2018-10-16 17:15       ` Alexander Dahl
2018-10-16 19:13         ` Michael Olbrich
2018-10-11 14:19 ` [ptxdist] [PATCH 3/3] barebox_mlo: add option for building barebox_mlo reproducibly Baeuerle, Florian
2018-10-11 14:43 ` [ptxdist] [PATCH 1/3] host-faketime: new package Roland Hieber
2018-10-11 21:30   ` Jon Ringle
2018-10-16  7:33     ` Baeuerle, Florian
2018-10-16  8:47       ` Michael Olbrich
2018-10-12  7:47   ` Baeuerle, Florian
2018-10-16  8:51     ` Michael Olbrich
2018-10-16 11:34       ` Alexander Dahl
2018-10-16 12:30         ` Michael Olbrich
2018-10-16  8:53 ` Michael Olbrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181026134644.22900-2-florian.baeuerle@allegion.com \
    --to=florian.baeuerle@allegion.com \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox