- revert buildroot macro setting that did more harm than good

- add set_to_buildtime and set_to_source_date_epoch mtime policy
  support
  * new patch: mtime_policy_set.diff
- drop unused 0001-Add-option-to-set-mtime-of-files-in-rpms.patch
  patch

OBS-URL: https://build.opensuse.org/package/show/Base:System/rpm?expand=0&rev=691
This commit is contained in:
2025-02-12 13:48:37 +00:00
committed by Git OBS Bridge
parent 641eb04afc
commit 4bb3c1092c
5 changed files with 53 additions and 148 deletions

View File

@@ -1,122 +0,0 @@
From fc04a1bde1941d2c61a9e33e55c5c492327674ba Mon Sep 17 00:00:00 2001
From: Jan Zerebecki <jan.suse@zerebecki.de>
Date: Thu, 15 Feb 2024 09:57:35 +0100
Subject: [PATCH 1/3] Add option to set mtime of files in rpms
to SOURCE_DATE_EPOCH.
For backwards compatibility the option clamp / limit the maximum mtime
is retained.
Setting it ouright avoids problems with an incorrectly older clock. It
also avoids problems with build scrips that incorrectly change file
mtimes when SOURCE_DATE_EPOCH_MTIME is in use.
mtimes are required to increase with new versions and releases
of an rpm with the same name, as rsync without --checksum and similar
tools would get confused if the content changes without newer mtime.
If SOURCE_DATE_EPOCH_MTIME is set use it instead for file modification time
stamps. It is supposed to be newer. This can be used if we might want to
compare if the file content remains the same when a build dependency
changes while a build script embeds SOURCE_DATE_EPOCH in the file
content.
This can be used to support automatic rebuilds. Normally automatic
rebuilds work, but together with reproducible builds an undesirable
situation may occur. If a build e.g. embeds SOURCE_DATE_EPOCH in the
output, then the output changes every time such a rebuild happens, which
can be very often. This is to be avoided as updating packages without
necessity is too expensive.
---
build/files.c | 33 ++++++++++++++++++++++++++++-----
docs/manual/buildprocess.md | 5 +++--
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/build/files.c b/build/files.c
index c403c806e..cec7999ca 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1033,14 +1033,34 @@ static void genCpioListAndHeader(FileList fl, Package pkg, int isSrc)
rpm_loff_t totalFileSize = 0;
Header h = pkg->header; /* just a shortcut */
int override_date = 0;
+ int set_mtime = 0;
time_t source_date_epoch = 0;
char *srcdate = getenv("SOURCE_DATE_EPOCH");
+ char *msrcdate = getenv("SOURCE_DATE_EPOCH_MTIME");
- /* Limit the maximum date to SOURCE_DATE_EPOCH if defined
- * similar to the tar --clamp-mtime option
+ /* If SOURCE_DATE_EPOCH_MTIME is set use it for file modification time
+ * stamps, it is supposed to be newer. This can be used if we might want to
+ * compare if the file content remains the same when a build dependency
+ * changes while a build script embeds SOURCE_DATE_EPOCH in the file
+ * content. mtimes are required to increase with new versions and releases
+ * of an rpm with the same name, as rsync without --checksum and similar
+ * tools would get confused if the content changes without newer mtime. */
+ if (msrcdate != NULL) {
+ srcdate = msrcdate;
+ }
+
+ /* Set the file mtime to SOURCE_DATE_EPOCH it if requested to make the
+ * resulting rpm reproducible.
* https://reproducible-builds.org/specs/source-date-epoch/
+ *
+ * For backwards compatibility clamp / limit the maximum mtime if requested
+ * similar the tar --clamp-mtime option. Setting it ouright avoids problems
+ * with an incorrectly older clock. It also avoids problems with build
+ * scrips that incorrectly change file mtimes when SOURCE_DATE_EPOCH_MTIME
+ * is in use.
*/
- if (srcdate && rpmExpandNumeric("%{?clamp_mtime_to_source_date_epoch}")) {
+ if (srcdate && (rpmExpandNumeric("%{?clamp_mtime_to_source_date_epoch}")
+ || rpmExpandNumeric("%{?set_mtime_to_source_date_epoch}"))) {
char *endptr;
errno = 0;
source_date_epoch = strtol(srcdate, &endptr, 10);
@@ -1049,6 +1069,9 @@ static void genCpioListAndHeader(FileList fl, Package pkg, int isSrc)
fl->processingFailed = 1;
}
override_date = 1;
+ if (rpmExpandNumeric("%{?set_mtime_to_source_date_epoch}")) {
+ set_mtime = 1;
+ }
}
/*
@@ -1191,8 +1214,8 @@ static void genCpioListAndHeader(FileList fl, Package pkg, int isSrc)
totalFileSize += flp->fl_size;
}
}
-
- if (override_date && flp->fl_mtime > source_date_epoch) {
+
+ if (override_date && (flp->fl_mtime > source_date_epoch || set_mtime)) {
flp->fl_mtime = source_date_epoch;
}
/*
diff --git a/docs/manual/buildprocess.md b/docs/manual/buildprocess.md
index 1ceb47a7e..64cd35626 100644
--- a/docs/manual/buildprocess.md
+++ b/docs/manual/buildprocess.md
@@ -94,13 +94,14 @@ Macro name | Description
`%_build_pkgcheck` | Progam to run on each generated binary package
`%_build_pkcheck_set` | Program to run on the generated binary package set
-### Reproducability
+### Reproducibility
Macro name | Description
--------------------------------------|-----------
`%source_date_epoch_from_changelog` | Set `SOURCE_DATE_EPOCH` from latest `%changelog` entry
`%use_source_date_epoch_as_buildtime` | Set package BuildTime to `SOURCE_DATE_EPOCH`
-`%clamp_mtime_to_source_date_epoch` | Ensure file timestamps are not newer than `SOURCE_DATE_EPOCH`
+`%set_mtime_to_source_date_epoch` | Set file modification timestamps to `SOURCE_DATE_EPOCH_MTIME` or as fallback to `SOURCE_DATE_EPOCH`
+`%clamp_mtime_to_source_date_epoch` | You should use the above instead, it is for backwards compatibility only. Ensure file timestamps are not newer than `SOURCE_DATE_EPOCH`
### Vendor defaults
--
2.30.2

View File

@@ -1,16 +1,6 @@
--- macros.in.orig 2024-12-16 12:48:44.110837972 +0000
+++ macros.in 2024-12-16 12:52:32.014378635 +0000
@@ -118,6 +118,9 @@
# The directory where sources/patches will be unpacked and built.
%_builddir %{_topdir}/BUILD
+# The build root where built files will be installed into
+%buildroot %{_builddir}/%{NAME}-%{VERSION}-build/BUILDROOT
+
# The interpreter used for build scriptlets.
%_buildshell /bin/sh
@@ -163,6 +166,7 @@
--- macros.in.orig 2025-02-12 13:23:21.868124201 +0000
+++ macros.in 2025-02-12 13:23:58.436059109 +0000
@@ -163,6 +163,7 @@
%{?_unique_debug_names:--unique-debug-suffix "-%{VERSION}-%{RELEASE}.%{_arch}"} \\\
%{?_unique_debug_srcs:--unique-debug-src-base "%{name}-%{VERSION}-%{RELEASE}.%{_arch}"} \\\
%{?_find_debuginfo_dwz_opts} \\\
@@ -18,7 +8,7 @@
%{?_find_debuginfo_opts} \\\
%{?_debugsource_packages:-S debugsourcefiles.list} \\\
"%{builddir}/%{?buildsubdir}"\
@@ -216,7 +220,8 @@ Supplements: (%{name} = %{version}-%{r
@@ -216,7 +217,8 @@ Supplements: (%{name} = %{version}-%{r
%files langpack-%{1}\
%{nil}
@@ -28,7 +18,7 @@
%_defaultlicensedir %{_datadir}/licenses
# Following macros for filtering auto deps must not be used in spec files.
@@ -275,7 +280,8 @@ Supplements: (%{name} = %{version}-%{r
@@ -275,7 +277,8 @@ Supplements: (%{name} = %{version}-%{r
%_tmppath %{_var}/tmp
# Path to top of build area.
@@ -38,7 +28,7 @@
#==============================================================================
# ---- Optional rpmrc macros.
@@ -366,7 +372,7 @@ Supplements: (%{name} = %{version}-%{r
@@ -366,7 +369,7 @@ Supplements: (%{name} = %{version}-%{r
# "w.ufdio" uncompressed
#
#%_source_payload w9.gzdio
@@ -47,7 +37,7 @@
# Algorithm to use for generating file checksum digests on build.
# If not specified or 0, MD5 is used.
@@ -476,6 +482,19 @@ Supplements: (%{name} = %{version}-%{r
@@ -476,6 +479,19 @@ Supplements: (%{name} = %{version}-%{r
#
#%_include_minidebuginfo 1
@@ -67,7 +57,7 @@
#
# Include a .gdb_index section in the .debug files.
# Requires _enable_debug_packages and gdb-add-index installed.
@@ -508,39 +527,39 @@ Supplements: (%{name} = %{version}-%{r
@@ -508,39 +524,39 @@ Supplements: (%{name} = %{version}-%{r
# Same as for "separate" but if the __debug_package global is set then
# the -debuginfo package will have a compatibility link for the main
# ELF /usr/lib/debug/.build-id/xx/yyy -> /usr/lib/.build-id/xx/yyy
@@ -114,7 +104,7 @@
#
# Use internal dependency generator rather than external helpers?
@@ -559,6 +578,7 @@ Supplements: (%{name} = %{version}-%{r
@@ -559,6 +575,7 @@ Supplements: (%{name} = %{version}-%{r
%__find_requires %{_rpmconfigdir}/find-requires
#%__find_conflicts ???
#%__find_obsoletes ???
@@ -122,7 +112,7 @@
#
# Path to file attribute classifications for automatic dependency
@@ -980,7 +1000,7 @@ Supplements: (%{name} = %{version}-%{r
@@ -980,7 +997,7 @@ Supplements: (%{name} = %{version}-%{r
%_build_vendor %{_host_vendor}
%_build_os %{_host_os}
%_host @host@
@@ -131,7 +121,7 @@
%_host_cpu @host_cpu@
%_host_vendor @host_vendor@
%_host_os @host_os@
@@ -1105,11 +1125,13 @@ Supplements: (%{name} = %{version}-%{r
@@ -1105,11 +1122,13 @@ Supplements: (%{name} = %{version}-%{r
#------------------------------------------------------------------------------
# arch macro for all supported 32-bit ARM processors

34
mtime_policy_set.diff Normal file
View File

@@ -0,0 +1,34 @@
--- build/files.c.orig 2025-02-12 13:27:08.131721537 +0000
+++ build/files.c 2025-02-12 13:32:28.371151422 +0000
@@ -1049,10 +1049,10 @@ static void genCpioListAndHeader(FileLis
}
}
- if (!strcmp(mtime_policy_str, "clamp_to_buildtime")) {
+ if (!strcmp(mtime_policy_str, "clamp_to_buildtime") || !strcmp(mtime_policy_str, "set_to_buildtime")) {
mtime_clamp = spec->buildTime;
- override_date = 1;
- } else if (!strcmp(mtime_policy_str, "clamp_to_source_date_epoch")) {
+ override_date = mtime_policy_str[0] == 's' ? 2 : 1;
+ } else if (!strcmp(mtime_policy_str, "clamp_to_source_date_epoch") || !strcmp(mtime_policy_str, "set_to_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/
@@ -1065,7 +1065,7 @@ static void genCpioListAndHeader(FileLis
rpmlog(RPMLOG_ERR, _("unable to parse %s=%s\n"), "SOURCE_DATE_EPOCH", srcdate);
fl->processingFailed = 1;
}
- override_date = 1;
+ override_date = mtime_policy_str[0] == 's' ? 2 : 1;
}
} else if (*mtime_policy_str) {
rpmlog(RPMLOG_WARNING,
@@ -1214,7 +1214,7 @@ static void genCpioListAndHeader(FileLis
}
}
- if (override_date && flp->fl_mtime > mtime_clamp) {
+ if (override_date && (flp->fl_mtime > mtime_clamp || override_date == 2)) {
flp->fl_mtime = mtime_clamp;
}
/*

View File

@@ -5,6 +5,12 @@ Wed Feb 12 13:36:45 CET 2025 - mls@suse.de
* move the rpmuncompress tool to rpm-build
* rewrite rpm2archive to not use libarchive for cpio/tar writing
* new patch: rpm2archive.diff
- revert buildroot macro setting that did more harm than good
- add set_to_buildtime and set_to_source_date_epoch mtime policy
support
* new patch: mtime_policy_set.diff
- drop unused 0001-Add-option-to-set-mtime-of-files-in-rpms.patch
patch
-------------------------------------------------------------------
Mon Feb 3 13:13:27 CET 2025 - mls@suse.de

View File

@@ -116,7 +116,6 @@ Patch135: selinux_transactional_update.patch
Patch136: rpmsort_reverse.diff
Patch138: canongnu.diff
Patch139: cmake_python_version.diff
Patch140: 0001-Add-option-to-set-mtime-of-files-in-rpms.patch
Patch141: 0002-log-build-time-if-it-is-set-from-SOURCE_DATE_EPOCH.patch
Patch142: 0003-Error-out-on-a-missing-changelog-date.patch
Patch150: unshare.diff
@@ -125,6 +124,7 @@ Patch152: debugpackage.diff
Patch153: nextfiles.diff
Patch154: undefbuildroot.diff
Patch155: rpm2archive.diff
Patch156: mtime_policy_set.diff
Patch6464: auto-config-update-aarch64-ppc64le.diff
BuildRoot: %{_tmppath}/%{name}-%{version}-build
#
@@ -242,11 +242,8 @@ rm -rf sqlite
%patch -P 122 -P 123
%patch -P 131 -P 133 -P 134 -P 135 -P 136 -P 138
%patch -P 139
%if 0
%patch -P 140
%endif
%patch -P 141 -P 142
%patch -P 150 -P 151 -P 152 -P 153 -P 154 -P 155
%patch -P 150 -P 151 -P 152 -P 153 -P 154 -P 155 -P 156
%ifarch aarch64 ppc64le riscv64 loongarch64
%patch -P 6464