gnu: r-qtl2: Move to (gnu packages cran).
[jackhill/guix/guix.git] / guix / build / emacs-build-system.scm
index e2b792d..26ea59b 100644 (file)
@@ -21,7 +21,7 @@
 
 (define-module (guix build emacs-build-system)
   #:use-module ((guix build gnu-build-system) #:prefix gnu:)
-  #:use-module (guix build utils)
+  #:use-module ((guix build utils) #:hide (delete))
   #:use-module (guix build emacs-utils)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
@@ -76,10 +76,20 @@ archive, a directory, or an Emacs Lisp file."
 (define* (add-source-to-load-path #:key dummy #:allow-other-keys)
   "Augment the EMACSLOADPATH environment variable with the source directory."
   (let* ((source-directory (getcwd))
-         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
-                                               source-directory)))
+         (emacs-load-path (string-split (getenv "EMACSLOADPATH") #\:))
+         ;; XXX: Make sure the Emacs core libraries appear at the end of
+         ;; EMACSLOADPATH, to avoid shadowing any other libraries depended
+         ;; upon.
+         (emacs-load-path-non-core (filter (cut string-contains <>
+                                                "/share/emacs/site-lisp")
+                                           emacs-load-path))
+         (emacs-load-path-value (string-append
+                                 (string-join (cons source-directory
+                                                    emacs-load-path-non-core)
+                                              ":")
+                                 ":")))
     (setenv "EMACSLOADPATH" emacs-load-path-value)
-    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
+    (format #t "source directory ~s prepended to the `EMACSLOADPATH' \
 environment variable\n" source-directory)))
 
 (define* (build #:key outputs inputs #:allow-other-keys)
@@ -215,6 +225,21 @@ parallel. PARALLEL-TESTS? is ignored when using a non-make TEST-COMMAND."
     (parameterize ((%emacs emacs))
       (emacs-generate-autoloads elpa-name site-lisp))))
 
+(define* (enable-autoloads-compilation #:key outputs #:allow-other-keys)
+  "Remove the NO-BYTE-COMPILATION local variable embedded in the generated
+autoload files."
+  (let* ((out (assoc-ref outputs "out"))
+         (autoloads (find-files out "-autoloads.el$")))
+    (substitute* autoloads
+      ((";; no-byte-compile.*") ""))
+    #t))
+
+(define* (validate-compiled-autoloads #:key outputs #:allow-other-keys)
+  "Verify whether the byte compiled autoloads load fine."
+  (let* ((out (assoc-ref outputs "out"))
+         (autoloads (find-files out "-autoloads.elc$")))
+    (emacs-batch-eval (format #f "(mapc #'load '~s)" autoloads))))
+
 (define (emacs-package? name)
   "Check if NAME correspond to the name of an Emacs package."
   (string-prefix? "emacs-" name))
@@ -239,15 +264,17 @@ second hyphen.  This corresponds to 'name-version' as used in ELPA packages."
     (add-after 'unpack 'add-source-to-load-path add-source-to-load-path)
     (delete 'bootstrap)
     (delete 'configure)
-    ;; Move the build phase after install: the .el files are byte compiled
-    ;; directly in the store.
     (delete 'build)
     (replace 'check check)
     (replace 'install install)
-    (add-after 'install 'build build)
     (add-after 'install 'make-autoloads make-autoloads)
-    (add-after 'make-autoloads 'patch-el-files patch-el-files)
-    (add-after 'make-autoloads 'move-doc move-doc)))
+    (add-after 'make-autoloads 'enable-autoloads-compilation
+      enable-autoloads-compilation)
+    (add-after 'enable-autoloads-compilation 'patch-el-files patch-el-files)
+    ;; The .el files are byte compiled directly in the store.
+    (add-after 'patch-el-files 'build build)
+    (add-after 'build 'validate-compiled-autoloads validate-compiled-autoloads)
+    (add-after 'validate-compiled-autoloads 'move-doc move-doc)))
 
 (define* (emacs-build #:key inputs (phases %standard-phases)
                       #:allow-other-keys #:rest args)