From 22c5672f9e02f6947bbfd4041636ddbd271d1df5 Mon Sep 17 00:00:00 2001 From: mhagger Date: Sat, 30 Jul 2016 10:47:02 +0000 Subject: [PATCH] If SOURCE_DATE_EPOCH is set, use it for manpages To improve build reproducibility, use the value of the environment variable SOURCE_DATE_EPOCH as the date to embed in manpages if it is set, rather than unconditionally using the current date. The idea is that packaging systems can feed in the date of the last source modification, so that the result is the same no matter when the package is built. See the SOURCE_DATE_EPOCH specification [1] for more information. This was reported as Debian bug #831066 [2]. [1] https://reproducible-builds.org/specs/source-date-epoch/ [2] https://bugs.debian.org/831066 Suggested-by: Chris Lamb git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5465 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/man_writer.py | 2 +- cvs2svn_lib/run_options.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cvs2svn_lib/man_writer.py b/cvs2svn_lib/man_writer.py index d1ca7bd0..b5f3a4d8 100644 --- a/cvs2svn_lib/man_writer.py +++ b/cvs2svn_lib/man_writer.py @@ -93,7 +93,7 @@ class ManWriter(object): '.TH %s "%s" "%s" "%s" "%s"\n' % ( self.parser.get_prog_name().upper(), self.section, - self.date.strftime('%b %d, %Y'), + self.date.strftime('%Y-%m-%d'), self.source, self.manual, ) diff --git a/cvs2svn_lib/run_options.py b/cvs2svn_lib/run_options.py index e0425504..2721d232 100644 --- a/cvs2svn_lib/run_options.py +++ b/cvs2svn_lib/run_options.py @@ -16,6 +16,7 @@ """This module contains classes to set common cvs2xxx run options.""" +import os import sys import re import optparse @@ -883,11 +884,23 @@ class RunOptions(object): self.pass_manager.help_passes() sys.exit(0) + def _choose_build_date(self): + """Choose the data to embed in the man pages. + + If environment variable SOURCE_DATE_EPOCH is set, use that. + Otherwise, use the current time.""" + + t = os.environ.get('SOURCE_DATE_EPOCH') + if t: + return datetime.datetime.utcfromtimestamp(int(t)).date() + else: + return datetime.date.today() + def callback_manpage(self, option, opt_str, value, parser): f = codecs.getwriter('utf_8')(sys.stdout) writer = ManWriter(parser, section='1', - date=datetime.date.today(), + date=self._choose_build_date(), source='Version %s' % (VERSION,), manual='User Commands', short_desc=self.short_desc, -- 2.11.4.GIT