[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08/09: guix package: Refactor 'options->installable'.
From: |
Ludovic Courtès |
Subject: |
08/09: guix package: Refactor 'options->installable'. |
Date: |
Mon, 30 Nov 2015 22:20:49 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit 27b91d7851859c1c82e891fafc4a326b71fbf88d
Author: Ludovic Courtès <address@hidden>
Date: Mon Nov 30 22:00:39 2015 +0200
guix package: Refactor 'options->installable'.
* guix/scripts/package.scm (options->upgrade-predicate)
(store-item->manifest-entry): New procedures.
* guix/scripts/package.scm (options->installable): Use them. Remove the
'packages-to-upgrade' and 'packages-to-install' variables by getting rid
of a level of indirection.
---
guix/scripts/package.scm | 119 +++++++++++++++++++++-------------------------
1 files changed, 54 insertions(+), 65 deletions(-)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 5f65ed9..c62daee 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -510,87 +510,76 @@ kind of search path~%")
%standard-build-options))
-(define (options->installable opts manifest)
- "Given MANIFEST, the current manifest, and OPTS, the result of 'args-fold',
-return the new list of manifest entries."
- (define (package->manifest-entry* package output)
- (check-package-freshness package)
- ;; When given a package via `-e', install the first of its
- ;; outputs (XXX).
- (package->manifest-entry package output))
-
+(define (options->upgrade-predicate opts)
+ "Return a predicate based on the upgrade/do-not-upgrade regexps in OPTS
+that, given a package name, returns true if the package is a candidate for
+upgrading, #f otherwise."
(define upgrade-regexps
(filter-map (match-lambda
- (('upgrade . regexp)
- (make-regexp* (or regexp "")))
- (_ #f))
+ (('upgrade . regexp)
+ (make-regexp* (or regexp "")))
+ (_ #f))
opts))
(define do-not-upgrade-regexps
(filter-map (match-lambda
- (('do-not-upgrade . regexp)
- (make-regexp* regexp))
- (_ #f))
+ (('do-not-upgrade . regexp)
+ (make-regexp* regexp))
+ (_ #f))
opts))
- (define packages-to-upgrade
- (match upgrade-regexps
- (()
- '())
- ((_ ...)
- (filter-map (match-lambda
- (($ <manifest-entry> name version output path _)
- (and (any (cut regexp-exec <> name)
- upgrade-regexps)
- (not (any (cut regexp-exec <> name)
- do-not-upgrade-regexps))
- (upgradeable? name version path)
- (let ((output (or output "out")))
- (call-with-values
- (lambda ()
- (specification->package+output name output))
- list))))
- (_ #f))
- (manifest-entries manifest)))))
+ (lambda (name)
+ (and (any (cut regexp-exec <> name) upgrade-regexps)
+ (not (any (cut regexp-exec <> name) do-not-upgrade-regexps)))))
+
+(define (store-item->manifest-entry item)
+ "Return a manifest entry for ITEM, a \"/gnu/store/...\" file name."
+ (let-values (((name version)
+ (package-name->name+version (store-path-package-name item))))
+ (manifest-entry
+ (name name)
+ (version version)
+ (output #f)
+ (item item))))
+
+(define (options->installable opts manifest)
+ "Given MANIFEST, the current manifest, and OPTS, the result of 'args-fold',
+return the new list of manifest entries."
+ (define (package->manifest-entry* package output)
+ (check-package-freshness package)
+ (package->manifest-entry package output))
+
+ (define upgrade?
+ (options->upgrade-predicate opts))
(define to-upgrade
- (map (match-lambda
- ((package output)
- (package->manifest-entry* package output)))
- packages-to-upgrade))
+ (filter-map (match-lambda
+ (($ <manifest-entry> name version output path _)
+ (and (upgrade? name)
+ (upgradeable? name version path)
+ (let ((output (or output "out")))
+ (call-with-values
+ (lambda ()
+ (specification->package+output name output))
+ package->manifest-entry*))))
+ (_ #f))
+ (manifest-entries manifest)))
- (define packages-to-install
+ (define to-install
(filter-map (match-lambda
- (('install . (? package? p))
- (list p "out"))
- (('install . (? string? spec))
- (and (not (store-path? spec))
+ (('install . (? package? p))
+ ;; When given a package via `-e', install the first of its
+ ;; outputs (XXX).
+ (package->manifest-entry* p "out"))
+ (('install . (? string? spec))
+ (if (store-path? spec)
+ (store-item->manifest-entry spec)
(let-values (((package output)
(specification->package+output spec)))
- (and package (list package output)))))
- (_ #f))
+ (package->manifest-entry* package output))))
+ (_ #f))
opts))
- (define to-install
- (append (map (match-lambda
- ((package output)
- (package->manifest-entry* package output)))
- packages-to-install)
- (filter-map (match-lambda
- (('install . (? package?))
- #f)
- (('install . (? store-path? path))
- (let-values (((name version)
- (package-name->name+version
- (store-path-package-name path))))
- (manifest-entry
- (name name)
- (version version)
- (output #f)
- (item path))))
- (_ #f))
- opts)))
-
(append to-upgrade to-install))
(define (options->removable options manifest)
- branch master updated (ccd20fc -> 64ec0e2), Ludovic Courtès, 2015/11/30
- 01/09: guix package: Remove unnecessary use of (%store)., Ludovic Courtès, 2015/11/30
- 07/09: guix package: Move 'process-actions' out of sight., Ludovic Courtès, 2015/11/30
- 03/09: guix package: Move 'build-and-use-profile' out of sight., Ludovic Courtès, 2015/11/30
- 06/09: build: Fix detection of ARM systems., Ludovic Courtès, 2015/11/30
- 02/09: guix package: Move a couple of procedures out of sight., Ludovic Courtès, 2015/11/30
- 05/09: guix package: Formalize the list of actions., Ludovic Courtès, 2015/11/30
- 08/09: guix package: Refactor 'options->installable'.,
Ludovic Courtès <=
- 09/09: guix build: Modularize transformation handling., Ludovic Courtès, 2015/11/30
- 04/09: nls: Update 'de' translation., Ludovic Courtès, 2015/11/30