diff mbox

[v4,14/18] python3: generate reproducible .pyc

Message ID 1479905937-17241-15-git-send-email-jezz@sysmic.org
State Superseded
Headers show

Commit Message

Jérôme Pouiller Nov. 23, 2016, 12:58 p.m. UTC
.pyc files contain modification time of .py source. In order to make
build reproducible, we fix modification time of all .py before to
compile .pyc files.

This work was sponsored by `BA Robotic Systems'.

Signed-off-by: Jérôme Pouiller <jezz@sysmic.org>
---

Notes:
    v3:
      - Force compilation instead of removing .pyc

 package/python3/python3.mk | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Thomas Petazzoni Nov. 23, 2016, 10:09 p.m. UTC | #1
Hello,

On Wed, 23 Nov 2016 13:58:53 +0100, Jérôme Pouiller wrote:
> .pyc files contain modification time of .py source. In order to make
> build reproducible, we fix modification time of all .py before to
> compile .pyc files.

Is there a way of avoiding the modification time contained inside
the .pyc files? According to
http://wiki.baserock.org/projects/deterministic-builds/: "Debian solve
this by creating the .pyc and .pyo files at package install time",
which is essentially what we do. How do they handle this exactly?

Thanks,

Thomas
Jérôme Pouiller Nov. 26, 2016, 4:20 p.m. UTC | #2
Hello Thomas,

On Wednesday 23 November 2016 23:09:39 Thomas Petazzoni wrote:
> Hello,
> 
> On Wed, 23 Nov 2016 13:58:53 +0100, Jérôme Pouiller wrote:
> > .pyc files contain modification time of .py source. In order to make
> > build reproducible, we fix modification time of all .py before to
> > compile .pyc files.
> 
> Is there a way of avoiding the modification time contained inside
> the .pyc files? According to
> http://wiki.baserock.org/projects/deterministic-builds/: "Debian solve
> this by creating the .pyc and .pyo files at package install time",
> which is essentially what we do. How do they handle this exactly?
Debian compile .pyc and .pyo when user install package. deb files does 
not contains compiled files. Therefore, .pyc reproducibility does not 
matter.

In Buildroot, .pyc are included in filesystem. .pyc reproducibility does 
matter.
diff mbox

Patch

diff --git a/package/python3/python3.mk b/package/python3/python3.mk
index b3f31c0..a526c0f 100644
--- a/package/python3/python3.mk
+++ b/package/python3/python3.mk
@@ -219,10 +219,18 @@  PYTHON3_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/sysconfigdat
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+define PYTHON3_FIX_TIME
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
+		xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH)
+endef
+PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_FIX_TIME
+endif
+
 define PYTHON3_CREATE_PYC_FILES
 	PYTHONPATH="$(PYTHON3_PATH)" \
 	$(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
-		support/scripts/pycompile.py \
+		support/scripts/pycompile.py $(if $(BR2_REPRODUCIBLE),--force) \
 		$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
 endef