From 0eae1d90da13934959153a0c291712ed369e2229 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 23 Jul 2020 12:23:49 +0200 Subject: [PATCH] Disable Python hash seed randomization in %py_byte_compile This change should help with byte-compilation reproducibility: https://bugzilla.redhat.com/show_bug.cgi?id=1686078 --- macros.pybytecompile | 9 ++++++--- python-rpm-macros.spec | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/macros.pybytecompile b/macros.pybytecompile index f34716b..7bd555b 100644 --- a/macros.pybytecompile +++ b/macros.pybytecompile @@ -12,9 +12,12 @@ # use it in a subshell like this: # (%{py_byte_compile }) || : +# Setting PYTHONHASHSEED=0 disables Python hash seed randomization +# This should help with byte-compilation reproducibility: https://bugzilla.redhat.com/show_bug.cgi?id=1686078 + %py_byte_compile()\ py2_byte_compile () {\ - python_binary="%1"\ + python_binary="env PYTHONHASHSEED=0 %1"\ bytecode_compilation_path="%2"\ failure=0\ find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -s -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("'"$RPM_BUILD_ROOT"'")[2], doraise=True) for f in sys.argv[1:]]' || failure=1\ @@ -23,13 +26,13 @@ py2_byte_compile () {\ }\ \ py3_byte_compile () {\ - python_binary="%1"\ + python_binary="env PYTHONHASHSEED=0 %1"\ bytecode_compilation_path="%2"\ PYTHONPATH="%{_rpmconfigdir}/redhat" $python_binary -s -B -m compileall2 -o 0 -o 1 -s $RPM_BUILD_ROOT -p / $bytecode_compilation_path \ }\ \ py39_byte_compile () {\ - python_binary="%1"\ + python_binary="env PYTHONHASHSEED=0 %1"\ bytecode_compilation_path="%2"\ $python_binary -s -B -m compileall -o 0 -o 1 -s $RPM_BUILD_ROOT -p / $bytecode_compilation_path \ }\ diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index be4c08d..8128055 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -1,6 +1,6 @@ Name: python-rpm-macros Version: 3.9 -Release: 7%{?dist} +Release: 8%{?dist} Summary: The common Python RPM macros # macros and lua: MIT, compileall2.py: PSFv2 @@ -107,6 +107,9 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Fri Jul 24 2020 Lumír Balhar - 3.9-8 +- Disable Python hash seed randomization in %%py_byte_compile + * Tue Jul 21 2020 Lumír Balhar - 3.9-7 - Make %%py3_dist respect %%python3_pkgversion