summaryrefslogtreecommitdiff
path: root/tests/grafts.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-01-25 10:20:02 +0100
committerLudovic Courtès <ludo@gnu.org>2017-01-25 11:04:25 +0100
commit482fda2729c3e76999892cb8f9a0391a7bd37119 (patch)
tree377fa547185e3e9114d562033aac00de44efe226 /tests/grafts.scm
parentad91454281506869f571e225a0ba7d09303f51a1 (diff)
grafts: Do not pull derivation outputs not depended on.
Fixes <http://bugs.gnu.org/24886>. Previously, the grafting derivation of, say, brdf-explorer would pull in qt:doc even though brdf-explorer depends only on qt:out, not qt:doc. * guix/grafts.scm (with-cache): Use 'vhash-assoc' and 'vhash-cons' instead of 'vhash-assq' and 'vhash-consq'. (cumulative-grafts): Pass #:outputs to 'graft-derivation/shallow'. Use OUTPUTS instead of (derivation-output-names drv). (graft-derivation): Add #:outputs parameter; pass it to 'cumulative-grafts'. * tests/grafts.scm (make-derivation-input): New variable. ("graft-derivation, replaced derivation has multiple outputs"): Make sure P2:zzz is not part of the outputs of P3D. ("graft-derivation with #:outputs") ("graft-derivation, unused outputs not depended on"): New tests.
Diffstat (limited to 'tests/grafts.scm')
-rw-r--r--tests/grafts.scm118
1 files changed, 116 insertions, 2 deletions
diff --git a/tests/grafts.scm b/tests/grafts.scm
index 6454a03b1f5..08f05c0f758 100644
--- a/tests/grafts.scm
+++ b/tests/grafts.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -43,6 +43,9 @@
43(define %mkdir 43(define %mkdir
44 (bootstrap-binary "mkdir")) 44 (bootstrap-binary "mkdir"))
45 45
46(define make-derivation-input
47 (@@ (guix derivations) make-derivation-input))
48
46 49
47(test-begin "grafts") 50(test-begin "grafts")
48 51
@@ -241,7 +244,18 @@
241 (replacement p1r) 244 (replacement p1r)
242 (replacement-output "ONE"))) 245 (replacement-output "ONE")))
243 (p3d (graft-derivation %store p3 (list p1g)))) 246 (p3d (graft-derivation %store p3 (list p1g))))
244 (and (build-derivations %store (list p3d)) 247
248 (and (not (find (lambda (input)
249 ;; INPUT should not be P2:zzz since the result of P3
250 ;; does not depend on it. See
251 ;; <http://bugs.gnu.org/24886>.
252 (and (string=? (derivation-input-path input)
253 (derivation-file-name p2))
254 (member "zzz"
255 (derivation-input-sub-derivations input))))
256 (derivation-inputs p3d)))
257
258 (build-derivations %store (list p3d))
245 (let ((out (derivation->output-path (pk 'p2d p3d)))) 259 (let ((out (derivation->output-path (pk 'p2d p3d))))
246 (and (not (string=? (readlink out) 260 (and (not (string=? (readlink out)
247 (derivation->output-path p2 "aaa"))) 261 (derivation->output-path p2 "aaa")))
@@ -249,6 +263,106 @@
249 (readlink (string-append out "/two"))) 263 (readlink (string-append out "/two")))
250 (file-exists? (string-append out "/one/replacement"))))))) 264 (file-exists? (string-append out "/one/replacement")))))))
251 265
266(test-assert "graft-derivation with #:outputs"
267 ;; Call 'graft-derivation' with a narrowed set of outputs passed as
268 ;; #:outputs.
269 (let* ((p1 (build-expression->derivation
270 %store "p1"
271 `(let ((one (assoc-ref %outputs "one"))
272 (two (assoc-ref %outputs "two")))
273 (mkdir one)
274 (mkdir two))
275 #:outputs '("one" "two")))
276 (p1r (build-expression->derivation
277 %store "P1"
278 `(let ((other (assoc-ref %outputs "ONE")))
279 (mkdir other)
280 (call-with-output-file (string-append other "/replacement")
281 (const #t)))
282 #:outputs '("ONE")))
283 (p2 (build-expression->derivation
284 %store "p2"
285 `(let ((aaa (assoc-ref %outputs "aaa"))
286 (zzz (assoc-ref %outputs "zzz")))
287 (mkdir zzz) (chdir zzz)
288 (mkdir aaa) (chdir aaa)
289 (symlink (assoc-ref %build-inputs "p1:two") "two"))
290 #:outputs '("aaa" "zzz")
291 #:inputs `(("p1:one" ,p1 "one")
292 ("p1:two" ,p1 "two"))))
293 (p1g (graft
294 (origin p1)
295 (origin-output "one")
296 (replacement p1r)
297 (replacement-output "ONE")))
298 (p2g (graft-derivation %store p2 (list p1g)
299 #:outputs '("aaa"))))
300 ;; P2:aaa depends on P1:two, but not on P1:one, so nothing to graft.
301 (eq? p2g p2)))
302
303(test-equal "graft-derivation, unused outputs not depended on"
304 '("aaa")
305
306 ;; Make sure that the result of 'graft-derivation' does not pull outputs
307 ;; that are irrelevant to the grafting process. See
308 ;; <http://bugs.gnu.org/24886>.
309 (let* ((p1 (build-expression->derivation
310 %store "p1"
311 `(let ((one (assoc-ref %outputs "one"))
312 (two (assoc-ref %outputs "two")))
313 (mkdir one)
314 (mkdir two))
315 #:outputs '("one" "two")))
316 (p1r (build-expression->derivation
317 %store "P1"
318 `(let ((other (assoc-ref %outputs "ONE")))
319 (mkdir other)
320 (call-with-output-file (string-append other "/replacement")
321 (const #t)))
322 #:outputs '("ONE")))
323 (p2 (build-expression->derivation
324 %store "p2"
325 `(let ((aaa (assoc-ref %outputs "aaa"))
326 (zzz (assoc-ref %outputs "zzz")))
327 (mkdir zzz) (chdir zzz)
328 (symlink (assoc-ref %build-inputs "p1:two") "two")
329 (mkdir aaa) (chdir aaa)
330 (symlink (assoc-ref %build-inputs "p1:one") "one"))
331 #:outputs '("aaa" "zzz")
332 #:inputs `(("p1:one" ,p1 "one")
333 ("p1:two" ,p1 "two"))))
334 (p1g (graft
335 (origin p1)
336 (origin-output "one")
337 (replacement p1r)
338 (replacement-output "ONE")))
339 (p2g (graft-derivation %store p2 (list p1g)
340 #:outputs '("aaa"))))
341
342 ;; Here P2G should only depend on P1:one and P1R:one; it must not depend
343 ;; on P1:two or P1R:two since these are unused in the grafting process.
344 (and (not (eq? p2g p2))
345 (let* ((inputs (derivation-inputs p2g))
346 (match-input (lambda (drv)
347 (lambda (input)
348 (string=? (derivation-input-path input)
349 (derivation-file-name drv)))))
350 (p1-inputs (filter (match-input p1) inputs))
351 (p1r-inputs (filter (match-input p1r) inputs))
352 (p2-inputs (filter (match-input p2) inputs)))
353 (and (equal? p1-inputs
354 (list (make-derivation-input (derivation-file-name p1)
355 '("one"))))
356 (equal? p1r-inputs
357 (list
358 (make-derivation-input (derivation-file-name p1r)
359 '("ONE"))))
360 (equal? p2-inputs
361 (list
362 (make-derivation-input (derivation-file-name p2)
363 '("aaa"))))
364 (derivation-output-names p2g))))))
365
252(test-assert "graft-derivation, renaming" ;<http://bugs.gnu.org/23132> 366(test-assert "graft-derivation, renaming" ;<http://bugs.gnu.org/23132>
253 (let* ((build `(begin 367 (let* ((build `(begin
254 (use-modules (guix build utils)) 368 (use-modules (guix build utils))