From 87937205f722dde4fc97b046f05d8231933238ab Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Fri, 25 Sep 2015 19:38:59 +0100 Subject: [PATCH] debian/bin/genorig.py: Make orig tarballs reproducible --- debian/bin/genorig.py | 23 +++++++++++++++++++---- debian/changelog | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/debian/bin/genorig.py b/debian/bin/genorig.py index b072e22fd..2fcfdaadf 100755 --- a/debian/bin/genorig.py +++ b/debian/bin/genorig.py @@ -8,6 +8,7 @@ import os.path import re import shutil import subprocess +import time from debian_linux.debian import Changelog, VersionLinux @@ -79,8 +80,19 @@ class Main(object): self.upstream_extract(self.input_files[0]) if len(self.input_files) > 1: self.upstream_patch(self.input_files[1]) + + # generate() will change file mtimes. Capture the + # original release time so we can apply it to the final + # tarball. Note this doesn't work in case we apply an + # upstream patch, as that doesn't carry a release time. + orig_date = time.strftime( + "%a, %d %b %Y %H:%M:%S +0000", + time.gmtime( + os.stat(os.path.join(self.dir, 'temp/Makefile')) + .st_mtime)) + self.generate() - self.tar() + self.tar(orig_date) finally: shutil.rmtree(self.dir) @@ -170,7 +182,7 @@ class Main(object): os.makedirs(d) shutil.copyfile(temp_j, orig_j) - def tar(self): + def tar(self, orig_date): out = os.path.join("../orig", self.orig_tar) try: os.mkdir("../orig") @@ -182,9 +194,12 @@ class Main(object): except OSError: pass self.log("Generate tarball %s\n" % out) - cmdline = ['tar -caf', out, '-C', self.dir, self.orig] + cmdline = '''(cd '%s' && find '%s' -print0) | + LC_ALL=C sort -z | + tar -C '%s' --no-recursion --null -T - --mtime '%s' -caf '%s' + ''' % (self.dir, self.orig, self.dir, orig_date, out) try: - if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', ' '.join(cmdline)]): + if os.spawnv(os.P_WAIT, '/bin/sh', ['sh', '-c', cmdline]): raise RuntimeError("Can't patch source") os.chmod(out, 0o644) except: diff --git a/debian/changelog b/debian/changelog index 885324d25..262b1b16b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ linux-tools (4.2-1) UNRELEASED; urgency=medium [ Ben Hutchings ] * debian/bin,debian/control,debian/lib/python,debian/rules: Use Python 3 - debian/lib/python: Sync with linux package + * debian/bin/genorig.py: Make orig tarballs reproducible -- Ben Hutchings Fri, 25 Sep 2015 18:42:20 +0100