guix-commits
[Top][All Lists]
Advanced

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

12/29: gexp: Add 'with-build-variables'.


From: guix-commits
Subject: 12/29: gexp: Add 'with-build-variables'.
Date: Mon, 8 Mar 2021 06:24:51 -0500 (EST)

civodul pushed a commit to branch wip-build-systems-gexp
in repository guix.

commit 9514caaebf0b863f4302a26f906f3a017e6a2157
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Mar 8 09:39:27 2021 +0100

    gexp: Add 'with-build-variables'.
    
    * guix/gexp.scm (with-build-variables): New procedure.
---
 guix/gexp.scm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index e9b8503..c7fabfe 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -104,6 +104,7 @@
             lowered-gexp-load-path
             lowered-gexp-load-compiled-path
 
+            with-build-variables
             gexp->derivation
             gexp->file
             gexp->script
@@ -1785,6 +1786,30 @@ are searched for in PATH.  Return #f when MODULES and 
EXTENSIONS are empty."
                                          extensions))
                               %load-compiled-path)))))))))
 
+(define (with-build-variables inputs outputs body)
+  "Return a gexp that surrounds BODY with a definition of the legacy
+'%build-inputs', '%outputs', and '%output' variables based on INPUTS, a list
+of name/gexp-input tuples, and OUTPUTS, a list of strings."
+
+  ;; These two variables are defined for backward compatibility.  They are
+  ;; used by package expressions.  These must be top-level defines so that
+  ;; 'use-modules' form in BODY that are required for macro expansion work as
+  ;; expected.
+  (gexp (begin
+          (define %build-inputs
+            (map (lambda (tuple)
+                   (apply cons tuple))
+                 '(ungexp inputs)))
+          (define %outputs
+            (list (ungexp-splicing
+                   (map (lambda (name)
+                          (gexp (cons (ungexp name)
+                                      (ungexp output name))))
+                        outputs))))
+          (define  %output
+            (assoc-ref %outputs "out"))
+          (ungexp body))))
+
 (define* (gexp->script name exp
                        #:key (guile (default-guile))
                        (module-path %load-path)



reply via email to

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