From 136c0ed8859ef92321c5b784dffd19d5c1df420b Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: May 12 2024 23:23:30 +0000 Subject: man page generator: use $SOURCE_DATE_EPOCH if specified When doing package builds, centpkg builds the man page using pyrpkg.man_gen.generate(), and since the man page embeds the build timestamp in the footer, the result is irreproducible. Use $SOURCE_DATE_EPOCH [1], if set, to clamp the timestamp. If SOURCE_DATE_EPOCH is set, but not a valid integer, this will raise an error. I think this is appropriate, since this would most likely be a result of some strange operator error. Checked with: $ PYTHONPATH=.:centpkg-0.8.2/src python centpkg-0.8.2/doc/centpkg_man_page.py $ SOURCE_DATE_EPOCH=3001111 PYTHONPATH=.:centpkg-0.8.2/src python centpkg-0.8.2/doc/centpkg_man_page.py The only difference is the date in the footer. [1] https://reproducible-builds.org/docs/source-date-epoch/ Signed-off-by: Zbigniew Jędrzejewski-Szmek --- diff --git a/pyrpkg/man_gen.py b/pyrpkg/man_gen.py index b73dded..b739e42 100644 --- a/pyrpkg/man_gen.py +++ b/pyrpkg/man_gen.py @@ -65,8 +65,16 @@ class ManFormatter(object): @property def constants(self): """Global constants for man file templates""" - today = datetime.date.today() + + source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH') + if source_date_epoch: + today = datetime.datetime.fromtimestamp(int(source_date_epoch), + tz=datetime.timezone.utc) + else: + today = datetime.date.today() + today_manstr = today.strftime(r'%Y\-%m\-%d') + return {'today': today_manstr, 'identity': self.identity, 'sourceurl': self.sourceurl}