[Buildroot] [PATCH 19/34] reproducibility/python: make python reproducible
Gilles Chanteperdrix
gilles.chanteperdrix at xenomai.org
Sat Apr 30 07:49:15 UTC 2016
python build is not reproducible for two reasons:
- the libpython library embeds the build timestamps, fix this by
overriding the __DATE__ and __TIME__ macro using SOURCE_DATE_EPOCH;
- _sysconfigdata.py and config/Makefile on target includes references
through INSTALL and MKDIR_P variables to host tools, fix this by
overriding these variables values with the corresponding paths on
buildroot rootfs.
---
package/python/python.mk | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/package/python/python.mk b/package/python/python.mk
index 5c5ebb8..dc064df 100644
--- a/package/python/python.mk
+++ b/package/python/python.mk
@@ -143,7 +143,9 @@ PYTHON_CONF_OPTS += \
--disable-tk \
--disable-nis \
--disable-dbm \
- --disable-pyo-build
+ --disable-pyo-build \
+ ac_cv_path_install=/usr/bin/install \
+ ac_cv_path_mkdir=/bin/mkdir
# This is needed to make sure the Python build process doesn't try to
# regenerate those files with the pgen program. Otherwise, it builds
@@ -214,6 +216,22 @@ endif
# Provided to other packages
PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/:$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages/
+ifeq ($(BR2_REPRODUCIBLE),y)
+PYTHON_SOURCE_DATE = `TZ=UTC LANG=C LC_ALL=C date -d @$(SOURCE_DATE_EPOCH) '+%b %_d %Y'`
+PYTHON_SOURCE_TIME = `TZ=UTC LANG=C LC_ALL=C date -d @$(SOURCE_DATE_EPOCH) '+%T'`
+
+PYTHON_CONF_OPTS += \
+ CFLAGS="$(TARGET_CFLAGS) -Wno-builtin-macro-redefined -include $(PYTHON_DIR)/.br_date_override.h"
+
+define PYTHON_OVERRIDE_DATE_HOOK
+ echo "#define buildroot_stringify(x) #x" > $(PYTHON_DIR)/.br_date_override.h
+ echo "#define __DATE__ buildroot_stringify($(PYTHON_SOURCE_DATE))" >> $(PYTHON_DIR)/.br_date_override.h
+ echo "#define __TIME__ buildroot_stringify($(PYTHON_SOURCE_TIME))" >> $(PYTHON_DIR)/.br_date_override.h
+endef
+
+PYTHON_POST_PATCH_HOOKS += PYTHON_OVERRIDE_DATE_HOOK
+endif
+
$(eval $(autotools-package))
$(eval $(host-autotools-package))
--
2.7.4
More information about the buildroot
mailing list