Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Jérôme Pouiller" <jezz@sysmic.org>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v4 09/18] fakedate: new package
Date: Wed, 23 Nov 2016 13:58:48 +0100	[thread overview]
Message-ID: <1479905937-17241-10-git-send-email-jezz@sysmic.org> (raw)
In-Reply-To: <1479905937-17241-1-git-send-email-jezz@sysmic.org>

`date' is widely used by packages to include build information in their
binaries. Unfortunately, this is incompatible with  BR2_REPRODUCIBLE.

Instead of having to identify all `date' invocations in the different
packages, this commit adds a small tool that allows to always return
the same date.

This work was sponsored by `BA Robotic Systems'.

Signed-off-by: J?r?me Pouiller <jezz@sysmic.org>
---

Notes:
    v3:
      - Do not force $PATH. Find true `date' binary instead (Thomas)
      - Add explanations (Thomas)
      - Fix options detection (Arnout)
      - Rename INHIBIT in FORCE_EPOCH (Thomas)
      - Break after FORCE_EPOCH=0 (Arnout)
      - Add support for '--reference'
      - Add full copyright blurb (Arnout)

 package/fakedate/fakedate    | 59 ++++++++++++++++++++++++++++++++++++++++++++
 package/fakedate/fakedate.mk | 15 +++++++++++
 2 files changed, 74 insertions(+)
 create mode 100755 package/fakedate/fakedate
 create mode 100644 package/fakedate/fakedate.mk

diff --git a/package/fakedate/fakedate b/package/fakedate/fakedate
new file mode 100755
index 0000000..074c517
--- /dev/null
+++ b/package/fakedate/fakedate
@@ -0,0 +1,59 @@
+#!/bin/sh
+# vim: set sw=4 expandtab:
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Copyright (C) 2016 J?r?me Pouiller <jezz@sysmic.org>
+#
+LOG=/dev/null
+
+# Sanity check
+if ! readlink -f "$0" | grep -q fakedate; then
+    echo "fakedate: Please name this script \`fakedate'"
+    exit 1
+fi
+
+DATE_BIN=false
+# Do not call `date'd directly since it will produce an infinite recursion.
+# Instead, find path of true `date' binary.
+for P in `echo $PATH | tr ':' ' '`; do
+    if [ -x "$P/date" ]; then
+        if readlink -f "$P/date" | grep -qv fakedate; then
+            DATE_BIN="$P/date"
+            break;
+        fi
+    fi
+done
+
+if [ -n "$SOURCE_DATE_EPOCH" ]; then
+    FORCE_EPOCH=1
+    for i in "$@"; do
+        # Use of --date, --file and --reference (and their short option counter
+        # parts) is incompatible with SOURCE_DATE_EPOCH.
+        # -u and -R are the only short options without argument. So they could
+        # appear between '-' and option we want to match.
+        if echo "$i" | grep -qE '^-([uR]*d|-date|[uR]*f|-file|[uR]*r|--reference)'; then
+            FORCE_EPOCH=0
+            break;
+        fi
+    done
+    if [ $FORCE_EPOCH -eq 1 ]; then
+        echo "date: Warning: using \$SOURCE_DATE_EPOCH instead of true time" >&2
+        echo "Catch call to date from `pwd` with parameters: '$@'" >> $LOG
+        exec $DATE_BIN -d "@$SOURCE_DATE_EPOCH" "$@"
+    fi
+fi
+
+exec $DATE_BIN "$@"
diff --git a/package/fakedate/fakedate.mk b/package/fakedate/fakedate.mk
new file mode 100644
index 0000000..61d4bd7
--- /dev/null
+++ b/package/fakedate/fakedate.mk
@@ -0,0 +1,15 @@
+################################################################################
+#
+# fakedate
+#
+################################################################################
+
+# source included in buildroot
+HOST_FAKEDATE_LICENSE = GPLv2+
+
+define HOST_FAKEDATE_INSTALL_CMDS
+	$(INSTALL) -D -m 755 package/fakedate/fakedate $(HOST_DIR)/usr/bin/fakedate
+	ln -sfn fakedate $(HOST_DIR)/usr/bin/date
+endef
+
+$(eval $(host-generic-package))
-- 
1.9.1

  parent reply	other threads:[~2016-11-23 12:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23 12:58 [Buildroot] [PATCH v4 00/18] Reproducible builds Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 01/18] reproducibility: generate SOURCE_DATE_EPOCH Jérôme Pouiller
2016-11-23 21:49   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 02/18] reproducible: fix DATE/TIME macros in toolchain-wrapper Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 03/18] reproducible: add '-n' to gzip invocations Jérôme Pouiller
2016-11-23 21:49   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 04/18] fs/tar: make results reproducible Jérôme Pouiller
2016-11-23 21:56   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 05/18] reproducibility/linux: override build timestamp Jérôme Pouiller
2016-11-23 21:56   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 06/18] reproducibility/linux: inhibit build-id Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 07/18] reproducibility/busybox: disable build timestamps Jérôme Pouiller
2016-11-23 21:57   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 08/18] reproducible: lock modification times in $TARGET_DIR Jérôme Pouiller
2016-11-23 21:59   ` Thomas Petazzoni
2016-11-23 12:58 ` Jérôme Pouiller [this message]
2016-11-23 12:58 ` [Buildroot] [PATCH v4 10/18] core: do not reset DEPENDENCIES_HOST_PREREQ in dependencies.mk Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 11/18] reproducible: enable fakedate Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 12/18] pycompile: allow to force compilation Jérôme Pouiller
2016-11-23 22:03   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 13/18] python2: generate reproducible .pyc Jérôme Pouiller
2016-11-23 22:05   ` Thomas Petazzoni
2016-11-24 19:06     ` Arnout Vandecappelle
2016-11-26 16:00       ` Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 14/18] python3: " Jérôme Pouiller
2016-11-23 22:09   ` Thomas Petazzoni
2016-11-26 16:20     ` Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 15/18] python2: remove full path from .pyc Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 16/18] python3: " Jérôme Pouiller
2016-11-23 12:58 ` [Buildroot] [PATCH v4 17/18] reproducible: improve help text Jérôme Pouiller
2016-11-23 22:09   ` Thomas Petazzoni
2016-11-23 12:58 ` [Buildroot] [PATCH v4 18/18] reproducible: fix coding style Jérôme Pouiller
2016-11-23 22:10   ` Thomas Petazzoni

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=1479905937-17241-10-git-send-email-jezz@sysmic.org \
    --to=jezz@sysmic.org \
    --cc=buildroot@busybox.net \
    /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