churchyard / rpms / python3

Forked from rpms/python3 3 years ago
Clone

Blame 00328-pyc-timestamp-invalidation-mode.patch

a262879
From 95f28a4e0417c5749ac228b1d443ec49ccc72e5b Mon Sep 17 00:00:00 2001
9213c03
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
9213c03
Date: Thu, 11 Jul 2019 13:44:13 +0200
9213c03
Subject: [PATCH] 00328: Restore pyc to TIMESTAMP invalidation mode as default
9213c03
 in rpmbuild
9213c03
9213c03
Since Fedora 31, the $SOURCE_DATE_EPOCH is set in rpmbuild to the latest
9213c03
%changelog date. This makes Python default to the CHECKED_HASH pyc
9213c03
invalidation mode, bringing more reproducible builds traded for an import
9213c03
performance decrease. To avoid that, we don't default to CHECKED_HASH
9213c03
when $RPM_BUILD_ROOT is set (i.e. when we are building RPM packages).
9213c03
9213c03
See https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/57#comment-27426
9213c03
---
9213c03
 Lib/py_compile.py           | 3 ++-
9213c03
 Lib/test/test_py_compile.py | 2 ++
9213c03
 2 files changed, 4 insertions(+), 1 deletion(-)
9213c03
9213c03
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
9213c03
index 21736896af..310bed5620 100644
9213c03
--- a/Lib/py_compile.py
9213c03
+++ b/Lib/py_compile.py
9213c03
@@ -70,7 +70,8 @@ class PycInvalidationMode(enum.Enum):
9213c03
 
9213c03
 
9213c03
 def _get_default_invalidation_mode():
9213c03
-    if os.environ.get('SOURCE_DATE_EPOCH'):
9213c03
+    if (os.environ.get('SOURCE_DATE_EPOCH') and not
9213c03
+            os.environ.get('RPM_BUILD_ROOT')):
9213c03
         return PycInvalidationMode.CHECKED_HASH
9213c03
     else:
9213c03
         return PycInvalidationMode.TIMESTAMP
9213c03
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
a262879
index d4a68c9320..ed09874023 100644
9213c03
--- a/Lib/test/test_py_compile.py
9213c03
+++ b/Lib/test/test_py_compile.py
9213c03
@@ -17,6 +17,7 @@ def without_source_date_epoch(fxn):
9213c03
     def wrapper(*args, **kwargs):
9213c03
         with support.EnvironmentVarGuard() as env:
9213c03
             env.unset('SOURCE_DATE_EPOCH')
9213c03
+            env.unset('RPM_BUILD_ROOT')
9213c03
             return fxn(*args, **kwargs)
9213c03
     return wrapper
9213c03
 
9213c03
@@ -27,6 +28,7 @@ def with_source_date_epoch(fxn):
9213c03
     def wrapper(*args, **kwargs):
9213c03
         with support.EnvironmentVarGuard() as env:
9213c03
             env['SOURCE_DATE_EPOCH'] = '123456789'
9213c03
+            env.unset('RPM_BUILD_ROOT')
9213c03
             return fxn(*args, **kwargs)
9213c03
     return wrapper
9213c03
 
9213c03
-- 
a262879
2.24.1
9213c03