From 5b0c9d1635df1608a498db8718af575d2f0e1663 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 26 Aug 2013 22:12:46 +0200 Subject: derivations: Add #:dependency-graphs `derivation' parameter. * guix/derivations.scm (derivation): Add `dependency-graphs' keyword parameter; honor it. * tests/derivations.scm (bootstrap-binary): New procedure. (%bash): Use it. (%mkdir): New variable. (directory-contents): Add `slurp' optional parameter. ("derivation with #:dependency-graphs"): New test. * doc/guix.texi (Derivations): Update accordingly. --- tests/derivations.scm | 68 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/derivations.scm b/tests/derivations.scm index 9833e15112..9b3d92a7bf 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm @@ -50,19 +50,23 @@ (define %store (let ((drv (package-derivation %store %bootstrap-guile))) (%guile-for-build drv))) -(define %bash - (let ((bash (search-bootstrap-binary "bash" (%current-system)))) +(define (bootstrap-binary name) + (let ((bin (search-bootstrap-binary name (%current-system)))) (and %store - (add-to-store %store "bash" #t "sha256" bash)))) + (add-to-store %store name #t "sha256" bin)))) + +(define %bash + (bootstrap-binary "bash")) +(define %mkdir + (bootstrap-binary "mkdir")) -(define (directory-contents dir) +(define* (directory-contents dir #:optional (slurp get-bytevector-all)) "Return an alist representing the contents of DIR." (define prefix-len (string-length dir)) (sort (file-system-fold (const #t) ; enter? (lambda (path stat result) ; leaf (alist-cons (string-drop path prefix-len) - (call-with-input-file path - get-bytevector-all) + (call-with-input-file path slurp) result)) (lambda (path stat result) result) ; down (lambda (path stat result) result) ; up @@ -84,7 +88,7 @@ (define prefix-len (string-length dir)) (and (equal? b1 b2) (equal? d1 d2)))) -(test-skip (if %store 0 11)) +(test-skip (if %store 0 12)) (test-assert "add-to-store, flat" (let* ((file (search-path %load-path "language/tree-il/spec.scm")) @@ -292,6 +296,56 @@ (define prefix-len (string-length dir)) (and (valid-path? %store p) (equal? '(one two) (call-with-input-file p read))))))) +(test-assert "derivation with #:dependency-graphs" + (let* ((input1 (add-text-to-store %store "foo" "hello" + (list %bash))) + (input2 (add-text-to-store %store "bar" + (number->string (random 7777)) + (list input1))) + (builder (add-text-to-store %store "build-graph" + (format #f " +~a $out + (while read l ; do echo $l ; done) < bash > $out/bash + (while read l ; do echo $l ; done) < input1 > $out/input1 + (while read l ; do echo $l ; done) < input2 > $out/input2" + %mkdir) + (list %mkdir))) + (drv (derivation %store "closure-graphs" + %bash `(,builder) + #:dependency-graphs + `(("bash" . ,%bash) + ("input1" . ,input1) + ("input2" . ,input2)) + #:inputs `((,%bash) (,builder)))) + (out (derivation-path->output-path drv))) + (define (deps path . deps) + (let ((count (length deps))) + (string-append path "\n\n" (number->string count) "\n" + (string-join (sort deps string? input1 %bash) + (string-append (deps %bash) + (deps input1 %bash)) + (string-append (deps input1 %bash) + (deps %bash)))) + ("/input2" . ,(string-concatenate + (map cdr + (sort + (map (lambda (p d) + (cons p (apply deps p d))) + (list %bash input1 input2) + (list '() (list %bash) (list input1))) + (lambda (x y) + (match x + ((p1 . _) + (match y + ((p2 . _) + (string