unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: [PATCH 3/5] build: Add 'emacs-build-system'
@ 2015-07-07  7:21 Federico Beffa
  2015-07-07 16:58 ` Alex Kost
  0 siblings, 1 reply; 24+ messages in thread
From: Federico Beffa @ 2015-07-07  7:21 UTC (permalink / raw)
  To: alezost; +Cc: Guix-devel

Alex Kost <alezost@gmail.com> writes:

> Wouldn't it be better to name it "elpa-build-system" as that's what it
> is in my opinion, since it does not retrieve the source directly from
> upstream but from ELPA/MELPA/... "repositories" instead.

The build system doesn't assume anything about the source location.

>
> I imagine there may appear another build system for simple emacs
> packages (that don't provide Makefile, etc.) that will compile elisp
> files, generate autoloads and so on.  I think it will be a system that
> should be called "emacs-build-system".  WDYT?

That's what the proposed build system does. If it lacks some
functionality that you think is desirable, I think it is better to add
it here rather than adding another, almost identical, build system.

Regards,
Fede

^ permalink raw reply	[flat|nested] 24+ messages in thread
* [PATCH 3/5] build: Add 'emacs-build-system'
@ 2015-06-21  8:31 Federico Beffa
  2015-06-21 20:40 ` Alex Kost
  2015-07-06 17:47 ` Alex Kost
  0 siblings, 2 replies; 24+ messages in thread
From: Federico Beffa @ 2015-06-21  8:31 UTC (permalink / raw)
  To: Guix-devel

[-- Attachment #1: Type: text/plain, Size: 33 bytes --]

A new 'emacs-buld-system'.

Fede

[-- Attachment #2: 0003-build-Add-emacs-build-system.patch --]
[-- Type: text/x-diff, Size: 17135 bytes --]

From 9c090ddd7de011b369208cdeb28eb3eaa5dc6011 Mon Sep 17 00:00:00 2001
From: Federico Beffa <beffa@fbengineering.ch>
Date: Sun, 21 Jun 2015 10:10:05 +0200
Subject: [PATCH 3/5] build: Add 'emacs-build-system'.

* Makefile.am (MODULES): Add 'guix/build-system/emacs.scm' and
  'guix/build/emacs-build-system.scm'.
* guix/build-system/emacs.scm: New file.
* guix/build/emacs-build-system.scm: New file.
* doc/guix.texi (Build Systems): Document it.
---
 Makefile.am                       |   2 +
 doc/guix.texi                     |  11 ++
 guix/build-system/emacs.scm       | 141 +++++++++++++++++++++++++
 guix/build/emacs-build-system.scm | 212 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 366 insertions(+)
 create mode 100644 guix/build-system/emacs.scm
 create mode 100644 guix/build/emacs-build-system.scm

diff --git a/Makefile.am b/Makefile.am
index c027fb3..a013b7a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,7 @@ MODULES =					\
   guix/licenses.scm				\
   guix/build-system.scm				\
   guix/build-system/cmake.scm			\
+  guix/build-system/emacs.scm			\
   guix/build-system/glib-or-gtk.scm		\
   guix/build-system/gnu.scm			\
   guix/build-system/haskell.scm			\
@@ -67,6 +68,7 @@ MODULES =					\
   guix/ui.scm					\
   guix/build/download.scm			\
   guix/build/cmake-build-system.scm		\
+  guix/build/emacs-build-system.scm		\
   guix/build/git.scm				\
   guix/build/glib-or-gtk-build-system.scm	\
   guix/build/gnu-build-system.scm		\
diff --git a/doc/guix.texi b/doc/guix.texi
index 3ca105a..00fe5bb 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2404,6 +2404,17 @@ Which Haskell compiler is used can be specified with the @code{#:haskell}
 parameter which defaults to @code{ghc}.
 @end defvr
 
+@defvr {Scheme Variable} emacs-build-system
+This variable is exported by @code{(guix build-system haskell)}.  It
+implements an installation procedure similar to the one of Emacs own
+packaging system.  It first creates the @code{PACKAGE-autoloads.el}
+file, then it byte compiles all Emacs Lisp files.  Differently from the
+Emacs packaging system, the @code{info} documentation files are moved to
+the standard documentation direcotry and the @code{dir} file is deleted.
+Each package is installed in its own directory under
+@code{share/emacs/site-lisp/guix.d}.
+@end defvr
+
 Lastly, for packages that do not need anything as sophisticated, a
 ``trivial'' build system is provided.  It is trivial in the sense that
 it provides basically no support: it does not pull any implicit inputs,
diff --git a/guix/build-system/emacs.scm b/guix/build-system/emacs.scm
new file mode 100644
index 0000000..da2b594
--- /dev/null
+++ b/guix/build-system/emacs.scm
@@ -0,0 +1,141 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
+;;;
+;;; 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-system emacs)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (guix packages)
+  #:use-module (guix derivations)
+  #:use-module (guix search-paths)
+  #:use-module (guix build-system)
+  #:use-module (guix build-system gnu)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-26)
+  #:export (%emacs-build-system-modules
+            emacs-build
+            emacs-build-system))
+
+;; Commentary:
+;;
+;; Standard build procedure for Emacs packages.  This is implemented as an
+;; extension of 'gnu-build-system'.
+;;
+;; Code:
+
+(define %emacs-build-system-modules
+  ;; Build-side modules imported by default.
+  `((guix build emacs-build-system)
+    (guix build emacs-utils)
+    ,@%gnu-build-system-modules))
+
+(define (default-emacs)
+  "Return the default Emacs package."
+  ;; Lazily resolve the binding to avoid a circular dependency.
+  (let ((emacs-mod (resolve-interface '(gnu packages emacs))))
+    ;; we use 'emacs' instead of 'emacs-no-x' because the latter appears not
+    ;; to be loading some macros and causes problems to some packages.  For
+    ;; example, with the latter AUCTeX gives the error message:
+    ;; "(invalid-function dbus-ignore-errors)".
+    (module-ref emacs-mod 'emacs)))
+
+(define* (lower name
+                #:key source inputs native-inputs outputs system target
+                (emacs (default-emacs))
+                #:allow-other-keys
+                #:rest arguments)
+  "Return a bag for NAME."
+  (define private-keywords
+    '(#:target #:emacs #:inputs #:native-inputs))
+
+  (and (not target)                               ;XXX: no cross-compilation
+       (bag
+         (name name)
+         (system system)
+         (host-inputs `(,@(if source
+                              `(("source" ,source))
+                              '())
+                        ,@inputs
+
+                        ;; Keep the standard inputs of 'gnu-build-system'.
+                        ,@(standard-packages)))
+         (build-inputs `(("emacs" ,emacs)
+                         ,@native-inputs))
+         (outputs outputs)
+         (build emacs-build)
+         (arguments (strip-keyword-arguments private-keywords arguments)))))
+
+(define* (emacs-build store name inputs
+                      #:key source
+                      (tests? #t)
+                      (test-target "test")
+                      (configure-flags ''())
+                      (phases '(@ (guix build emacs-build-system)
+                                  %standard-phases))
+                      (outputs '("out"))
+                      (search-paths '())
+                      (system (%current-system))
+                      (guile #f)
+                      (imported-modules %emacs-build-system-modules)
+                      (modules '((guix build emacs-build-system)
+                                 (guix build utils)
+                                 (guix build emacs-utils))))
+  "Build SOURCE using EMACS, and with INPUTS."
+  (define builder
+    `(begin
+       (use-modules ,@modules)
+       (emacs-build #:name ,name
+                    #:source ,(match (assoc-ref inputs "source")
+                                (((? derivation? source))
+                                 (derivation->output-path source))
+                                ((source)
+                                 source)
+                                (source
+                                 source))
+                    #:configure-flags ,configure-flags
+                    #:system ,system
+                    #:test-target ,test-target
+                    #:tests? ,tests?
+                    #:phases ,phases
+                    #:outputs %outputs
+                    #:search-paths ',(map search-path-specification->sexp
+                                          search-paths)
+                    #:inputs %build-inputs)))
+  
+  (define guile-for-build
+    (match guile
+      ((? package?)
+       (package-derivation store guile system #:graft? #f))
+      (#f                                         ; the default
+       (let* ((distro (resolve-interface '(gnu packages commencement)))
+              (guile  (module-ref distro 'guile-final)))
+         (package-derivation store guile system #:graft? #f)))))
+
+  (build-expression->derivation store name builder
+                                #:inputs inputs
+                                #:system system
+                                #:modules imported-modules
+                                #:outputs outputs
+                                #:guile-for-build guile-for-build))
+
+(define emacs-build-system
+  (build-system
+    (name 'emacs)
+    (description "The build system for Emacs packages")
+    (lower lower)))
+
+;;; emacs.scm ends here
diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
new file mode 100644
index 0000000..86dcdb9
--- /dev/null
+++ b/guix/build/emacs-build-system.scm
@@ -0,0 +1,212 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
+;;;
+;;; 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)
+  #:use-module (srfi srfi-26)
+  #:use-module (ice-9 rdelim)
+  #:use-module (ice-9 regex)
+  #:use-module (ice-9 match)
+  #:export (%standard-phases
+            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.
+(define %install-suffix "/share/emacs/site-lisp/guix.d")
+
+(define-syntax lambda*-with-emacs-env
+  (lambda (x)
+    "Creates a 'lambda*' expression where the following variables are bound to
+the values expected by the 'emacs-build-system': 'emacs', 'out', 'name-ver',
+'name', 'elpa-name-ver', 'elpa-name', 'info-dir', 'el-dir'.  The first
+parameter of the syntax must be a list of symbols which become key parameters
+of the procedure.  'inputs' and 'outputs' are automatically added to them.
+The remaining parameters become the body of the procedure."
+    (syntax-case x ()
+      ((k (p ...) e1 e2 ...)
+       (with-syntax (((outputs inputs emacs out name-ver name elpa-name-ver
+                               elpa-name info-dir el-dir)
+                      (map (cut datum->syntax #'k <>)
+                           '(outputs inputs emacs out name-ver name
+                                     elpa-name-ver elpa-name
+                                     info-dir el-dir))))
+         #'(lambda* (#:key outputs inputs p ... #:allow-other-keys)
+             (let* ((emacs (string-append (assoc-ref inputs "emacs")
+                                          "/bin/emacs"))
+                    (out (assoc-ref outputs "out"))
+                    (name-ver (store-dir->name-version out))
+                    (name (package-name->name+version name-ver))
+                    (elpa-name-ver (store-dir->elpa-name-version out))
+                    (elpa-name (package-name->name+version elpa-name-ver))
+                    (info-dir (string-append out "/share/info/" name-ver))
+                    (el-dir (string-append out %install-suffix
+                                           "/" elpa-name-ver)))
+               e1 e2 ...)))))))
+
+;; Compile .el files.
+(define build
+  (lambda*-with-emacs-env ()
+    (let ((deps-dirs (emacs-inputs-dirs inputs)))
+      (setenv "SHELL" "sh")
+      (parameterize ((%emacs emacs))
+        (emacs-byte-compile-directory el-dir
+                                      (emacs-inputs-el-dirs deps-dirs))))))
+
+;; Substitute the absolute \"/bin/\" directory with the right location in the
+;; store in '.el' files.
+(define patch-el-files
+  (lambda*-with-emacs-env ()
+    (let ((substitute-cmd (lambda ()
+                            (substitute* (find-files "." "\\.el$")
+                              (("\"/bin/(.*)\"" _ cmd)
+                               (string-append "\"" (which cmd) "\""))))))
+      (with-directory-excursion el-dir
+        ;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still encoded
+        ;; with the "ISO-8859-1" locale.
+        (unless (false-if-exception (substitute-cmd))
+          (with-fluids ((%default-port-encoding "ISO-8859-1"))
+            (substitute-cmd))))
+      #t)))
+
+;;  Install the package contents.
+(define install
+  (lambda*-with-emacs-env ()
+    (let ((src-dir (getcwd))
+          (tgt-dir (string-append out %install-suffix "/" elpa-name-ver)))
+    (copy-recursively src-dir tgt-dir)
+    #t)))
+
+;;  Move info files from the ELPA package directory to the info directory.
+(define move-doc
+  (lambda*-with-emacs-env ()
+    (let ((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)))
+
+;;  Generate the autoloads file.
+(define make-autoloads
+  (lambda*-with-emacs-env ()
+    (parameterize ((%emacs emacs))
+      (emacs-generate-autoloads elpa-name el-dir))
+    #t))
+
+(define (emacs-package? name)
+  "Check if NAME correspond to the name of an Emacs package."
+  (string-prefix? "emacs-" name))
+
+(define (emacs-inputs inputs)
+  "Retrive the list of Emacs packages from inputs."
+  (filter (lambda (p)
+            (and (pair? p)
+                 (emacs-package? (package-name->name+version (first p)))))
+          inputs))
+
+(define (emacs-inputs-dirs inputs)
+  "Extract the list of Emacs package directories from INPUTS."
+  (let ((emacs-ins (emacs-inputs inputs)))
+    (match emacs-ins
+      (((name . dir) ...) dir))))
+
+(define (emacs-inputs-el-dirs dirs)
+  "Build the list of Emacs Lisp directories from the Emacs package directory
+DIRS."
+  (map (lambda (d)
+         (string-append d %install-suffix "/"
+                        (store-dir->elpa-name-version d)))
+       dirs))
+
+(define (package-name-version->elpa-name-version name-ver)
+  "Convert the Guix package NAME-VER to the corresponding ELPA name-version
+format.  Essnetially drop the prefix used in Guix."
+  (let ((name (store-dir->name-version name-ver)))
+    (if (emacs-package? name-ver)
+        (store-dir->name-version name-ver)
+        name-ver)))
+
+(define (store-dir->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
+            store-dir->name-version)
+   store-dir))
+
+(define (store-dir->name-version store-dir)
+  "Given a store directory STORE-DIR return the part of the basename
+after the first hyphen.  This corresponds to 'name-version' of the package."
+  (let* ((base (basename store-dir)))
+    (string-drop base
+                 (+ 1 (string-index base #\-)))))
+
+;; from (guix utils).  Should we put it in (guix build utils)?
+(define (package-name->name+version name)
+  "Given NAME, a package name like \"foo-0.9.1b\", return two values:
+\"foo\" and \"0.9.1b\".  When the version part is unavailable, NAME and
+#f are returned.  The first hyphen followed by a digit is considered to
+introduce the version part."
+  ;; See also `DrvName' in Nix.
+
+  (define number?
+    (cut char-set-contains? char-set:digit <>))
+
+  (let loop ((chars   (string->list name))
+             (prefix '()))
+    (match chars
+      (()
+       (values name #f))
+      ((#\- (? number? n) rest ...)
+       (values (list->string (reverse prefix))
+               (list->string (cons n rest))))
+      ((head tail ...)
+       (loop tail (cons head prefix))))))
+
+(define %standard-phases
+  (modify-phases gnu:%standard-phases
+    (delete 'configure)
+    (delete 'check)
+    (delete 'install)
+    (replace 'build build)
+    (add-before 'build 'install install)
+    (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
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-07-15 21:52 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07  7:21 [PATCH 3/5] build: Add 'emacs-build-system' Federico Beffa
2015-07-07 16:58 ` Alex Kost
2015-07-08 20:22   ` Federico Beffa
2015-07-09  8:51     ` Alex Kost
2015-07-09 20:41       ` Federico Beffa
2015-07-10  6:47         ` Alex Kost
2015-07-10  7:43           ` Federico Beffa
2015-07-15 21:52           ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2015-06-21  8:31 Federico Beffa
2015-06-21 20:40 ` Alex Kost
2015-06-22  8:51   ` Federico Beffa
2015-06-22 11:49     ` Mathieu Lirzin
2015-06-22 17:59     ` Alex Kost
2015-06-22 19:33       ` Federico Beffa
2015-06-22 19:40         ` Thompson, David
2015-06-23  6:51           ` Federico Beffa
2015-06-25 11:57             ` Ludovic Courtès
2015-06-25 18:39               ` Federico Beffa
2015-06-23 11:57         ` Alex Kost
2015-06-24 16:12           ` Federico Beffa
2015-06-25 12:33             ` Ludovic Courtès
2015-06-25 18:36               ` Federico Beffa
2015-06-27  9:59                 ` Ludovic Courtès
2015-07-06 17:47 ` Alex Kost

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).