summaryrefslogtreecommitdiff
path: root/tests/derivations.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/derivations.scm')
-rw-r--r--tests/derivations.scm217
1 files changed, 148 insertions, 69 deletions
diff --git a/tests/derivations.scm b/tests/derivations.scm
index 788cffd7ad..9092e3acd6 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -50,19 +50,23 @@
(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 @@
(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"))
@@ -106,9 +110,9 @@
(let* ((builder (add-text-to-store %store "my-builder.sh"
"echo hello, world\n"
'()))
- (drv-path (derivation %store "foo" (%current-system)
+ (drv-path (derivation %store "foo"
%bash `("-e" ,builder)
- '(("HOME" . "/homeless")) '())))
+ #:env-vars '(("HOME" . "/homeless")))))
(and (store-path? drv-path)
(valid-path? %store drv-path))))
@@ -118,12 +122,12 @@
"echo hello, world > \"$out\"\n"
'()))
((drv-path drv)
- (derivation %store "foo" (%current-system)
+ (derivation %store "foo"
%bash `(,builder)
- '(("HOME" . "/homeless")
- ("zzz" . "Z!")
- ("AAA" . "A!"))
- `((,builder))))
+ #:env-vars '(("HOME" . "/homeless")
+ ("zzz" . "Z!")
+ ("AAA" . "A!"))
+ #:inputs `((,builder))))
((succeeded?)
(build-derivations %store (list drv-path))))
(and succeeded?
@@ -139,18 +143,17 @@
"(while read line ; do echo \"$line\" ; done) < $in > $out"
'()))
(input (search-path %load-path "ice-9/boot-9.scm"))
+ (input* (add-to-store %store (basename input)
+ #t "sha256" input))
(drv-path (derivation %store "derivation-with-input-file"
- (%current-system)
%bash `(,builder)
- `(("in"
- ;; Cheat to pass the actual file
- ;; name to the builder.
- . ,(add-to-store %store
- (basename input)
- #t "sha256"
- input)))
- `((,builder)
- (,input))))) ; ← local file name
+
+ ;; Cheat to pass the actual file name to the
+ ;; builder.
+ #:env-vars `(("in" . ,input*))
+
+ #:inputs `((,builder)
+ (,input))))) ; ← local file name
(and (build-derivations %store (list drv-path))
;; Note: we can't compare the files because the above trick alters
;; the contents.
@@ -160,10 +163,9 @@
(let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
"echo -n hello > $out" '()))
(hash (sha256 (string->utf8 "hello")))
- (drv-path (derivation %store "fixed" (%current-system)
+ (drv-path (derivation %store "fixed"
%bash `(,builder)
- '()
- `((,builder)) ; optional
+ #:inputs `((,builder)) ; optional
#:hash hash #:hash-algo 'sha256))
(succeeded? (build-derivations %store (list drv-path))))
(and succeeded?
@@ -178,13 +180,11 @@
(builder2 (add-text-to-store %store "fixed-builder2.sh"
"echo hey; echo -n hello > $out" '()))
(hash (sha256 (string->utf8 "hello")))
- (drv-path1 (derivation %store "fixed" (%current-system)
+ (drv-path1 (derivation %store "fixed"
%bash `(,builder1)
- '() `()
#:hash hash #:hash-algo 'sha256))
- (drv-path2 (derivation %store "fixed" (%current-system)
+ (drv-path2 (derivation %store "fixed"
%bash `(,builder2)
- '() `()
#:hash hash #:hash-algo 'sha256))
(succeeded? (build-derivations %store
(list drv-path1 drv-path2))))
@@ -201,27 +201,25 @@
(builder2 (add-text-to-store %store "fixed-builder2.sh"
"echo hey; echo -n hello > $out" '()))
(hash (sha256 (string->utf8 "hello")))
- (fixed1 (derivation %store "fixed" (%current-system)
+ (fixed1 (derivation %store "fixed"
%bash `(,builder1)
- '() `()
#:hash hash #:hash-algo 'sha256))
- (fixed2 (derivation %store "fixed" (%current-system)
+ (fixed2 (derivation %store "fixed"
%bash `(,builder2)
- '() `()
#:hash hash #:hash-algo 'sha256))
(fixed-out (derivation-path->output-path fixed1))
(builder3 (add-text-to-store
%store "final-builder.sh"
;; Use Bash hackery to avoid Coreutils.
"echo $in ; (read -u 3 c; echo $c) 3< $in > $out" '()))
- (final1 (derivation %store "final" (%current-system)
+ (final1 (derivation %store "final"
%bash `(,builder3)
- `(("in" . ,fixed-out))
- `((,builder3) (,fixed1))))
- (final2 (derivation %store "final" (%current-system)
+ #:env-vars `(("in" . ,fixed-out))
+ #:inputs `((,builder3) (,fixed1))))
+ (final2 (derivation %store "final"
%bash `(,builder3)
- `(("in" . ,fixed-out))
- `((,builder3) (,fixed2))))
+ #:env-vars `(("in" . ,fixed-out))
+ #:inputs `((,builder3) (,fixed2))))
(succeeded? (build-derivations %store
(list final1 final2))))
(and succeeded?
@@ -232,12 +230,12 @@
(let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
"echo one > $out ; echo two > $second"
'()))
- (drv-path (derivation %store "fixed" (%current-system)
+ (drv-path (derivation %store "fixed"
%bash `(,builder)
- '(("HOME" . "/homeless")
- ("zzz" . "Z!")
- ("AAA" . "A!"))
- `((,builder))
+ #:env-vars '(("HOME" . "/homeless")
+ ("zzz" . "Z!")
+ ("AAA" . "A!"))
+ #:inputs `((,builder))
#:outputs '("out" "second")))
(succeeded? (build-derivations %store (list drv-path))))
(and succeeded?
@@ -255,10 +253,9 @@
(let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
"echo one > $out ; echo two > $AAA"
'()))
- (drv-path (derivation %store "fixed" (%current-system)
+ (drv-path (derivation %store "fixed"
%bash `(,builder)
- '()
- `((,builder))
+ #:inputs `((,builder))
#:outputs '("out" "AAA")))
(succeeded? (build-derivations %store (list drv-path))))
(and succeeded?
@@ -273,10 +270,9 @@
(let* ((builder1 (add-text-to-store %store "my-mo-builder.sh"
"echo one > $out ; echo two > $two"
'()))
- (mdrv (derivation %store "multiple-output" (%current-system)
+ (mdrv (derivation %store "multiple-output"
%bash `(,builder1)
- '()
- `((,builder1))
+ #:inputs `((,builder1))
#:outputs '("out" "two")))
(builder2 (add-text-to-store %store "my-mo-user-builder.sh"
"read x < $one;
@@ -284,21 +280,72 @@
echo \"($x $y)\" > $out"
'()))
(udrv (derivation %store "multiple-output-user"
- (%current-system)
%bash `(,builder2)
- `(("one" . ,(derivation-path->output-path
- mdrv "out"))
- ("two" . ,(derivation-path->output-path
- mdrv "two")))
- `((,builder2)
- ;; two occurrences of MDRV:
- (,mdrv)
- (,mdrv "two")))))
+ #:env-vars `(("one"
+ . ,(derivation-path->output-path
+ mdrv "out"))
+ ("two"
+ . ,(derivation-path->output-path
+ mdrv "two")))
+ #:inputs `((,builder2)
+ ;; two occurrences of MDRV:
+ (,mdrv)
+ (,mdrv "two")))))
(and (build-derivations %store (list (pk 'udrv udrv)))
(let ((p (derivation-path->output-path udrv)))
(and (valid-path? %store p)
(equal? '(one two) (call-with-input-file p read)))))))
+(test-assert "derivation with #:references-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)
+ #:references-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<?) "\n")
+ (if (zero? count) "" "\n"))))
+
+ (and (build-derivations %store (list drv))
+ (equal? (directory-contents out get-string-all)
+ `(("/bash" . ,(string-append %bash "\n\n0\n"))
+ ("/input1" . ,(if (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<? p1 p2)))))))))))))))
+
(define %coreutils
(false-if-exception
@@ -314,14 +361,14 @@
"echo $PATH ; mkdir --version ; mkdir $out ; touch $out/good"
'()))
(drv-path
- (derivation %store "foo" (%current-system)
+ (derivation %store "foo"
%bash `(,builder)
- `(("PATH" .
- ,(string-append
- (derivation-path->output-path %coreutils)
- "/bin")))
- `((,builder)
- (,%coreutils))))
+ #:env-vars `(("PATH" .
+ ,(string-append
+ (derivation-path->output-path %coreutils)
+ "/bin")))
+ #:inputs `((,builder)
+ (,%coreutils))))
(succeeded?
(build-derivations %store (list drv-path))))
(and succeeded?
@@ -329,7 +376,7 @@
(and (valid-path? %store p)
(file-exists? (string-append p "/good")))))))
-(test-skip (if (%guile-for-build) 0 7))
+(test-skip (if (%guile-for-build) 0 8))
(test-assert "build-expression->derivation and derivation-prerequisites"
(let-values (((drv-path drv)
@@ -605,6 +652,38 @@ Deriver: ~a~%"
(derivation-path->output-path final2))
(build-derivations %store (list final1 final2)))))
+(test-assert "build-expression->derivation with #:references-graphs"
+ (let* ((input (add-text-to-store %store "foo" "hello"
+ (list %bash %mkdir)))
+ (builder '(copy-file "input" %output))
+ (drv (build-expression->derivation %store "references-graphs"
+ (%current-system)
+ builder '()
+ #:references-graphs
+ `(("input" . ,input))))
+ (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<?) "\n")
+ (if (zero? count) "" "\n"))))
+
+ (and (build-derivations %store (list drv))
+ (equal? (call-with-input-file out get-string-all)
+ (string-concatenate
+ (map cdr
+ (sort (map (lambda (p d)
+ (cons p (apply deps p d)))
+ (list input %bash %mkdir)
+ (list (list %bash %mkdir)
+ '() '()))
+ (lambda (x y)
+ (match x
+ ((p1 . _)
+ (match y
+ ((p2 . _)
+ (string<? p1 p2)))))))))))))
+
(test-end)