Subject: [bug#48205] [PATCH v2] gnu: emacs-org: Make build reproducible

From: [email-masked]
Date: Wed, 9 Jun 2021 11:32:02 -0400

From: Morgan Smith <[email-masked]>

* gnu/packages/emacs-xyz.scm (emacs-org)[phases]: Remove loaddefs and use
autoloads instead. Copy autoloads into build directory.
---

Thanks for the suggestions! Sorry about the delay. Also sorry about the
comment. It's probably a little too long :/. I need to work on my english and
my ability to be concise.

 gnu/packages/emacs-xyz.scm | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 1d954ec5bd..180b2709fe 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -11761,6 +11761,27 @@ (define-public emacs-org
     (arguments
      `(#:phases
        (modify-phases %standard-phases
+         ;; Org ships with the file org-loaddefs.el that functions like our
+         ;; autoloads. Something about the interaction between the loaddefs
+         ;; and autoloads makes the build non-deterministic. We should opt for
+         ;; our autoloads system over the loaddefs since the loaddefs are
+         ;; autogenerated for the release tarball. org-loaddefs.el is
+         ;; mentioned by name in the source files so we have to do a blanket
+         ;; regex search and replace.
+         (add-after 'unpack 'use-autoloads
+           (lambda _
+             (delete-file "org-loaddefs.el")
+             (substitute* (find-files "." "\\.el$")
+               (("org-loaddefs.el") "org-autoloads.el"))))
+         ;; We create the autoloads directly in the install folder. During
+         ;; compilation org checks for the autoloads file so we need to copy
+         ;; it to the build directory.
+         (add-after 'make-autoloads 'copy-autoload-to-build-dir
+           (lambda* (#:key outputs #:allow-other-keys)
+             (copy-file (string-append
+                         (elpa-directory (assoc-ref outputs "out"))
+                         "/org-autoloads.el")
+                        "org-autoloads.el")))
          (add-after 'install 'install-documentation
            (lambda* (#:key outputs #:allow-other-keys)
              (let* ((share (string-append (assoc-ref outputs "out") "/share"))
-- 
2.32.0