core: rpm: Do use source_date_epoch also for fakeStat
PATCH 1/3 core: rpm: Do use source_date_epoch also for fakeStat
From: Jan-Simon Möller <[email protected]>
This makes sure that if we enforce SOURCE_DATE_EPOCH we do also set this for entries returned by the fakeStat function of rpm.
Upstream status: pending
--- ...-the-timestamps-returned-by-fakeStat.patch | 46 +++++++++++++++++++ meta/recipes-devtools/rpm/rpm_4.16.1.2.bb | 1 + 2 files changed, 47 insertions(+) create mode 100644 meta/recipes-devtools/rpm/files/0001-Also-clamp-the-timestamps-returned-by-fakeStat.patch
meta/recipes-devtools/rpm/files/0001-Also-clamp-the-timestamps-returned-by-fakeStat.patch new file +46 -0
@@ -0,0 +1,46 @@ +From b79d505fc408a41616d51329895a27c99cbbaeaf Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= <[email protected]> +Date: Thu, 18 Feb 2021 16:26:58 +0100 +Subject: [PATCH] Also clamp the timestamps returned by fakeStat +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Use the source_data_epoch also for the fakeStat supplied entries. + +Upstream status: pending + +Signed-off-by: Jan-Simon Möller <[email protected]> +--- + build/files.c | 18 ++++++++++++++++++ + 1 file changed, 18 insertions(+) + +diff --git a/build/files.c b/build/files.c +index 47625905c..75ec0792f 100644 +--- a/build/files.c ++++ b/build/files.c +@@ -1304,6 +1304,24 @@ static rpmRC recurseDir(FileList fl, const char * diskPath); + static struct stat * fakeStat(FileEntry cur, struct stat * statp) + { + time_t now = time(NULL); ++ time_t source_date_epoch = 0; ++ char *srcdate = getenv("SOURCE_DATE_EPOCH"); ++ ++ /* Limit the maximum date to SOURCE_DATE_EPOCH if defined ++ * similar to the tar --clamp-mtime option ++ * https://reproducible-builds.org/specs/source-date-epoch/ ++ */ ++ if (srcdate && rpmExpandNumeric("%{?clamp_mtime_to_source_date_epoch}")) { ++ char *endptr; ++ errno = 0; ++ source_date_epoch = strtol(srcdate, &endptr, 10); ++ if (srcdate == endptr || *endptr || errno != 0) { ++ rpmlog(RPMLOG_ERR, _("unable to parse %s=%s\n"), "SOURCE_DATE_EPOCH", srcdate); ++ } else { ++ now = source_date_epoch; ++ } ++ } ++ + + if (cur->devtype) { + statp->st_rdev = ((cur->devmajor & 0xff) << 8) | (cur->devminor & 0xff);
meta/recipes-devtools/rpm/rpm_4.16.1.2.bb +1 -0
@@ -40,6 +40,7 @@ SRC_URI = "git://github.com/rpm-software-management/rpm;branch=rpm-4.16.x \ file://0016-rpmscript.c-change-logging-level-around-scriptlets-t.patch \ file://0001-lib-transaction.c-fix-file-conflicts-for-MIPS64-N32.patch \ file://0001-tools-Add-error.h-for-non-glibc-case.patch \ + file://0001-Also-clamp-the-timestamps-returned-by-fakeStat.patch \ " PE = "1"
--
2.26.2
PATCH 2/3 reproducible_builds: SOURCE_DATE_EPOCH should not be 0
From: Jan-Simon Möller <[email protected]>
A SOURCE_DATE_EPOCH of 0 might be misinterpreted by namely rpm as no SDE.
e.g.:
char *srcdate = getenv(SOURCE_DATE_EPOCH);
if (srcdate && rpmExpandNumeric(%{?clamp_mtime_to_source_date_epoch}))
Solve this by:
- providing a SOURCE_DATE_EPOCH_FALLBACK variable != 0
- changing defaults to use it
- using SOURCE_DATE_EPOCH_FALLBACK also when reading 0 out of sstate-cache
--- meta/classes/reproducible_build.bbclass | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
meta/classes/reproducible_build.bbclass +15 -4
@@ -37,10 +37,13 @@ BUILD_REPRODUCIBLE_BINARIES ??= '1' inherit ${@oe.utils.ifelse(d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1', 'reproducible_build_simple', '')} -SDE_DIR ="${WORKDIR}/source-date-epoch" +SDE_DIR = "${WORKDIR}/source-date-epoch" SDE_FILE = "${SDE_DIR}/__source_date_epoch.txt" SDE_DEPLOYDIR = "${WORKDIR}/deploy-source-date-epoch" +# A SOURCE_DATE_EPOCH of '0' might be misinterpreted as no SDE +export SOURCE_DATE_EPOCH_FALLBACK ??= "1302044400" + SSTATETASKS += "do_deploy_source_date_epoch" do_deploy_source_date_epoch () {
@@ -81,6 +84,10 @@ python create_source_date_epoch_stamp() { source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S')) + if source_date_epoch == 0 : + bb.debug(1, "source_date_epoch is 0, using SOURCE_DATE_EPOCH_FALLBACK instead.") + source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) + bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) bb.utils.mkdirhier(d.getVar('SDE_DIR')) with open(epochfile, 'w') as f:
@@ -93,15 +100,19 @@ def get_source_date_epoch_value(d): return cached epochfile = d.getVar('SDE_FILE') - source_date_epoch = 0 + source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) if os.path.isfile(epochfile): with open(epochfile, 'r') as f: s = f.read() try: source_date_epoch = int(s) + # workaround for old sstate with SDE_FILE content being 0 - use SOURCE_DATE_EPOCH_FALLBACK + if source_date_epoch == 0 : + bb.warn("SOURCE_DATE_EPOCH value from sstate '%s' is deprecated/invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK '%s'" % (s, SOURCE_DATE_EPOCH_FALLBACK)) + source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) except ValueError: - bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to 0" % s) - source_date_epoch = 0 + bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s) + source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) else: bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch))
--
2.26.2
PATCH 3/3 oe-selftests: add rpm to reproducible build selftest
In reply to Jan-Simon MöllerFrom: Jan-Simon Möller <[email protected]>
rpm packaging has shown good numbers wrt reproducible builds as well when testing core-image-minimal locally:
Reproducibility summary for rpm: same=4671 different=0 missing=0 total=4671
Thus enable it in the autobuilder to be more widely tested.
(From OE-Core rev: 84d3a90557444d8cd83d780b1c3f2b278ab07af2)
--- meta/lib/oeqa/selftest/cases/reproducible.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/reproducible.py +1 -1
@@ -173,7 +173,7 @@ class DiffoscopeTests(OESelftestTestCase): self.assertTrue(os.path.exists(os.path.join(tmpdir, 'index.html')), "HTML index not found!") class ReproducibleTests(OESelftestTestCase): - package_classes = ['deb', 'ipk'] + package_classes = ['deb', 'ipk', 'rpm'] images = ['core-image-minimal', 'core-image-sato', 'core-image-full-cmdline', 'world'] save_results = False if 'OEQA_DEBUGGING_SAVED_OUTPUT' in os.environ:
--
2.26.2