diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2013-11-13 11:22:07 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2013-11-13 11:22:07 +0100 |
| commit | a716e36de915a275e4eab42b73cf0a2affc4aa33 (patch) | |
| tree | affdccec604ccf00846b7e48f85fcf1861672b87 | |
| parent | f80594cc41d7ad491f14a73d594228bacafdc871 (diff) | |
derivations: Allow 'map-derivations' to replace sources.
* guix/derivations.scm (map-derivation)[input->output-paths]: Allow
non-derivation inputs.
Allow replacements to be store files. Replace in SOURCES too.
* tests/derivations.scm ("map-derivation, sources"): New test.
| -rw-r--r-- | guix/derivations.scm | 26 | ||||
| -rw-r--r-- | tests/derivations.scm | 22 |
2 files changed, 41 insertions, 7 deletions
diff --git a/guix/derivations.scm b/guix/derivations.scm index b33e835556b..63c1ba4f2b7 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm | |||
| @@ -674,17 +674,21 @@ recursively." | |||
| 674 | 674 | ||
| 675 | (define input->output-paths | 675 | (define input->output-paths |
| 676 | (match-lambda | 676 | (match-lambda |
| 677 | ((drv) | 677 | (((? derivation? drv)) |
| 678 | (list (derivation->output-path drv))) | 678 | (list (derivation->output-path drv))) |
| 679 | ((drv sub-drvs ...) | 679 | (((? derivation? drv) sub-drvs ...) |
| 680 | (map (cut derivation->output-path drv <>) | 680 | (map (cut derivation->output-path drv <>) |
| 681 | sub-drvs)))) | 681 | sub-drvs)) |
| 682 | ((file) | ||
| 683 | (list file)))) | ||
| 682 | 684 | ||
| 683 | (let ((mapping (fold (lambda (pair result) | 685 | (let ((mapping (fold (lambda (pair result) |
| 684 | (match pair | 686 | (match pair |
| 685 | ((orig . replacement) | 687 | (((? derivation? orig) . replacement) |
| 686 | (vhash-cons (derivation-file-name orig) | 688 | (vhash-cons (derivation-file-name orig) |
| 687 | replacement result)))) | 689 | replacement result)) |
| 690 | ((file . replacement) | ||
| 691 | (vhash-cons file replacement result)))) | ||
| 688 | vlist-null | 692 | vlist-null |
| 689 | mapping))) | 693 | mapping))) |
| 690 | (define rewritten-input | 694 | (define rewritten-input |
| @@ -695,8 +699,10 @@ recursively." | |||
| 695 | (match input | 699 | (match input |
| 696 | (($ <derivation-input> path (sub-drvs ...)) | 700 | (($ <derivation-input> path (sub-drvs ...)) |
| 697 | (match (vhash-assoc path mapping) | 701 | (match (vhash-assoc path mapping) |
| 698 | ((_ . replacement) | 702 | ((_ . (? derivation? replacement)) |
| 699 | (cons replacement sub-drvs)) | 703 | (cons replacement sub-drvs)) |
| 704 | ((_ . replacement) | ||
| 705 | (list replacement)) | ||
| 700 | (#f | 706 | (#f |
| 701 | (let* ((drv (loop (call-with-input-file path read-derivation)))) | 707 | (let* ((drv (loop (call-with-input-file path read-derivation)))) |
| 702 | (cons drv sub-drvs))))))))) | 708 | (cons drv sub-drvs))))))))) |
| @@ -711,7 +717,13 @@ recursively." | |||
| 711 | ;; Sources typically refer to the output directories of the | 717 | ;; Sources typically refer to the output directories of the |
| 712 | ;; original inputs, INITIAL. Rewrite them by substituting | 718 | ;; original inputs, INITIAL. Rewrite them by substituting |
| 713 | ;; REPLACEMENTS. | 719 | ;; REPLACEMENTS. |
| 714 | (sources (map (cut substitute-file <> initial replacements) | 720 | (sources (map (lambda (source) |
| 721 | (match (vhash-assoc source mapping) | ||
| 722 | ((_ . replacement) | ||
| 723 | replacement) | ||
| 724 | (#f | ||
| 725 | (substitute-file source | ||
| 726 | initial replacements)))) | ||
| 715 | (derivation-sources drv))) | 727 | (derivation-sources drv))) |
| 716 | 728 | ||
| 717 | ;; Now augment the lists of initials and replacements. | 729 | ;; Now augment the lists of initials and replacements. |
diff --git a/tests/derivations.scm b/tests/derivations.scm index 09cf81972c9..a4e073bf07c 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm | |||
| @@ -720,6 +720,28 @@ Deriver: ~a~%" | |||
| 720 | (and (build-derivations %store (list (pk 'remapped drv4))) | 720 | (and (build-derivations %store (list (pk 'remapped drv4))) |
| 721 | (call-with-input-file out get-string-all)))) | 721 | (call-with-input-file out get-string-all)))) |
| 722 | 722 | ||
| 723 | (test-equal "map-derivation, sources" | ||
| 724 | "hello" | ||
| 725 | (let* ((script1 (add-text-to-store %store "fail.sh" "exit 1")) | ||
| 726 | (script2 (add-text-to-store %store "hi.sh" "echo -n hello > $out")) | ||
| 727 | (bash-full (package-derivation %store (@ (gnu packages bash) bash))) | ||
| 728 | (drv1 (derivation %store "drv-to-remap" | ||
| 729 | |||
| 730 | ;; XXX: This wouldn't work in practice, but if | ||
| 731 | ;; we append "/bin/bash" then we can't replace | ||
| 732 | ;; it with the bootstrap bash, which is a | ||
| 733 | ;; single file. | ||
| 734 | (derivation->output-path bash-full) | ||
| 735 | |||
| 736 | `("-e" ,script1) | ||
| 737 | #:inputs `((,bash-full) (,script1)))) | ||
| 738 | (drv2 (map-derivation %store drv1 | ||
| 739 | `((,bash-full . ,%bash) | ||
| 740 | (,script1 . ,script2)))) | ||
| 741 | (out (derivation->output-path drv2))) | ||
| 742 | (and (build-derivations %store (list (pk 'remapped* drv2))) | ||
| 743 | (call-with-input-file out get-string-all)))) | ||
| 744 | |||
| 723 | (test-end) | 745 | (test-end) |
| 724 | 746 | ||
| 725 | 747 | ||
