diff mbox series

[bug#68394,python-team] gnu: python: Make the build reproducible.

Message ID f0dcb5eadb333cf840f515ddda025734d924c25a.1705019596.git.~@wolfsden.cz
State New
Headers show
Series [bug#68394,python-team] gnu: python: Make the build reproducible. | expand

Commit Message

Tomas Volf Jan. 12, 2024, 12:33 a.m. UTC
While python build was reproducible on a single machine, once multiple
file systems entered the picture, it was no longer true.  My local builds on
BTRFS differed from build on ext4 done in a virtual machine.

The distutils library present in current python is sensitive to file system
ordering.  The solution is the same opensuse used, sorting the list of files.

With this patch, build on my machine (BTRFS) and in a guix system vm (ext4)
produce the same store item.

More info: https://bugzilla.opensuse.org/show_bug.cgi?id=1049186

* gnu/packages/python.scm (python-3.10)[arguments]<#:phases>: Add
'patch-distutils phase.

Change-Id: I0273dc0f8511a7acdcc2b462a26cc29a9756c801
---
 gnu/packages/python.scm | 13 +++++++++++++
 1 file changed, 13 insertions(+)


base-commit: 5c0f77f4241c9beac0c82deae946bfdc70b49ff0

Comments

Lars-Dominik Braun Jan. 12, 2024, 7:39 a.m. UTC | #1
Hi,

> +                 (substitute* file
> +                   (("^        for file in py_files:\n$")
> +                    "        for file in sorted(py_files):\n"))

as far as I understand this change was rejected from upstream Python,
see https://github.com/python/cpython/pull/8057, and instead this is
the accepted (and merged) solution:
https://github.com/python/cpython/pull/8226
That patch is also used by Debian.

Cheers,
Lars
diff mbox series

Patch

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 51d5f598d7..319a917b4b 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -515,6 +515,19 @@  (define-public python-3.10
                        (substitute* "Makefile.pre.in"
                          (("-j0") "-j1")))))
                  '())
+           (add-after 'unpack 'patch-distutils
+             (lambda _
+               ;; Ensure byte_compile produces the same output regardless
+               ;; filesystem ordering.  For more information see:
+               ;; https://bugzilla.opensuse.org/show_bug.cgi?id=1049186
+               (let* ((file "Lib/distutils/util.py")
+                      (old-content (call-with-input-file file get-string-all)))
+                 (substitute* file
+                   (("^        for file in py_files:\n$")
+                    "        for file in sorted(py_files):\n"))
+                 (if (string=? old-content
+                               (call-with-input-file file get-string-all))
+                     (error "substitute did nothing, phase requires an update")))))
            (add-after 'unpack 'remove-windows-binaries
              (lambda _
                ;; Delete .exe from embedded .whl (zip) files