guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some macros to make package definitions prettier


From: Taylan Ulrich Bayırlı/Kammer
Subject: Re: Some macros to make package definitions prettier
Date: Thu, 26 Feb 2015 12:07:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

address@hidden (Ludovic Courtès) writes:

> address@hidden (Taylan Ulrich "Bayırlı/Kammer") skribis:
>
>> (modify-phases '((foo . 0) (bar . 1) (baz . 2))
>>   (delete foo)
>>   (replace bar 'x)
>>   (add-before baz pre-baz 'y)) ;=> ((bar . x) (pre-baz . y) (baz . 2))
>
> I like it!  Let’s put it in (guix utils)?

Shouldn't it go to (guix build utils)?  Here's a patch:

>From 320a974e9b04959544bb93c67766957541ec02ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Taylan=20Ulrich=20Bay=C4=B1rl=C4=B1/Kammer?=
 <address@hidden>
Date: Thu, 26 Feb 2015 11:51:11 +0100
Subject: [PATCH] utils: Add 'modify-phases'.

* guix/build/utils.scm (modify-phases): New macro.
---
 guix/build/utils.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 4407f9a..c35966f 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -54,6 +54,7 @@
             alist-cons-before
             alist-cons-after
             alist-replace
+            modify-phases
             with-atomic-file-replacement
             substitute
             substitute*
@@ -423,6 +424,33 @@ An error is raised when no such pair exists."
       ((_ after ...)
        (append before (alist-cons key value after))))))
 
+(define-syntax-rule (modify-phases phases mod-spec ...)
+  "Modify PHASES sequentially as per each MOD-SPEC, which may have one of the
+following forms:
+
+  (delete <old-phase-name>)
+  (replace <old-phase-name> <new-phase>)
+  (add-before <old-phase-name> <new-phase-name> <new-phase>)
+  (add-after <old-phase-name> <new-phase-name> <new-phase>)
+
+Where every <*-phase-name> is an automatically quoted symbol, and <new-phase>
+an expression evaluating to a procedure."
+  (let* ((phases* phases)
+         (phases* (%modify-phases phases* mod-spec))
+         ...)
+    phases*))
+
+(define-syntax %modify-phases
+  (syntax-rules (delete replace add-before add-after)
+    ((_ phases (delete old-phase-name))
+     (alist-delete 'old-phase-name phases))
+    ((_ phases (replace old-phase-name new-phase))
+     (alist-replace 'old-phase-name new-phase phases))
+    ((_ phases (add-before old-phase-name new-phase-name new-phase))
+     (alist-cons-before 'old-phase-name 'new-phase-name new-phase phases))
+    ((_ phases (add-after old-phase-name new-phase-name new-phase))
+     (alist-cons-after 'old-phase-name 'new-phase-name new-phase phases))))
+
 
 ;;;
 ;;; Text substitution (aka. sed).
-- 
2.2.1

On the other topic, I'm afraid I know yet too little about gexprs and
Guix internals...

Taylan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]