Subject: [PATCH v3] gnu: emacs: Make strip-double-wrap more robust.

From: [email-masked]
Date: Wed, 4 Nov 2020 14:47:13 -0500

From: Morgan Smith <[email-masked]>

* gnu/packages/emacs.scm (emacs) [strip-double-wrap]: Use regex to find emacs
executable.  This works even when the version is changed by package
transformations (e.g., version=git.master).
---

(Can you reopen this bug report please?)

So I see 3 possible solutions:
1. Accept my first patch and give up on match
2. Accept this patch and modify almost every emacs varient (I did test building them all)
3. Figure out some proper module inheritence

I think option 3 is the most correct, but I'm lazy so I'm leaning towards option 1.
---
 gnu/packages/emacs.scm | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 4963379d74..4d1080f9dd 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -123,6 +123,9 @@
     (build-system glib-or-gtk-build-system)
     (arguments
      `(#:tests? #f                      ; no check target
+       #:modules ((guix build glib-or-gtk-build-system)
+                  (guix build utils)
+                  (ice-9 match))
        #:configure-flags (list "--with-modules"
                                "--with-cairo"
                                "--disable-build-details")
@@ -196,17 +199,12 @@
            (lambda* (#:key outputs #:allow-other-keys)
              ;; Directly copy emacs-X.Y to emacs, so that it is not wrapped
              ;; twice.  This also fixes a minor issue, where WMs would not be
-             ;; able to track emacs back to emacs.desktop.  The version is
-             ;; accessed using using THIS-PACKAGE so it "just works" for
-             ;; inherited Emacs packages of different versions.
+             ;; able to track emacs back to emacs.desktop.
              (with-directory-excursion (assoc-ref outputs "out")
-               (copy-file (string-append
-                           "bin/emacs-"
-                           ,(let ((this-version (package-version this-package)))
-                              (or (false-if-exception
-                                   (version-major+minor+point this-version))
-                                  (version-major+minor this-version))))
-                          "bin/emacs")
+               (copy-file
+                (match (find-files "bin" "^emacs-")
+                  ((executable . _) executable))
+                "bin/emacs")
                #t)))
          (add-before 'reset-gzip-timestamps 'make-compressed-files-writable
            ;; The 'reset-gzip-timestamps phase will throw a permission error
@@ -328,7 +326,11 @@ languages.")
        ((#:phases phases)
         `(modify-phases ,phases
            (delete 'restore-emacs-pdmp)
-           (delete 'strip-double-wrap)))))
+           (delete 'strip-double-wrap)))
+       ((#:modules modules)
+        `((guix build gnu-build-system)
+          (guix build utils)
+          (ice-9 match)))))
     (inputs
      `(("guix-emacs.el" ,(search-auxiliary-file "emacs/guix-emacs.el"))
        ("ncurses" ,ncurses)))
@@ -348,7 +350,11 @@ editor (with xwidgets support)")
        ((#:phases phases)
         `(modify-phases ,phases
            (delete 'restore-emacs-pdmp)
-           (delete 'strip-double-wrap)))))
+           (delete 'strip-double-wrap)))
+       ((#:modules modules)
+        `((guix build gnu-build-system)
+          (guix build utils)
+          (ice-9 match)))))
     (inputs
      `(("webkitgtk" ,webkitgtk)
        ("libxcomposite" ,libxcomposite)
@@ -375,7 +381,11 @@ editor (console only)")
        ((#:phases phases)
         `(modify-phases ,phases
            (delete 'restore-emacs-pdmp)
-           (delete 'strip-double-wrap)))))))
+           (delete 'strip-double-wrap)))
+       ((#:modules modules)
+        `((guix build gnu-build-system)
+          (guix build utils)
+          (ice-9 match)))))))
 
 (define-public emacs-no-x-toolkit
   (package/inherit emacs
@@ -392,7 +402,11 @@ editor (without an X toolkit)" )
        ((#:phases phases)
         `(modify-phases ,phases
            (delete 'restore-emacs-pdmp)
-           (delete 'strip-double-wrap)))))))
+           (delete 'strip-double-wrap)))
+       ((#:modules modules)
+        `((guix build gnu-build-system)
+          (guix build utils)
+          (ice-9 match)))))))
 
 (define-public emacs-wide-int
   (package/inherit emacs
-- 
2.29.1