[Reproducible-commits] [debhelper] 09/10: Define SOURCE_DATE_EPOCH when setting build flags

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Jul 12 14:59:12 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository debhelper.

commit c024de550f28aab026fa7bda95f20aa93019a07d
Author: Dhole <dhole at openmailbox.org>
Date:   Thu Jul 2 17:16:13 2015 +0200

    Define SOURCE_DATE_EPOCH when setting build flags
    
    When SOURCE_DATE_EPOCH is defined software which needs a timestamp can use it
    as a reference date instead of the current date and time. For more details,
    see: https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal
    
    The variable is set alongside other build flags, and its value is the time
    of the latest entry in `debian/changelog`.
    
    Closes: #791823
---
 Debian/Debhelper/Dh_Lib.pm | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 783be7b..5a7be7a 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -1147,12 +1147,42 @@ sub cross_command {
 	}
 }
 
+# Read latest debian/changelog timestamp and export the environment variable
+# SOURCE_DATE_EPOCH with its value, so that any package can read it and replace 
+# calls to localtime (or other undeterministic timestamps) with the exported 
+# timestamp to get reproducible builds.
+sub set_source_date_epoch {
+	eval "use Dpkg::Changelog::Debian";
+	if ($@) {
+		warning "unable to set SOURCE_DATE_EPOCH: $@";
+		return;
+	}
+	eval "use Time::Piece";
+	if ($@) {
+		warning "unable to set SOURCE_DATE_EPOCH: $@";
+		return;
+	}
+
+	my $changelog = Dpkg::Changelog::Debian->new();
+	$changelog->load("debian/changelog");
+
+	my $tt = @{$changelog}[0]->get_timestamp();
+	$tt =~ s/\s*\([^\)]+\)\s*$//; # Remove the optional timezone codename
+	my $timestamp = Time::Piece->strptime($tt, "%a, %d %b %Y %T %z");
+
+	$ENV{SOURCE_DATE_EPOCH} = $timestamp->epoch();
+}
+
 # Sets environment variables from dpkg-buildflags. Avoids changing
 # any existing environment variables.
 sub set_buildflags {
-	return if $ENV{DH_INTERNAL_BUILDFLAGS} || compat(8);
+	return if $ENV{DH_INTERNAL_BUILDFLAGS};
 	$ENV{DH_INTERNAL_BUILDFLAGS}=1;
 
+	set_source_date_epoch();
+
+	return if compat(8);
+
 	eval "use Dpkg::BuildFlags";
 	if ($@) {
 		warning "unable to load build flags: $@";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debhelper.git



More information about the Reproducible-commits mailing list