diff options
| -rw-r--r-- | guix/gexp.scm | 81 | ||||
| -rw-r--r-- | guix/grafts.scm | 23 | ||||
| -rw-r--r-- | tests/gexp.scm | 19 |
3 files changed, 71 insertions, 52 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm index 574d51e10d3..edeb12ea26c 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm | |||
| @@ -195,6 +195,9 @@ Upon success, return the three argument procedure; otherwise return #f." | |||
| 195 | corresponding to OBJ for SYSTEM, cross-compiling for TARGET if TARGET is true. | 195 | corresponding to OBJ for SYSTEM, cross-compiling for TARGET if TARGET is true. |
| 196 | OBJ must be an object that has an associated gexp compiler, such as a | 196 | OBJ must be an object that has an associated gexp compiler, such as a |
| 197 | <package>." | 197 | <package>." |
| 198 | ;; FIXME: Must register build continuation (or 'guix system build' does not | ||
| 199 | ;; graft its things because 'system-derivation' uses 'lower-object', not | ||
| 200 | ;; 'gexp->derivation'.) | ||
| 198 | (let ((lower (lookup-compiler obj))) | 201 | (let ((lower (lookup-compiler obj))) |
| 199 | (lower obj system target))) | 202 | (lower obj system target))) |
| 200 | 203 | ||
| @@ -656,7 +659,7 @@ The other arguments are as for 'derivation'." | |||
| 656 | (mlet* %store-monad (;; The following binding forces '%current-system' and | 659 | (mlet* %store-monad (;; The following binding forces '%current-system' and |
| 657 | ;; '%current-target-system' to be looked up at >>= | 660 | ;; '%current-target-system' to be looked up at >>= |
| 658 | ;; time. | 661 | ;; time. |
| 659 | (graft? (set-grafting graft?)) | 662 | (prev-graft? (set-grafting #f)) |
| 660 | 663 | ||
| 661 | (system -> (or system (%current-system))) | 664 | (system -> (or system (%current-system))) |
| 662 | (target -> (if (eq? target 'current) | 665 | (target -> (if (eq? target 'current) |
| @@ -701,38 +704,50 @@ The other arguments are as for 'derivation'." | |||
| 701 | #:system system | 704 | #:system system |
| 702 | #:target target) | 705 | #:target target) |
| 703 | (return #f))) | 706 | (return #f))) |
| 704 | (guile (if guile-for-build | 707 | (guile (if guile-for-build |
| 705 | (return guile-for-build) | 708 | (return guile-for-build) |
| 706 | (default-guile-derivation system)))) | 709 | (default-guile-derivation system)))) |
| 707 | (mbegin %store-monad | 710 | (>>= (mbegin %store-monad |
| 708 | (set-grafting graft?) ;restore the initial setting | 711 | (set-grafting prev-graft?) ;restore the initial setting |
| 709 | (raw-derivation name | 712 | (raw-derivation name |
| 710 | (string-append (derivation->output-path guile) | 713 | (string-append (derivation->output-path guile) |
| 711 | "/bin/guile") | 714 | "/bin/guile") |
| 712 | `("--no-auto-compile" | 715 | `("--no-auto-compile" |
| 713 | ,@(if (pair? %modules) | 716 | ,@(if (pair? %modules) |
| 714 | `("-L" ,(derivation->output-path modules) | 717 | `("-L" ,(derivation->output-path modules) |
| 715 | "-C" ,(derivation->output-path compiled)) | 718 | "-C" ,(derivation->output-path compiled)) |
| 716 | '()) | 719 | '()) |
| 717 | ,builder) | 720 | ,builder) |
| 718 | #:outputs outputs | 721 | #:outputs outputs |
| 719 | #:env-vars env-vars | 722 | #:env-vars env-vars |
| 720 | #:system system | 723 | #:system system |
| 721 | #:inputs `((,guile) | 724 | #:inputs `((,guile) |
| 722 | (,builder) | 725 | (,builder) |
| 723 | ,@(if modules | 726 | ,@(if modules |
| 724 | `((,modules) (,compiled) ,@inputs) | 727 | `((,modules) (,compiled) ,@inputs) |
| 725 | inputs) | 728 | inputs) |
| 726 | ,@(match graphs | 729 | ,@(match graphs |
| 727 | (((_ . inputs) ...) inputs) | 730 | (((_ . inputs) ...) inputs) |
| 728 | (_ '()))) | 731 | (_ '()))) |
| 729 | #:hash hash #:hash-algo hash-algo #:recursive? recursive? | 732 | #:hash hash #:hash-algo hash-algo #:recursive? recursive? |
| 730 | #:references-graphs (and=> graphs graphs-file-names) | 733 | #:references-graphs (and=> graphs graphs-file-names) |
| 731 | #:allowed-references allowed | 734 | #:allowed-references allowed |
| 732 | #:disallowed-references disallowed | 735 | #:disallowed-references disallowed |
| 733 | #:leaked-env-vars leaked-env-vars | 736 | #:leaked-env-vars leaked-env-vars |
| 734 | #:local-build? local-build? | 737 | #:local-build? local-build? |
| 735 | #:substitutable? substitutable?)))) | 738 | #:substitutable? substitutable?)) |
| 739 | (if graft? | ||
| 740 | (lambda (drv) | ||
| 741 | ;; Register a build continuation to apply the relevant grafts | ||
| 742 | ;; to the outputs of DRV. | ||
| 743 | (mlet %store-monad ((grafts (gexp-grafts exp system | ||
| 744 | #:target target))) | ||
| 745 | (mbegin %store-monad | ||
| 746 | (set-build-continuation (derivation-file-name drv) | ||
| 747 | (graft-continuation drv grafts)) | ||
| 748 | (return drv)))) | ||
| 749 | (lambda (drv) | ||
| 750 | (with-monad %store-monad (return drv))))))) | ||
| 736 | 751 | ||
| 737 | (define* (gexp-inputs exp #:key native?) | 752 | (define* (gexp-inputs exp #:key native?) |
| 738 | "Return the input list for EXP. When NATIVE? is true, return only native | 753 | "Return the input list for EXP. When NATIVE? is true, return only native |
diff --git a/guix/grafts.scm b/guix/grafts.scm index 2006d3908e0..da106ae0dc8 100644 --- a/guix/grafts.scm +++ b/guix/grafts.scm | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #:use-module (srfi srfi-34) | 29 | #:use-module (srfi srfi-34) |
| 30 | #:use-module (ice-9 match) | 30 | #:use-module (ice-9 match) |
| 31 | #:use-module (ice-9 vlist) | 31 | #:use-module (ice-9 vlist) |
| 32 | #:use-module (ice-9 format) | ||
| 32 | #:export (graft? | 33 | #:export (graft? |
| 33 | graft | 34 | graft |
| 34 | graft-origin | 35 | graft-origin |
| @@ -39,6 +40,8 @@ | |||
| 39 | graft-derivation | 40 | graft-derivation |
| 40 | graft-derivation/shallow | 41 | graft-derivation/shallow |
| 41 | 42 | ||
| 43 | graft-continuation | ||
| 44 | |||
| 42 | %graft? | 45 | %graft? |
| 43 | set-grafting)) | 46 | set-grafting)) |
| 44 | 47 | ||
| @@ -321,6 +324,26 @@ DRV itself to refer to those grafted dependencies." | |||
| 321 | (graft-replacement first) | 324 | (graft-replacement first) |
| 322 | drv)))) | 325 | drv)))) |
| 323 | 326 | ||
| 327 | (define graft-derivation* | ||
| 328 | (store-lift graft-derivation)) | ||
| 329 | |||
| 330 | (define (graft-continuation drv grafts) | ||
| 331 | "Return a monadic thunk that acts as a built continuation applying GRAFTS to | ||
| 332 | the result of DRV." | ||
| 333 | (define _ gettext) ;FIXME: (guix ui)? | ||
| 334 | (match grafts | ||
| 335 | (() | ||
| 336 | (lift1 (const '()) %store-monad)) | ||
| 337 | (x | ||
| 338 | (lambda (drv-file-name) | ||
| 339 | (format #t (_ "applying ~a grafts to~{ ~a~}~%") | ||
| 340 | (length grafts) | ||
| 341 | (match (derivation->output-paths drv) | ||
| 342 | (((outputs . items) ...) | ||
| 343 | items))) | ||
| 344 | (mlet %store-monad ((drv (graft-derivation* drv grafts))) | ||
| 345 | (return (list (derivation-file-name drv)))))))) | ||
| 346 | |||
| 324 | 347 | ||
| 325 | ;; The following might feel more at home in (guix packages) but since (guix | 348 | ;; The following might feel more at home in (guix packages) but since (guix |
| 326 | ;; gexp), which is a lower level, needs them, we put them here. | 349 | ;; gexp), which is a lower level, needs them, we put them here. |
diff --git a/tests/gexp.scm b/tests/gexp.scm index ea4243a3a67..cb4e1c94876 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm | |||
| @@ -434,25 +434,6 @@ | |||
| 434 | (equal? refs (list (dirname (dirname guile)))) | 434 | (equal? refs (list (dirname (dirname guile)))) |
| 435 | (equal? refs2 (list file)))))) | 435 | (equal? refs2 (list file)))))) |
| 436 | 436 | ||
| 437 | (test-assertm "gexp->derivation vs. grafts" | ||
| 438 | (mlet* %store-monad ((graft? (set-grafting #f)) | ||
| 439 | (p0 -> (dummy-package "dummy" | ||
| 440 | (arguments | ||
| 441 | '(#:implicit-inputs? #f)))) | ||
| 442 | (r -> (package (inherit p0) (name "DuMMY"))) | ||
| 443 | (p1 -> (package (inherit p0) (replacement r))) | ||
| 444 | (exp0 -> (gexp (frob (ungexp p0) (ungexp output)))) | ||
| 445 | (exp1 -> (gexp (frob (ungexp p1) (ungexp output)))) | ||
| 446 | (void (set-guile-for-build %bootstrap-guile)) | ||
| 447 | (drv0 (gexp->derivation "t" exp0 #:graft? #t)) | ||
| 448 | (drv1 (gexp->derivation "t" exp1 #:graft? #t)) | ||
| 449 | (drv1* (gexp->derivation "t" exp1 #:graft? #f)) | ||
| 450 | (_ (set-grafting graft?))) | ||
| 451 | (return (and (not (string=? (derivation->output-path drv0) | ||
| 452 | (derivation->output-path drv1))) | ||
| 453 | (string=? (derivation->output-path drv0) | ||
| 454 | (derivation->output-path drv1*)))))) | ||
| 455 | |||
| 456 | (test-assertm "gexp-grafts" | 437 | (test-assertm "gexp-grafts" |
| 457 | ;; Make sure 'gexp-grafts' returns the graft to replace P1 by R. | 438 | ;; Make sure 'gexp-grafts' returns the graft to replace P1 by R. |
| 458 | (let* ((p0 (dummy-package "dummy" | 439 | (let* ((p0 (dummy-package "dummy" |
