[Rpm-maint] [PATCH v2 2/2] set mtime of all .py files to date of last Changelog

bmorbach at redhat.com bmorbach at redhat.com
Wed Aug 13 13:08:36 UTC 2014

From: Benedikt Morbach <bmorbach at redhat.com>

This ensures that rebuilds of an srpm result in the same .py{c,o} files,
even if the source files were modified during the build.
This should make the builds of most python packages reproducible.

The downside here is that we don't preserve the mtime of the sources
anymore. However, as of right now a user can't tell by looking at a file
on disk if it has the original source mtime or was modified during build,
which makes having the mtime near useless anyway, in my opinion.
 scripts/brp-python-bytecompile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/brp-python-bytecompile b/scripts/brp-python-bytecompile
index 39fca60..d26ec38 100644
--- a/scripts/brp-python-bytecompile
+++ b/scripts/brp-python-bytecompile
@@ -14,7 +14,9 @@ fi
 # Figure out how deep we need to descend.  We could pick an insanely high
 # number and hope it's enough, but somewhere, somebody's sure to run into it.
-depth=`(find "$RPM_BUILD_ROOT" -type f -name "*.py" -print0 ; echo /) | \
+# Also touch all .py files to the date of the last rpm Changelog entry to
+# ensure that the resulting .pyc and .pyo files are always the same
+depth=`(find "$RPM_BUILD_ROOT" -type f -name "*.py" -exec touch -d @"$RPM_CHANGELOG_DATE" {} \+ -print0 ; echo /) | \
        xargs -0 -n 1 dirname | sed 's,[^/],,g' | sort -u | tail -n 1 | wc -c`
 if [ -z "$depth" -o "$depth" -le "1" ]; then
 	exit 0

More information about the Rpm-maint mailing list