From patchwork Tue Dec 20 13:46:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 707434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tjfGj0fnmz9t0m for ; Wed, 21 Dec 2016 00:47:09 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 563082FF2D; Tue, 20 Dec 2016 13:47:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VXUwEzA4jSkx; Tue, 20 Dec 2016 13:46:59 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id D9BD32EDB1; Tue, 20 Dec 2016 13:46:57 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id F12651BFA5C for ; Tue, 20 Dec 2016 13:46:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id EB3D785443 for ; Tue, 20 Dec 2016 13:46:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5FUmZluGL71X for ; Tue, 20 Dec 2016 13:46:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lupi.sysmic.org (sysmic.org [62.210.89.17]) by whitealder.osuosl.org (Postfix) with ESMTPS id 8805D8551E for ; Tue, 20 Dec 2016 13:46:53 +0000 (UTC) Received: from lupi.online.net (sysmic.org [62.210.89.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jezz) by lupi.sysmic.org (Postfix) with ESMTPSA id BC6AE4304C; Tue, 20 Dec 2016 14:46:51 +0100 (CET) From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= To: buildroot@busybox.net Date: Tue, 20 Dec 2016 14:46:19 +0100 Message-Id: <1482241596-31688-3-git-send-email-jezz@sysmic.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1482241596-31688-1-git-send-email-jezz@sysmic.org> References: <1482241596-31688-1-git-send-email-jezz@sysmic.org> MIME-Version: 1.0 Cc: Thomas Petazzoni , =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= Subject: [Buildroot] [PATCH v5 02/19] fakedate: new package X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" `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 Reviewed-by: Samuel Martin --- 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 +# +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))