diff options
author | Ludovic Courtès <[email protected]> | 2021-03-08 09:39:27 +0100 |
---|---|---|
committer | Ludovic Courtès <[email protected]> | 2021-03-30 22:48:43 +0200 |
commit | 789babb76174758cbe0f159d4f61a65aefa9b4a4 (patch) | |
tree | 5b05afd3774ec8d595cf8c7ed3060bec0ad5372e | |
parent | cea364e7ff6ca9095aff83c83656e3c7aa0c2e62 (diff) |
gexp: Add 'with-build-variables'.
* guix/gexp.scm (with-build-variables): New procedure.
-rw-r--r-- | guix/gexp.scm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm index 78ce19956c..6bdc7ba11d 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 @@ -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) |