~ruther/guix-local

789babb76174758cbe0f159d4f61a65aefa9b4a4 — Ludovic Courtès 5 years ago cea364e
gexp: Add 'with-build-variables'.

* guix/gexp.scm (with-build-variables): New procedure.
1 files changed, 25 insertions(+), 0 deletions(-)

M guix/gexp.scm
M guix/gexp.scm => guix/gexp.scm +25 -0
@@ 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)