summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-09-06 22:28:12 +0200
committerLudovic Courtès <ludo@gnu.org>2016-09-06 23:22:10 +0200
commit5239f3d90841de767c86d0f3a7975b8d799d583d (patch)
tree0b785fe2d906e867bf25002d82ce2d0f89c24504
parentc8c25704aeb2e5fa4feb6a86235f9565738eea99 (diff)
guix package: Build up the transaction incrementally.
* guix/scripts/package.scm (upgraded-manifest-entry): Rename to... (transaction-upgrade-entry): ... this. Add 'transaction' parameter and return a transaction. (options->installable): Likewise. [to-upgrade]: Rename to... [upgraded]: ... this, and change to be a transaction. Return a transaction. (options->removable): Likewise. (process-actions): Adjust accordingly. * tests/packages.scm ("transaction-upgrade-entry, zero upgrades") ("transaction-upgrade-entry, one upgrade"): New tests.
-rw-r--r--guix/scripts/package.scm100
-rw-r--r--tests/packages.scm29
2 files changed, 87 insertions, 42 deletions
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 14a0895b438..dc5fcba9221 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -261,25 +261,30 @@ synopsis or description matches all of REGEXPS."
261 ((<) #t) 261 ((<) #t)
262 (else #f))))) 262 (else #f)))))
263 263
264(define (upgraded-manifest-entry entry) 264(define (transaction-upgrade-entry entry transaction)
265 "Return either a <manifest-entry> corresponding to an upgrade of ENTRY, or 265 "Return a variant of TRANSACTION that accounts for the upgrade of ENTRY, a
266#f if no upgrade was found." 266<manifest-entry>."
267 (match entry 267 (match entry
268 (($ <manifest-entry> name version output (? string? path)) 268 (($ <manifest-entry> name version output (? string? path))
269 (match (vhash-assoc name (find-newest-available-packages)) 269 (match (vhash-assoc name (find-newest-available-packages))
270 ((_ candidate-version pkg . rest) 270 ((_ candidate-version pkg . rest)
271 (case (version-compare candidate-version version) 271 (case (version-compare candidate-version version)
272 ((>) 272 ((>)
273 (package->manifest-entry pkg output)) 273 (manifest-transaction-install-entry
274 (package->manifest-entry pkg output)
275 transaction))
274 ((<) 276 ((<)
275 #f) 277 transaction)
276 ((=) 278 ((=)
277 (let ((candidate-path (derivation->output-path 279 (let ((candidate-path (derivation->output-path
278 (package-derivation (%store) pkg)))) 280 (package-derivation (%store) pkg))))
279 (and (not (string=? path candidate-path)) 281 (if (string=? path candidate-path)
280 (package->manifest-entry pkg output)))))) 282 transaction
283 (manifest-transaction-install-entry
284 (package->manifest-entry pkg output)
285 transaction))))))
281 (#f 286 (#f
282 #f))))) 287 transaction)))))
283 288
284 289
285;;; 290;;;
@@ -559,17 +564,20 @@ upgrading, #f otherwise."
559 (output #f) 564 (output #f)
560 (item item)))) 565 (item item))))
561 566
562(define (options->installable opts manifest) 567(define (options->installable opts manifest transaction)
563 "Given MANIFEST, the current manifest, and OPTS, the result of 'args-fold', 568 "Given MANIFEST, the current manifest, and OPTS, the result of 'args-fold',
564return the new list of manifest entries." 569return an variant of TRANSACTION that accounts for the specified installations
570and upgrades."
565 (define upgrade? 571 (define upgrade?
566 (options->upgrade-predicate opts)) 572 (options->upgrade-predicate opts))
567 573
568 (define to-upgrade 574 (define upgraded
569 (filter-map (lambda (entry) 575 (fold (lambda (entry transaction)
570 (and (upgrade? (manifest-entry-name entry)) 576 (if (upgrade? (manifest-entry-name entry))
571 (upgraded-manifest-entry entry))) 577 (transaction-upgrade-entry entry transaction)
572 (manifest-entries manifest))) 578 transaction))
579 transaction
580 (manifest-entries manifest)))
573 581
574 (define to-install 582 (define to-install
575 (filter-map (match-lambda 583 (filter-map (match-lambda
@@ -586,23 +594,29 @@ return the new list of manifest entries."
586 (_ #f)) 594 (_ #f))
587 opts)) 595 opts))
588 596
589 (append to-upgrade to-install)) 597 (fold manifest-transaction-install-entry
590 598 upgraded
591(define (options->removable options manifest) 599 to-install))
592 "Given options, return the list of manifest patterns of packages to be 600
593removed from MANIFEST." 601(define (options->removable options manifest transaction)
594 (filter-map (match-lambda 602 "Given options, return a variant of TRANSACTION augmented with the list of
595 (('remove . spec) 603patterns of packages to remove."
596 (call-with-values 604 (fold (lambda (opt transaction)
597 (lambda () 605 (match opt
598 (package-specification->name+version+output spec)) 606 (('remove . spec)
599 (lambda (name version output) 607 (call-with-values
600 (manifest-pattern 608 (lambda ()
601 (name name) 609 (package-specification->name+version+output spec))
602 (version version) 610 (lambda (name version output)
603 (output output))))) 611 (manifest-transaction-remove-pattern
604 (_ #f)) 612 (manifest-pattern
605 options)) 613 (name name)
614 (version version)
615 (output output))
616 transaction))))
617 (_ transaction)))
618 transaction
619 options))
606 620
607(define (register-gc-root store profile) 621(define (register-gc-root store profile)
608 "Register PROFILE, a profile generation symlink, as a GC root, unless it 622 "Register PROFILE, a profile generation symlink, as a GC root, unless it
@@ -813,16 +827,18 @@ processed, #f otherwise."
813 opts) 827 opts)
814 828
815 ;; Then, process normal package installation/removal/upgrade. 829 ;; Then, process normal package installation/removal/upgrade.
816 (let* ((manifest (profile-manifest profile)) 830 (let* ((manifest (profile-manifest profile))
817 (install (options->installable opts manifest)) 831 (step1 (options->installable opts manifest
818 (remove (options->removable opts manifest)) 832 (manifest-transaction)))
819 (transaction (manifest-transaction 833 (step2 (options->removable opts manifest step1))
820 (install (map transform-entry install)) 834 (step3 (manifest-transaction
821 (remove remove))) 835 (inherit step2)
822 (new (manifest-perform-transaction manifest transaction))) 836 (install (map transform-entry
823 837 (manifest-transaction-install step2)))))
824 (unless (and (null? install) (null? remove)) 838 (new (manifest-perform-transaction manifest step3)))
825 (show-manifest-transaction store manifest transaction 839
840 (unless (manifest-transaction-null? step3)
841 (show-manifest-transaction store manifest step3
826 #:dry-run? dry-run?) 842 #:dry-run? dry-run?)
827 (build-and-use-profile store profile new 843 (build-and-use-profile store profile new
828 #:bootstrap? bootstrap? 844 #:bootstrap? bootstrap?
diff --git a/tests/packages.scm b/tests/packages.scm
index daceea5d62a..456e6919625 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -49,6 +49,7 @@
49 #:use-module (srfi srfi-35) 49 #:use-module (srfi srfi-35)
50 #:use-module (srfi srfi-64) 50 #:use-module (srfi srfi-64)
51 #:use-module (rnrs io ports) 51 #:use-module (rnrs io ports)
52 #:use-module (ice-9 vlist)
52 #:use-module (ice-9 regex) 53 #:use-module (ice-9 regex)
53 #:use-module (ice-9 match)) 54 #:use-module (ice-9 match))
54 55
@@ -83,6 +84,34 @@
83 (and (hidden-package? (hidden-package (dummy-package "foo"))) 84 (and (hidden-package? (hidden-package (dummy-package "foo")))
84 (not (hidden-package? (dummy-package "foo"))))) 85 (not (hidden-package? (dummy-package "foo")))))
85 86
87(test-assert "transaction-upgrade-entry, zero upgrades"
88 (let* ((old (dummy-package "foo" (version "1")))
89 (tx (mock ((gnu packages) find-newest-available-packages
90 (const vlist-null))
91 ((@@ (guix scripts package) transaction-upgrade-entry)
92 (manifest-entry
93 (inherit (package->manifest-entry old))
94 (item (string-append (%store-prefix) "/"
95 (make-string 32 #\e) "-foo-1")))
96 (manifest-transaction)))))
97 (manifest-transaction-null? tx)))
98
99(test-assert "transaction-upgrade-entry, one upgrade"
100 (let* ((old (dummy-package "foo" (version "1")))
101 (new (dummy-package "foo" (version "2")))
102 (tx (mock ((gnu packages) find-newest-available-packages
103 (const (vhash-cons "foo" (list "2" new) vlist-null)))
104 ((@@ (guix scripts package) transaction-upgrade-entry)
105 (manifest-entry
106 (inherit (package->manifest-entry old))
107 (item (string-append (%store-prefix) "/"
108 (make-string 32 #\e) "-foo-1")))
109 (manifest-transaction)))))
110 (and (match (manifest-transaction-install tx)
111 ((($ <manifest-entry> "foo" "2" "out" item))
112 (eq? item new)))
113 (null? (manifest-transaction-remove tx)))))
114
86(test-assert "package-field-location" 115(test-assert "package-field-location"
87 (let () 116 (let ()
88 (define (goto port line column) 117 (define (goto port line column)