aboutsummaryrefslogtreecommitdiff
path: root/guix/gexp.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/gexp.scm')
-rw-r--r--guix/gexp.scm67
1 files changed, 58 insertions, 9 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index e31324e101..ff80e305db 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -109,6 +109,17 @@ the cross-compilation target triplet."
(return input)))
inputs))))
+(define* (lower-reference-graphs graphs #:key system target)
+ "Given GRAPHS, a list of (FILE-NAME INPUT ...) lists for use as a
+#:reference-graphs argument, lower it such that each INPUT is replaced by the
+corresponding derivation."
+ (match graphs
+ (((file-names . inputs) ...)
+ (mlet %store-monad ((inputs (lower-inputs inputs
+ #:system system
+ #:target target)))
+ (return (map cons file-names inputs))))))
+
(define* (gexp->derivation name exp
#:key
system (target 'current)
@@ -127,10 +138,38 @@ names of Guile modules from the current search path to be copied in the store,
compiled, and made available in the load path during the execution of
EXP---e.g., '((guix build utils) (guix build gnu-build-system)).
+When REFERENCES-GRAPHS is true, it must be a list of tuples of one of the
+following forms:
+
+ (FILE-NAME PACKAGE)
+ (FILE-NAME PACKAGE OUTPUT)
+ (FILE-NAME DERIVATION)
+ (FILE-NAME DERIVATION OUTPUT)
+ (FILE-NAME STORE-ITEM)
+
+The right-hand-side of each element of REFERENCES-GRAPHS is automatically made
+an input of the build process of EXP. In the build environment, each
+FILE-NAME contains the reference graph of the corresponding item, in a simple
+text format.
+
+In that case, the reference graph of each store path is exported in
+the build environment in the corresponding file, in a simple text format.
+
The other arguments are as for 'derivation'."
(define %modules modules)
(define outputs (gexp-outputs exp))
+ (define (graphs-file-names graphs)
+ ;; Return a list of (FILE-NAME . STORE-PATH) pairs made from GRAPHS.
+ (map (match-lambda
+ ((file-name (? derivation? drv))
+ (cons file-name (derivation->output-path drv)))
+ ((file-name (? derivation? drv) sub-drv)
+ (cons file-name (derivation->output-path drv sub-drv)))
+ ((file-name thing)
+ (cons file-name thing)))
+ graphs))
+
(mlet* %store-monad (;; The following binding is here to force
;; '%current-system' and '%current-target-system' to be
;; looked up at >>= time.
@@ -162,6 +201,11 @@ The other arguments are as for 'derivation'."
#:system system
#:guile guile-for-build)
(return #f)))
+ (graphs (if references-graphs
+ (lower-reference-graphs references-graphs
+ #:system system
+ #:target target)
+ (return #f)))
(guile (if guile-for-build
(return guile-for-build)
(package->derivation (default-guile)
@@ -182,9 +226,12 @@ The other arguments are as for 'derivation'."
(,builder)
,@(if modules
`((,modules) (,compiled) ,@inputs)
- inputs))
+ inputs)
+ ,@(match graphs
+ (((_ . inputs) ...) inputs)
+ (_ '())))
#:hash hash #:hash-algo hash-algo #:recursive? recursive?
- #:references-graphs references-graphs
+ #:references-graphs (and=> graphs graphs-file-names)
#:local-build? local-build?)))
(define* (gexp-inputs exp #:optional (references gexp-references))
@@ -449,14 +496,16 @@ its search path."
(format port
"#!~a/bin/guile --no-auto-compile~%!#~%"
(ungexp guile))
+
+ ;; Write the 'eval-when' form so that it can be
+ ;; compiled.
(write
- '(set! %load-path
- (cons (ungexp modules) %load-path))
- port)
- (write
- '(set! %load-compiled-path
- (cons (ungexp compiled)
- %load-compiled-path))
+ '(eval-when (expand load eval)
+ (set! %load-path
+ (cons (ungexp modules) %load-path))
+ (set! %load-compiled-path
+ (cons (ungexp compiled)
+ %load-compiled-path)))
port)
(write '(ungexp exp) port)
(chmod port #o555)))))))