aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-07-01 00:37:03 +0200
committerLudovic Courtès <ludo@gnu.org>2012-07-01 00:37:03 +0200
commit9a20830e57ea50dd73897725ad656a3b9e66f1ef (patch)
treecec6e88da4c3fff415562c30848e55c4bee934b3 /guix
parent31ef99a8a590cc52cea0cfda3d45651504bf1cb9 (diff)
downloadgnu-guix-9a20830e57ea50dd73897725ad656a3b9e66f1ef.tar
gnu-guix-9a20830e57ea50dd73897725ad656a3b9e66f1ef.tar.gz
Add `derivation-prerequisites' and `derivation-prerequisites-to-build'.
* guix/derivations.scm (derivation-prerequisites, derivation-prerequisites-to-build): New procedures. * tests/derivations.scm ("build-expression->derivation and derivation-prerequisites", "build-expression->derivation and derivation-prerequisites-to-build"): New tests.
Diffstat (limited to 'guix')
-rw-r--r--guix/derivations.scm43
1 files changed, 42 insertions, 1 deletions
diff --git a/guix/derivations.scm b/guix/derivations.scm
index 6011a3d97e..a2bff44a5f 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -26,19 +26,24 @@
#:use-module (ice-9 rdelim)
#:use-module (guix store)
#:use-module (guix utils)
- #:export (derivation?
+ #:export (<derivation>
+ derivation?
derivation-outputs
derivation-inputs
derivation-sources
derivation-system
derivation-builder-arguments
derivation-builder-environment-vars
+ derivation-prerequisites
+ derivation-prerequisites-to-build
+ <derivation-output>
derivation-output?
derivation-output-path
derivation-output-hash-algo
derivation-output-hash
+ <derivation-input>
derivation-input?
derivation-input-path
derivation-input-sub-derivations
@@ -92,6 +97,42 @@ download with a fixed hash (aka. `fetchurl')."
#t)
(_ #f)))
+(define (derivation-prerequisites drv)
+ "Return the list of derivation-inputs required to build DRV, recursively."
+ (let loop ((drv drv)
+ (result '()))
+ (let ((inputs (remove (cut member <> result) ; XXX: quadratic
+ (derivation-inputs drv))))
+ (fold loop
+ (append inputs result)
+ (map (lambda (i)
+ (call-with-input-file (derivation-input-path i)
+ read-derivation))
+ inputs)))))
+
+(define (derivation-prerequisites-to-build store drv)
+ "Return the list of derivation-inputs required to build DRV and not already
+available in STORE, recursively."
+ (define input-built?
+ (match-lambda
+ (($ <derivation-input> path sub-drvs)
+ (let ((out (map (cut derivation-path->output-path path <>)
+ sub-drvs)))
+ (any (cut valid-path? store <>) out)))))
+
+ (let loop ((drv drv)
+ (result '()))
+ (let ((inputs (remove (lambda (i)
+ (or (member i result) ; XXX: quadratic
+ (input-built? i)))
+ (derivation-inputs drv))))
+ (fold loop
+ (append inputs result)
+ (map (lambda (i)
+ (call-with-input-file (derivation-input-path i)
+ read-derivation))
+ inputs)))))
+
(define (read-derivation drv-port)
"Read the derivation from DRV-PORT and return the corresponding
<derivation> object."