[Rpm-ecosystem] Reproducible Builds

Nicolas Vigier boklm at mars-attacks.org
Fri Mar 4 15:43:05 UTC 2016


Hi!

On Tue, 01 Mar 2016, Florian Festi wrote:

> 
> So I want to focus the different pieces of work on rpm(build) here. So
> far I found:
> 
>  * The SOURCE_DATE_EPOCH patch mentioned above [1]
>   * Still unfinished patch for file timestamps mentioned there

You can find attached a patch to allow SOURCE_DATE_EPOCH to override the
file timestamps.

Nicolas

-------------- next part --------------
From 46f96f03ad94faea7cef06fe87bfbb6254a255ec Mon Sep 17 00:00:00 2001
From: Nicolas Vigier <boklm at torproject.org>
Date: Fri, 4 Mar 2016 16:25:43 +0100
Subject: [PATCH] Allow SOURCE_DATE_EPOCH to override file timestamps

---
 build/files.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/build/files.c b/build/files.c
index 81bb6004d667..1479ecfe599c 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1206,6 +1206,36 @@ static struct stat * fakeStat(FileEntry cur, struct stat * statp)
     return statp;
 }
 
+/*
+ * Get the date from SOURCE_DATE_EPOCH or 0 if not defined
+ *
+ * https://reproducible-builds.org/specs/source-date-epoch/
+ */
+static time_t sourceDateEpoch()
+{
+    static time_t res;
+    static int done;
+    char *srcdate;
+    char *endptr;
+    time_t epoch;
+
+    if (done)
+        return res;
+
+    srcdate = getenv("SOURCE_DATE_EPOCH");
+    if (srcdate) {
+        errno = 0;
+        epoch = strtol(srcdate, &endptr, 10);
+        if (srcdate == endptr || *endptr || errno != 0)
+            rpmlog(RPMLOG_WARNING, _("unable to parse SOURCE_DATE_EPOCH\n"));
+        else
+            res = epoch;
+    }
+
+    done = 1;
+    return res;
+}
+
 /**
  * Add a file to the package manifest.
  * @param fl		package file tree walk data
@@ -1226,6 +1256,7 @@ static rpmRC addFile(FileList fl, const char * diskPath,
     const char *fileUname;
     const char *fileGname;
     rpmRC rc = RPMRC_FAIL; /* assume failure */
+    time_t srcDate = sourceDateEpoch();
 
     /* Strip trailing slash. The special case of '/' path is handled below. */
     if (plen > 0 && diskPath[plen - 1] == '/') {
@@ -1363,6 +1394,8 @@ static rpmRC addFile(FileList fl, const char * diskPath,
 	flp->fl_mode = fileMode;
 	flp->fl_uid = fileUid;
 	flp->fl_gid = fileGid;
+	if (srcDate)
+            flp->fl_mtime = srcDate;
 
 	flp->cpioPath = xstrdup(cpioPath);
 	flp->diskPath = xstrdup(diskPath);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.rpm.org/pipermail/rpm-ecosystem/attachments/20160304/6203b51e/attachment.asc>


More information about the Rpm-ecosystem mailing list