rpm/0001-set-SOURCE_DATE_EPOCH-from-changelog.patch

63 lines
2.1 KiB
Diff
Raw Normal View History

From 42906a9c5da4c89128ed8ffb619f8ef1fa2d9b93 Mon Sep 17 00:00:00 2001
From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
Date: Fri, 27 Jan 2017 13:01:57 +0100
Subject: [PATCH 1/4] set SOURCE_DATE_EPOCH from changelog
if requested by macro
to allow for more reproducible builds of packages.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
(cherry picked from commit 0e87aed1785d0531c40b23889f8338744f6abb3a)
---
build/build.c | 15 +++++++++++++++
macros.in | 4 ++++
2 files changed, 19 insertions(+)
diff --git a/build/build.c b/build/build.c
index 04b039c..89b04ce 100644
--- build/build.c
+++ build/build.c
@@ -209,6 +209,21 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what)
int test = (what & RPMBUILD_NOBUILD);
char *cookie = buildArgs->cookie ? xstrdup(buildArgs->cookie) : NULL;
+ if (rpmExpandNumeric("%{?source_date_epoch_from_changelog}") &&
+ getenv("SOURCE_DATE_EPOCH") == NULL) {
+ /* Use date of first (== latest) changelog entry */
+ Header h = spec->packages->header;
+ struct rpmtd_s td;
+ if (headerGet(h, RPMTAG_CHANGELOGTIME, &td, (HEADERGET_MINMEM|HEADERGET_RAW))) {
+ char sdestr[22];
+ snprintf(sdestr, sizeof(sdestr), "%lli",
+ (long long) rpmtdGetNumber(&td));
+ rpmlog(RPMLOG_NOTICE, _("setting %s=%s\n"), "SOURCE_DATE_EPOCH", sdestr);
+ setenv("SOURCE_DATE_EPOCH", sdestr, 0);
+ rpmtdFreeData(&td);
+ }
+ }
+
/* XXX TODO: rootDir is only relevant during build, eliminate from spec */
spec->rootDir = buildArgs->rootdir;
if (!spec->recursing && spec->BACount) {
diff --git a/macros.in b/macros.in
index fd57f2e..85f172a 100644
--- macros.in
+++ macros.in
@@ -210,6 +210,10 @@ package or when debugging this package.\
# Any older entry is not packaged in binary packages.
%_changelog_trimtime 0
+# If true, set the SOURCE_DATE_EPOCH environment variable
+# to the timestamp of the topmost changelog entry
+%source_date_epoch_from_changelog 0
+
# The directory where newly built binary packages will be written.
%_rpmdir %{_topdir}/RPMS
--
2.10.2