From 17c0eb0499196600ceb516ad67b010c281e1b188 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer
Date: Fri, 6 Dec 2019 15:12:32 +0900 Subject: [PATCH 2/7] emacs-build-system: Byte compile the autoload files. * guix/build/emacs-build-system.scm (enable-autoloads-compilation) (validate-compiled-autoloads): Add procedures. (%standard-phases): Register the new procedures. * gnu/packages/aux-files/emacs/guix-emacs.el (guix-emacs-find-autoloads): Remove duplicates in the list of autoload files found. * guix/build/emacs-utils.scm (expr->string): Add procedure. (emacs-batch-eval, emacs-batch-edit-file): Use it. --- gnu/packages/aux-files/emacs/guix-emacs.el | 5 +++-- guix/build/emacs-build-system.scm | 22 ++++++++++++++++++++-- guix/build/emacs-utils.scm | 10 ++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el index 05fc9709b6..25a87ee52d 100644 --- a/gnu/packages/aux-files/emacs/guix-emacs.el +++ b/gnu/packages/aux-files/emacs/guix-emacs.el @@ -35,8 +35,9 @@ "Return a list of Emacs 'autoloads' files in DIRECTORY. The files in the list do not have extensions (.el, .elc)." ;; `directory-files' doesn't honor group in regexp. - (mapcar #'file-name-sans-extension - (directory-files directory 'full-name guix-emacs-autoloads-regexp))) + (delete-dups (mapcar #'file-name-sans-extension + (directory-files directory 'full-name + guix-emacs-autoloads-regexp)))) ;;;###autoload (defun guix-emacs-autoload-packages () diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm index 09de244993..219310cf08 100644 --- a/guix/build/emacs-build-system.scm +++ b/guix/build/emacs-build-system.scm @@ -225,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)) @@ -253,10 +268,13 @@ second hyphen. This corresponds to 'name-version' as used in ELPA packages." (replace 'check check) (replace 'install install) (add-after 'install 'make-autoloads make-autoloads) - (add-after 'make-autoloads 'patch-el-files patch-el-files) + (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 'move-doc move-doc))) + (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) diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index 885fd0a217..ab64e3714c 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -41,16 +41,22 @@ ;; The `emacs' command. (make-parameter "emacs")) +(define (expr->string expr) + "Converts EXPR, an expression, into a string." + (if (string? expr) + expr + (format #f "~s" expr))) + (define (emacs-batch-eval expr) "Run Emacs in batch mode, and execute the elisp code EXPR." (invoke (%emacs) "--quick" "--batch" - (format #f "--eval=~S" expr))) + (string-append "--eval=" (expr->string expr)))) (define (emacs-batch-edit-file file expr) "Load FILE in Emacs using batch mode, and execute the elisp code EXPR." (invoke (%emacs) "--quick" "--batch" (string-append "--visit=" file) - (format #f "--eval=~S" expr))) + (string-append "--eval=" (expr->string expr)))) (define (emacs-batch-disable-compilation file) (emacs-batch-edit-file file -- 2.25.0