summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-12-06 23:18:57 +0100
committerLudovic Courtès <ludo@gnu.org>2020-01-05 11:40:01 +0100
commitba6390df42a3495a6a68d9a32ddbb3edd090dc0d (patch)
tree3c15b4a11f39d057835cbe663d828e8dbf1aad03
parent09763444ce748487640c95d4e1a2cf9645c4e250 (diff)
downloadguix-ba6390df42a3495a6a68d9a32ddbb3edd090dc0d.tar.gz
DRAFT gexp: Add 'raw-derivation-closure'.
DRAFT: Add tests.

* guix/gexp.scm (<raw-derivation-closure>): New record type.
(sorted-references): New procedure.
(raw-derivation-closure-compiler): New gexp compiler.
-rw-r--r--guix/gexp.scm32
1 files changed, 32 insertions, 0 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index c4f4e80209..7bfff07766 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -82,6 +82,9 @@
             raw-derivation-file
             raw-derivation-file?
 
+            raw-derivation-closure
+            raw-derivation-closure?
+
             load-path-expression
             gexp-modules
 
@@ -291,6 +294,35 @@ The expander specifies how an object is converted to its sexp representation."
                     (derivation-file-name lowered)
                     lowered)))
 
+;; File containing the closure of a raw .drv file, in topological order.  This
+;; works around a deficiency of #:references-graphs that can produce the
+;; reference graph of an output, but not that of a raw .drv file.
+(define-record-type <raw-derivation-closure>
+  (raw-derivation-closure obj)
+  raw-derivation-closure?
+  (obj  raw-derivation-closure-object))
+
+(define sorted-references
+  (store-lift (lambda (store item)
+                (define (fixed-output? file)
+                  (and (string-suffix? ".drv" file)
+                       (let ((drv (read-derivation-from-file file)))
+                         (fixed-output-derivation? drv))))
+
+                (topologically-sorted store (list item)
+                                      #:cut? fixed-output?))))
+
+(define-gexp-compiler (raw-derivation-closure-compiler
+                       (obj <raw-derivation-closure>)
+                       system target)
+  (mlet %store-monad ((obj (lower-object
+                            (raw-derivation-closure-object obj)
+                            system #:target target)))
+    (if (derivation? obj)
+        (mlet %store-monad ((refs (sorted-references (derivation-file-name obj))))
+          (text-file "graph" (object->string refs)))
+        (return obj))))
+
 
 ;;;
 ;;; File declarations.