File reproducible-jar.patch of Package meson
commit 76a001e7f4f307760ccc11cd9af062fda71bd130
Author: Bernhard M. Wiedemann <bwiedemann@suse.de>
Date: Fri Feb 6 10:53:14 2026 +0100
Allow to use deterministic mtime in jar
when updating a .jar file, we use the SOURCE_DATE_EPOCH variable
to determine the mtime value of the manifest file.
This branch will fail if an incompatible jar version (e.g. openjdk < 17)
is used. This is probably preferrable to silently generating
non-deterministic build results. And it keeps the code simpler
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py
index 8adc35c4a..5ec49c820 100644
--- a/mesonbuild/scripts/depfixer.py
+++ b/mesonbuild/scripts/depfixer.py
@@ -4,6 +4,7 @@
from __future__ import annotations
+import datetime
import sys
import os
import stat
@@ -532,7 +533,19 @@ def fix_jar(fname: str) -> None:
# special-casing for the manifest file, so we can re-add it as a normal
# archive member. This puts the manifest at the end of the jar rather
# than the beginning, but the spec doesn't forbid that.
- subprocess.check_call(['jar', 'ufM', fname, 'META-INF/MANIFEST.MF'])
+ source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
+ if source_date_epoch:
+ # We want to adjust mtime for deterministic .jar file results:
+ source_date_epoch = int(source_date_epoch)
+ if source_date_epoch < 315529202:
+ source_date_epoch = 31552920 # zip cannot represent earlier timestamps
+ formatted_date = datetime.datetime.fromtimestamp(source_date_epoch, datetime.timezone.utc).isoformat()
+ cmd = ['jar', f'--date={formatted_date}', '-u', '-M', '-f']
+ else:
+ cmd = ['jar', 'ufM']
+
+ cmd.extend([fname, 'META-INF/MANIFEST.MF'])
+ subprocess.check_call(cmd)
def fix_rpath(fname: str, rpath_dirs_to_remove: T.Set[bytes], new_rpath: T.Union[str, bytes], final_path: str, install_name_mappings: T.Dict[str, str], verbose: bool = True) -> None:
global INSTALL_NAME_TOOL # pylint: disable=global-statement