2015-06-21 10:10:05 +02:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
|
2016-06-20 14:49:04 +02:00
|
|
|
;;; Copyright © 2016 David Thompson <davet@gnu.org>
|
|
|
|
;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
|
2018-01-13 23:54:18 +01:00
|
|
|
;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
2015-06-21 10:10:05 +02:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(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 emacs-utils)
|
|
|
|
#:use-module (srfi srfi-1)
|
2016-05-27 15:58:39 +02:00
|
|
|
#:use-module (srfi srfi-11)
|
2015-06-21 10:10:05 +02:00
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
#:use-module (ice-9 rdelim)
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:export (%standard-phases
|
2017-06-04 08:43:02 +02:00
|
|
|
%default-include
|
|
|
|
%default-exclude
|
2015-06-21 10:10:05 +02:00
|
|
|
emacs-build))
|
|
|
|
|
|
|
|
;; Commentary:
|
|
|
|
;;
|
|
|
|
;; Builder-side code of the build procedure for ELPA Emacs packages.
|
|
|
|
;;
|
|
|
|
;; Code:
|
|
|
|
|
|
|
|
;; Directory suffix where we install ELPA packages. We avoid ".../elpa" as
|
|
|
|
;; Emacs expects to find the ELPA repository 'archive-contents' file and the
|
|
|
|
;; archive signature.
|
2018-01-13 23:54:18 +01:00
|
|
|
(define %legacy-install-suffix "/share/emacs/site-lisp")
|
|
|
|
(define %install-suffix (string-append %legacy-install-suffix "/guix.d"))
|
2015-06-21 10:10:05 +02:00
|
|
|
|
2017-06-04 08:43:02 +02:00
|
|
|
;; These are the default inclusion/exclusion regexps for the install phase.
|
|
|
|
(define %default-include '("^[^/]*\\.el$" "^[^/]*\\.info$" "^doc/.*\\.info$"))
|
|
|
|
(define %default-exclude '("^\\.dir-locals\\.el$" "-pkg\\.el$"
|
|
|
|
"^[^/]*tests?\\.el$"))
|
|
|
|
|
2016-05-27 15:58:39 +02:00
|
|
|
(define gnu:unpack (assoc-ref gnu:%standard-phases 'unpack))
|
|
|
|
|
|
|
|
(define (store-file->elisp-source-file file)
|
|
|
|
"Convert FILE, a store file name for an Emacs Lisp source file, into a file
|
|
|
|
name that has been stripped of the hash and version number."
|
2017-05-17 18:09:27 +02:00
|
|
|
(let ((suffix ".el"))
|
|
|
|
(let-values (((name version)
|
|
|
|
(package-name->name+version
|
|
|
|
(basename
|
|
|
|
(strip-store-file-name file) suffix))))
|
|
|
|
(string-append name suffix))))
|
2016-05-27 15:58:39 +02:00
|
|
|
|
|
|
|
(define* (unpack #:key source #:allow-other-keys)
|
|
|
|
"Unpack SOURCE into the build directory. SOURCE may be a compressed
|
|
|
|
archive, a directory, or an Emacs Lisp file."
|
|
|
|
(if (string-suffix? ".el" source)
|
|
|
|
(begin
|
|
|
|
(mkdir "source")
|
|
|
|
(chdir "source")
|
|
|
|
(copy-file source (store-file->elisp-source-file source))
|
|
|
|
#t)
|
|
|
|
(gnu:unpack #:source source)))
|
|
|
|
|
2018-03-30 02:52:41 +02:00
|
|
|
(define* (set-emacs-load-path #:key source inputs #:allow-other-keys)
|
|
|
|
(define (inputs->directories inputs)
|
|
|
|
"Extract the directory part from INPUTS."
|
|
|
|
(match inputs
|
|
|
|
(((names . directories) ...) directories)))
|
|
|
|
|
|
|
|
(define (input-directory->el-directory input-directory)
|
|
|
|
"Return the correct Emacs Lisp directory in INPUT-DIRECTORY or #f, if there
|
|
|
|
is no Emacs Lisp directory."
|
|
|
|
(let ((legacy-elisp-directory (string-append input-directory %legacy-install-suffix))
|
|
|
|
(guix-elisp-directory
|
|
|
|
(string-append
|
|
|
|
input-directory %install-suffix "/"
|
|
|
|
(store-directory->elpa-name-version input-directory))))
|
|
|
|
(cond
|
|
|
|
((file-exists? guix-elisp-directory) guix-elisp-directory)
|
|
|
|
((file-exists? legacy-elisp-directory) legacy-elisp-directory)
|
|
|
|
(else #f))))
|
|
|
|
|
|
|
|
(define (input-directories->el-directories input-directories)
|
|
|
|
"Return the list of Emacs Lisp directories in INPUT-DIRECTORIES."
|
|
|
|
(filter-map input-directory->el-directory input-directories))
|
|
|
|
|
2018-01-13 23:54:18 +01:00
|
|
|
"Set the EMACSLOADPATH environment variable so that dependencies are found."
|
2018-03-30 02:52:41 +02:00
|
|
|
(let* ((source-directory (getcwd))
|
|
|
|
(input-elisp-directories (input-directories->el-directories
|
|
|
|
(inputs->directories inputs)))
|
|
|
|
(emacs-load-path-value
|
|
|
|
(string-join
|
|
|
|
(append input-elisp-directories (list source-directory))
|
|
|
|
":" 'suffix)))
|
2018-01-13 23:54:18 +01:00
|
|
|
(setenv "EMACSLOADPATH" emacs-load-path-value)
|
|
|
|
(format #t "environment variable `EMACSLOADPATH' set to ~a\n"
|
|
|
|
emacs-load-path-value)))
|
|
|
|
|
2015-06-21 10:10:05 +02:00
|
|
|
(define* (build #:key outputs inputs #:allow-other-keys)
|
|
|
|
"Compile .el files."
|
|
|
|
(let* ((emacs (string-append (assoc-ref inputs "emacs") "/bin/emacs"))
|
|
|
|
(out (assoc-ref outputs "out"))
|
|
|
|
(elpa-name-ver (store-directory->elpa-name-version out))
|
2018-01-13 23:54:18 +01:00
|
|
|
(el-dir (string-append out %install-suffix "/" elpa-name-ver)))
|
2015-06-21 10:10:05 +02:00
|
|
|
(setenv "SHELL" "sh")
|
|
|
|
(parameterize ((%emacs emacs))
|
2018-01-13 23:54:18 +01:00
|
|
|
(emacs-byte-compile-directory el-dir))))
|
2015-06-21 10:10:05 +02:00
|
|
|
|
|
|
|
(define* (patch-el-files #:key outputs #:allow-other-keys)
|
|
|
|
"Substitute the absolute \"/bin/\" directory with the right location in the
|
|
|
|
store in '.el' files."
|
2018-01-15 04:38:20 +01:00
|
|
|
|
|
|
|
(define (file-contains-nul-char? file)
|
|
|
|
(call-with-input-file file
|
|
|
|
(lambda (in)
|
|
|
|
(let loop ((line (read-line in 'concat)))
|
|
|
|
(cond
|
|
|
|
((eof-object? line) #f)
|
|
|
|
((string-index line #\nul) #t)
|
|
|
|
(else (loop (read-line in 'concat))))))
|
|
|
|
#:binary #t))
|
|
|
|
|
2015-06-21 10:10:05 +02:00
|
|
|
(let* ((out (assoc-ref outputs "out"))
|
|
|
|
(elpa-name-ver (store-directory->elpa-name-version out))
|
|
|
|
(el-dir (string-append out %install-suffix "/" elpa-name-ver))
|
2018-01-15 04:38:20 +01:00
|
|
|
|
|
|
|
;; (ice-9 regex) uses libc's regexp routines, which cannot deal with
|
|
|
|
;; strings containing NULs. Filter out such files. TODO: Remove
|
|
|
|
;; this workaround when <https://bugs.gnu.org/30116> is fixed.
|
|
|
|
(el-files (remove file-contains-nul-char?
|
|
|
|
(find-files (getcwd) "\\.el$"))))
|
|
|
|
(define (substitute-program-names)
|
|
|
|
(substitute* el-files
|
|
|
|
(("\"/bin/([^.]\\S*)\"" _ cmd-name)
|
|
|
|
(let ((cmd (which cmd-name)))
|
|
|
|
(unless cmd
|
|
|
|
(error "patch-el-files: unable to locate " cmd-name))
|
|
|
|
(string-append "\"" cmd "\"")))))
|
|
|
|
|
2015-06-21 10:10:05 +02:00
|
|
|
(with-directory-excursion el-dir
|
2018-01-15 04:38:20 +01:00
|
|
|
;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still
|
|
|
|
;; ISO-8859-1-encoded.
|
|
|
|
(unless (false-if-exception (substitute-program-names))
|
2015-06-21 10:10:05 +02:00
|
|
|
(with-fluids ((%default-port-encoding "ISO-8859-1"))
|
2018-01-15 04:38:20 +01:00
|
|
|
(substitute-program-names))))
|
2015-06-21 10:10:05 +02:00
|
|
|
#t))
|
|
|
|
|
2017-04-19 09:29:11 +02:00
|
|
|
(define* (install #:key outputs
|
2017-06-04 08:43:02 +02:00
|
|
|
(include %default-include)
|
|
|
|
(exclude %default-exclude)
|
2017-04-19 09:29:11 +02:00
|
|
|
#:allow-other-keys)
|
2015-06-21 10:10:05 +02:00
|
|
|
"Install the package contents."
|
2017-04-19 09:29:11 +02:00
|
|
|
|
|
|
|
(define source (getcwd))
|
|
|
|
|
2017-08-22 19:11:35 +02:00
|
|
|
(define* (install-file? file stat #:key verbose?)
|
|
|
|
(let* ((stripped-file (string-trim
|
|
|
|
(string-drop file (string-length source)) #\/)))
|
|
|
|
(define (match-stripped-file action regex)
|
|
|
|
(let ((result (string-match regex stripped-file)))
|
|
|
|
(when (and result verbose?)
|
|
|
|
(format #t "info: ~A ~A as it matches \"~A\"\n"
|
|
|
|
stripped-file action regex))
|
|
|
|
result))
|
|
|
|
|
|
|
|
(when verbose?
|
|
|
|
(format #t "info: considering installing ~A\n" stripped-file))
|
|
|
|
|
|
|
|
(and (any (cut match-stripped-file "included" <>) include)
|
|
|
|
(not (any (cut match-stripped-file "excluded" <>) exclude)))))
|
2017-04-19 09:29:11 +02:00
|
|
|
|
2015-06-21 10:10:05 +02:00
|
|
|
(let* ((out (assoc-ref outputs "out"))
|
|
|
|
(elpa-name-ver (store-directory->elpa-name-version out))
|
2017-08-22 19:11:35 +02:00
|
|
|
(target-directory (string-append out %install-suffix "/" elpa-name-ver))
|
|
|
|
(files-to-install (find-files source install-file?)))
|
|
|
|
(cond
|
2017-09-03 20:39:11 +02:00
|
|
|
((not (null? files-to-install))
|
2017-08-22 19:11:35 +02:00
|
|
|
(for-each
|
|
|
|
(lambda (file)
|
|
|
|
(let* ((stripped-file (string-drop file (string-length source)))
|
|
|
|
(target-file (string-append target-directory stripped-file)))
|
|
|
|
(format #t "`~a' -> `~a'~%" file target-file)
|
|
|
|
(install-file file (dirname target-file))))
|
|
|
|
files-to-install)
|
|
|
|
#t)
|
|
|
|
(else
|
|
|
|
(format #t "error: No files found to install.\n")
|
|
|
|
(find-files source (lambda (file stat)
|
|
|
|
(install-file? file stat #:verbose? #t)))
|
|
|
|
#f))))
|
2015-06-21 10:10:05 +02:00
|
|
|
|
|
|
|
(define* (move-doc #:key outputs #:allow-other-keys)
|
|
|
|
"Move info files from the ELPA package directory to the info directory."
|
|
|
|
(let* ((out (assoc-ref outputs "out"))
|
|
|
|
(elpa-name-ver (store-directory->elpa-name-version out))
|
|
|
|
(el-dir (string-append out %install-suffix "/" elpa-name-ver))
|
2015-08-30 14:38:10 +02:00
|
|
|
(name-ver (strip-store-file-name out))
|
2015-09-13 21:28:01 +02:00
|
|
|
(info-dir (string-append out "/share/info/"))
|
2015-06-21 10:10:05 +02:00
|
|
|
(info-files (find-files el-dir "\\.info$")))
|
|
|
|
(unless (null? info-files)
|
|
|
|
(mkdir-p info-dir)
|
|
|
|
(with-directory-excursion el-dir
|
|
|
|
(when (file-exists? "dir") (delete-file "dir"))
|
|
|
|
(for-each (lambda (f)
|
|
|
|
(copy-file f (string-append info-dir "/" (basename f)))
|
|
|
|
(delete-file f))
|
|
|
|
info-files)))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define* (make-autoloads #:key outputs inputs #:allow-other-keys)
|
|
|
|
"Generate the autoloads file."
|
|
|
|
(let* ((emacs (string-append (assoc-ref inputs "emacs") "/bin/emacs"))
|
|
|
|
(out (assoc-ref outputs "out"))
|
|
|
|
(elpa-name-ver (store-directory->elpa-name-version out))
|
|
|
|
(elpa-name (package-name->name+version elpa-name-ver))
|
|
|
|
(el-dir (string-append out %install-suffix "/" elpa-name-ver)))
|
|
|
|
(parameterize ((%emacs emacs))
|
2018-04-16 04:46:26 +02:00
|
|
|
(emacs-generate-autoloads elpa-name el-dir))))
|
2015-06-21 10:10:05 +02:00
|
|
|
|
|
|
|
(define (emacs-package? name)
|
|
|
|
"Check if NAME correspond to the name of an Emacs package."
|
|
|
|
(string-prefix? "emacs-" name))
|
|
|
|
|
|
|
|
(define (package-name-version->elpa-name-version name-ver)
|
|
|
|
"Convert the Guix package NAME-VER to the corresponding ELPA name-version
|
2018-01-13 23:54:18 +01:00
|
|
|
format. Essentially drop the prefix used in Guix."
|
2015-09-23 23:34:54 +02:00
|
|
|
(if (emacs-package? name-ver) ; checks for "emacs-" prefix
|
|
|
|
(string-drop name-ver (string-length "emacs-"))
|
|
|
|
name-ver))
|
2015-06-21 10:10:05 +02:00
|
|
|
|
|
|
|
(define (store-directory->elpa-name-version store-dir)
|
|
|
|
"Given a store directory STORE-DIR return the part of the basename after the
|
|
|
|
second hyphen. This corresponds to 'name-version' as used in ELPA packages."
|
|
|
|
((compose package-name-version->elpa-name-version
|
2015-08-30 14:38:10 +02:00
|
|
|
strip-store-file-name)
|
2015-06-21 10:10:05 +02:00
|
|
|
store-dir))
|
|
|
|
|
|
|
|
(define %standard-phases
|
|
|
|
(modify-phases gnu:%standard-phases
|
2016-05-27 15:58:39 +02:00
|
|
|
(replace 'unpack unpack)
|
2018-03-30 02:52:41 +02:00
|
|
|
(add-after 'unpack 'set-emacs-load-path set-emacs-load-path)
|
2015-06-21 10:10:05 +02:00
|
|
|
(delete 'configure)
|
2018-01-13 23:54:18 +01:00
|
|
|
;; Move the build phase after install: the .el files are byte compiled
|
|
|
|
;; directly in the store.
|
|
|
|
(delete 'build)
|
|
|
|
(replace 'install install)
|
|
|
|
(add-after 'install 'build build)
|
2015-06-21 10:10:05 +02:00
|
|
|
(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)))
|
|
|
|
|
|
|
|
(define* (emacs-build #:key inputs (phases %standard-phases)
|
|
|
|
#:allow-other-keys #:rest args)
|
|
|
|
"Build the given Emacs package, applying all of PHASES in order."
|
|
|
|
(apply gnu:gnu-build
|
|
|
|
#:inputs inputs #:phases phases
|
|
|
|
args))
|
|
|
|
|
|
|
|
;;; emacs-build-system.scm ends here
|