From 4038b0c53d5066facceea3c159a6510fa8a625d6 Mon Sep 17 00:00:00 2001 From: zimoun Date: Sun, 7 Jun 2020 11:07:08 +0200 Subject: [PATCH] DRAFT: build-system: emacs: Add new 'package-with-emacs-next'procedure. * guix/build-system/emacs.scm: Add 'default-emacs-next'. * guix/build-system/emacs.scm: Add 'package-with-emacs-next'. --- guix/build-system/emacs.scm | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/guix/build-system/emacs.scm b/guix/build-system/emacs.scm index ef6d1b3397..8732678dca 100644 --- a/guix/build-system/emacs.scm +++ b/guix/build-system/emacs.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 Federico Beffa +;;; Copyright © 2020 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -29,6 +30,7 @@ #:use-module (ice-9 match) #:use-module (srfi srfi-26) #:export (%emacs-build-system-modules + package-with-emacs-next emacs-build emacs-build-system) #:re-export (%default-include ;for convenience @@ -54,6 +56,70 @@ (let ((emacs-mod (resolve-interface '(gnu packages emacs)))) (module-ref emacs-mod 'emacs-minimal))) +(define (default-emacs-next) + "Return the default Emacs-next package." + (let ((emacs-mod (resolve-interface '(gnu packages emacs)))) + (module-ref emacs-mod 'emacs-next))) + +(define* (package-with-explicit-emacs emacs old-prefix new-prefix + #:key variant-property) + "Return a procedure of one argument, P. The procedure creates a package with +the same fields as P, which is assumed to use EMACS-BUILD-SYSTEM, such that +it is compiled with EMACS instead. The inputs are changed recursively +accordingly. If the name of P starts with OLD-PREFIX, this is replaced by +NEW-PREFIX; otherwise, NEW-PREFIX is prepended to the name. + +When VARIANT-PROPERTY is present, it is used as a key to search for +pre-defined variants of this transformation recorded in the 'properties' field +of packages. The property value must be the promise of a package. This is a +convenient way for package writers to force the transformation to use +pre-defined variants." + (define package-variant + (if variant-property + (lambda (package) + (assq-ref (package-properties package) + variant-property)) + (const #f))) + + (define (transform p) + (cond + ;; If VARIANT-PROPERTY is present, use that. + ((package-variant p) + => force) + + ;; Otherwise build the new package object graph. + ((eq? (package-build-system p) emacs-build-system) + (package + (inherit p) + (location (package-location p)) + (name (let ((name (package-name p))) + (string-append new-prefix + (if (string-prefix? old-prefix name) + (substring name + (string-length old-prefix)) + name)))) + (arguments + (let ((emacs (if (promise? emacs) + (force emacs) + emacs))) + (ensure-keyword-arguments (package-arguments p) + `(#:emacs ,emacs)))))) + (else p))) + + (define (cut? p) + (or (not (eq? (package-build-system p) emacs-build-system)) + (package-variant p))) + + (package-mapping transform cut?)) + +(define package-with-emacs-next + ;; Note: delay call to 'default-emacs-next' until after the 'arguments' field + ;; of packages is accessed to avoid a circular dependency when evaluating + ;; the top-level of (gnu packages emacs). + (package-with-explicit-emacs (delay (default-emacs-next)) + "emacs-" "emacs-next-" + #:variant-property 'emacs-next-variant)) + (define* (lower name #:key source inputs native-inputs outputs system target (emacs (default-emacs)) -- 2.26.2