gexp: Add 'with-build-variables'.

* guix/gexp.scm (with-build-variables): New procedure.
This commit is contained in:
Ludovic Courtès 2021-03-08 09:39:27 +01:00
parent cea364e7ff
commit 789babb761
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 25 additions and 0 deletions

View File

@ -104,6 +104,7 @@
lowered-gexp-load-path
lowered-gexp-load-compiled-path
with-build-variables
gexp->derivation
gexp->file
gexp->script
@ -1786,6 +1787,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)