build-system: emacs: Use subdirectories again.

With this, Emacs libraries are installed in the ELPA_NAME-VERSION subdirectory
of site-lisp and potential subdirectories should no longer collide.

* guix/build/emacs-build-system.scm (add-source-to-load-path): Rename to...
(expand-load-path): ... this.  Also expand lone subdirectories of site-lisp.
(%standard-phases): Adjust accordingly.
(elpa-directory): New variable.  Export it publicly for use in other build
systems.
(build, patch-el-files, make-autoloads): Use ELPA name and version to
construct subdirectories of %install-dir.
(install): Install in subdirectory.
This commit is contained in:
Leo Prikler 2021-04-17 19:06:19 +02:00
parent d13b46fae4
commit 79cfe30f3e
No known key found for this signature in database
GPG key ID: 442A84B8C70E2F87

View file

@ -26,13 +26,16 @@ (define-module (guix build emacs-build-system)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-11) #:use-module (srfi srfi-11)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (ice-9 format)
#:use-module (ice-9 ftw)
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:use-module (ice-9 regex) #:use-module (ice-9 regex)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:export (%standard-phases #:export (%standard-phases
%default-include %default-include
%default-exclude %default-exclude
emacs-build)) emacs-build
elpa-directory))
;; Commentary: ;; Commentary:
;; ;;
@ -73,33 +76,43 @@ (define* (unpack #:key source #:allow-other-keys)
#t) #t)
(gnu:unpack #:source source))) (gnu:unpack #:source source)))
(define* (add-source-to-load-path #:key dummy #:allow-other-keys) (define* (expand-load-path #:key (prepend-source? #t) #:allow-other-keys)
"Augment the EMACSLOADPATH environment variable with the source directory." "Expand EMACSLOADPATH, so that inputs, whose code resides in subdirectories,
are properly found.
If @var{prepend-source?} is @code{#t} (the default), also add the current
directory to EMACSLOADPATH in front of any other directories."
(let* ((source-directory (getcwd)) (let* ((source-directory (getcwd))
(emacs-load-path (string-split (getenv "EMACSLOADPATH") #\:)) (emacs-load-path (string-split (getenv "EMACSLOADPATH") #\:))
;; XXX: Make sure the Emacs core libraries appear at the end of (emacs-load-path*
;; EMACSLOADPATH, to avoid shadowing any other libraries depended (map
;; upon. (lambda (dir)
(emacs-load-path-non-core (filter (cut string-contains <> (match (scandir dir (negate (cute member <> '("." ".."))))
"/share/emacs/site-lisp") ((sub) (string-append dir "/" sub))
emacs-load-path)) (_ dir)))
emacs-load-path))
(emacs-load-path-value (string-append (emacs-load-path-value (string-append
(string-join (cons source-directory (string-join
emacs-load-path-non-core) (if prepend-source?
":") (cons source-directory emacs-load-path*)
emacs-load-path*)
":")
":"))) ":")))
(setenv "EMACSLOADPATH" emacs-load-path-value) (setenv "EMACSLOADPATH" emacs-load-path-value)
(format #t "source directory ~s prepended to the `EMACSLOADPATH' \ (when prepend-source?
environment variable\n" source-directory))) (format #t "source directory ~s prepended to the `EMACSLOADPATH' \
environment variable\n" source-directory))
(let ((diff (lset-difference string=? emacs-load-path* emacs-load-path)))
(unless (null? diff)
(format #t "expanded load paths for ~{~a~^, ~}\n"
(map basename diff))))))
(define* (build #:key outputs inputs #:allow-other-keys) (define* (build #:key outputs inputs #:allow-other-keys)
"Compile .el files." "Compile .el files."
(let* ((emacs (string-append (assoc-ref inputs "emacs") "/bin/emacs")) (let* ((emacs (string-append (assoc-ref inputs "emacs") "/bin/emacs"))
(out (assoc-ref outputs "out")) (out (assoc-ref outputs "out")))
(site-lisp (string-append out %install-dir)))
(setenv "SHELL" "sh") (setenv "SHELL" "sh")
(parameterize ((%emacs emacs)) (parameterize ((%emacs emacs))
(emacs-byte-compile-directory site-lisp)))) (emacs-byte-compile-directory (elpa-directory out)))))
(define* (patch-el-files #:key outputs #:allow-other-keys) (define* (patch-el-files #:key outputs #:allow-other-keys)
"Substitute the absolute \"/bin/\" directory with the right location in the "Substitute the absolute \"/bin/\" directory with the right location in the
@ -116,7 +129,8 @@ (define (file-contains-nul-char? file)
#:binary #t)) #:binary #t))
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(site-lisp (string-append out %install-dir)) (elpa-name-ver (store-directory->elpa-name-version out))
(el-dir (string-append out %install-dir "/" elpa-name-ver))
;; (ice-9 regex) uses libc's regexp routines, which cannot deal with ;; (ice-9 regex) uses libc's regexp routines, which cannot deal with
;; strings containing NULs. Filter out such files. TODO: Remove ;; strings containing NULs. Filter out such files. TODO: Remove
;; this workaround when <https://bugs.gnu.org/30116> is fixed. ;; this workaround when <https://bugs.gnu.org/30116> is fixed.
@ -130,7 +144,7 @@ (define (substitute-program-names)
(error "patch-el-files: unable to locate " cmd-name)) (error "patch-el-files: unable to locate " cmd-name))
(string-append "\"" cmd "\""))))) (string-append "\"" cmd "\"")))))
(with-directory-excursion site-lisp (with-directory-excursion el-dir
;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still ;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still
;; ISO-8859-1-encoded. ;; ISO-8859-1-encoded.
(unless (false-if-exception (substitute-program-names)) (unless (false-if-exception (substitute-program-names))
@ -181,14 +195,14 @@ (define (match-stripped-file action regex)
(not (any (cut match-stripped-file "excluded" <>) exclude))))) (not (any (cut match-stripped-file "excluded" <>) exclude)))))
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(site-lisp (string-append out %install-dir)) (el-dir (elpa-directory out))
(files-to-install (find-files source install-file?))) (files-to-install (find-files source install-file?)))
(cond (cond
((not (null? files-to-install)) ((not (null? files-to-install))
(for-each (for-each
(lambda (file) (lambda (file)
(let* ((stripped-file (string-drop file (string-length source))) (let* ((stripped-file (string-drop file (string-length source)))
(target-file (string-append site-lisp stripped-file))) (target-file (string-append el-dir stripped-file)))
(format #t "`~a' -> `~a'~%" file target-file) (format #t "`~a' -> `~a'~%" file target-file)
(install-file file (dirname target-file)))) (install-file file (dirname target-file))))
files-to-install) files-to-install)
@ -219,11 +233,11 @@ (define* (make-autoloads #:key outputs inputs #:allow-other-keys)
"Generate the autoloads file." "Generate the autoloads file."
(let* ((emacs (string-append (assoc-ref inputs "emacs") "/bin/emacs")) (let* ((emacs (string-append (assoc-ref inputs "emacs") "/bin/emacs"))
(out (assoc-ref outputs "out")) (out (assoc-ref outputs "out"))
(site-lisp (string-append out %install-dir))
(elpa-name-ver (store-directory->elpa-name-version out)) (elpa-name-ver (store-directory->elpa-name-version out))
(elpa-name (package-name->name+version elpa-name-ver))) (elpa-name (package-name->name+version elpa-name-ver))
(el-dir (elpa-directory out)))
(parameterize ((%emacs emacs)) (parameterize ((%emacs emacs))
(emacs-generate-autoloads elpa-name site-lisp)))) (emacs-generate-autoloads elpa-name el-dir))))
(define* (enable-autoloads-compilation #:key outputs #:allow-other-keys) (define* (enable-autoloads-compilation #:key outputs #:allow-other-keys)
"Remove the NO-BYTE-COMPILATION local variable embedded in the generated "Remove the NO-BYTE-COMPILATION local variable embedded in the generated
@ -258,10 +272,16 @@ (define (store-directory->elpa-name-version store-dir)
strip-store-file-name) strip-store-file-name)
store-dir)) store-dir))
(define (elpa-directory store-dir)
"Given the store directory STORE-DIR return the absolute install directory
for libraries following the ELPA convention."
(string-append store-dir %install-dir "/"
(store-directory->elpa-name-version store-dir)))
(define %standard-phases (define %standard-phases
(modify-phases gnu:%standard-phases (modify-phases gnu:%standard-phases
(replace 'unpack unpack) (replace 'unpack unpack)
(add-after 'unpack 'add-source-to-load-path add-source-to-load-path) (add-after 'unpack 'expand-load-path expand-load-path)
(delete 'bootstrap) (delete 'bootstrap)
(delete 'configure) (delete 'configure)
(delete 'build) (delete 'build)