[Reproducible-commits] [debhelper] 01/05: Define SOURCE_DATE_EPOCH when setting build flags
Mattia Rizzolo
mattia at mapreri.org
Wed Aug 12 17:47:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
mapreri-guest pushed a commit to branch master
in repository debhelper.
commit d9ea95e44a83d9f9288b720fbb15b4d8156fd550
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 +++++++++++++++++++++++++++++++-
debian/changelog | 7 +++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 348144e..c5b2748 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -1143,12 +1143,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: $@";
diff --git a/debian/changelog b/debian/changelog
index ef4455b..2cfd1a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+debhelper (9.20150811+unreleased) UNRELEASED; urgency=medium
+
+ * dh/dh_auto_*: Apply patch from "Dhole" to define
+ SOURCE_DATE_EPOCH. (Closes: #791823)
+
+ -- Niels Thykier <niels at thykier.net> Wed, 12 Aug 2015 10:46:59 +0200
+
debhelper (9.20150811) unstable; urgency=medium
* d/changelog: Add missing entry for dh_md5sums/#786695 in
--
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