From 789babb76174758cbe0f159d4f61a65aefa9b4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 8 Mar 2021 09:39:27 +0100 Subject: [PATCH] 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 78ce19956c..6bdc7ba11d 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -104,6 +104,7 @@ (define-module (guix gexp) lowered-gexp-load-path lowered-gexp-load-compiled-path + with-build-variables gexp->derivation gexp->file gexp->script @@ -1786,6 +1787,30 @@ (define* (load-path-expression modules #:optional (path %load-path) 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)