[Buildroot] [git commit] python2: generate reproducible .pyc

Thomas Petazzoni thomas.petazzoni at free-electrons.com
Mon Mar 20 22:03:15 UTC 2017


commit: https://git.buildroot.net/buildroot/commit/?id=edbe7e815ec55117ed58a70d8a8f7f5d9848b5eb
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master

.pyc files contain the modification time of the corresponding .py
source. In order to make the build reproducible, we fix the modification
time of all .py before compiling .pyc files.

In addition, since pycompile relies on the modification time to know if
a file needs to be recompiled, it is safer to force recompilation of all
source files.

This work was sponsored by `BA Robotic Systems'.

Signed-off-by: Jérôme Pouiller <jezz at sysmic.org>
Reviewed-by: Samuel Martin <s.martin49 at gmail.com>
[Thomas: do not register PYTHON_FIX_TIME as a
 PYTHON_TARGET_FINALIZE_HOOKS, instead call it inside
 PYTHON_CREATE_PYC_FILES before doing the byte compilation.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at free-elecrons.com>
---
 package/python/python.mk | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/package/python/python.mk b/package/python/python.mk
index 8f4e298..1787576 100644
--- a/package/python/python.mk
+++ b/package/python/python.mk
@@ -244,10 +244,18 @@ PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+define PYTHON_FIX_TIME
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | \
+		xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH)
+endef
+endif
+
 define PYTHON_CREATE_PYC_FILES
+	$(PYTHON_FIX_TIME)
 	PYTHONPATH="$(PYTHON_PATH)" \
 	$(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) \
-		support/scripts/pycompile.py \
+		support/scripts/pycompile.py $(if $(BR2_REPRODUCIBLE),--force) \
 		$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)
 endef
 


More information about the buildroot mailing list