summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-04-25 22:56:25 +0200
committerLudovic Courtès <ludo@gnu.org>2013-04-25 22:56:25 +0200
commit37a5340262fd916b2c7b8d175282987a6d4449bb (patch)
tree94d922f39dc63f04d1d77c2e0f3d981773e30e5b
parent1c9e7d65d4ca8674e674b339740f575f8edb5db2 (diff)
refresh: Add `--select'.
* guix/scripts/refresh.scm (%options): Add `--select'. (show-help): Likewise. Augment initial help text. (guix-refresh)[core-package?]: New procedure. Use it when selecting packages.
-rw-r--r--guix/scripts/refresh.scm119
1 files changed, 82 insertions, 37 deletions
diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index 036da38a3f8..da318b07ad9 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -23,6 +23,7 @@
23 #:use-module (guix packages) 23 #:use-module (guix packages)
24 #:use-module (guix gnu-maintenance) 24 #:use-module (guix gnu-maintenance)
25 #:use-module (gnu packages) 25 #:use-module (gnu packages)
26 #:use-module ((gnu packages base) #:select (%final-inputs))
26 #:use-module (ice-9 match) 27 #:use-module (ice-9 match)
27 #:use-module (ice-9 regex) 28 #:use-module (ice-9 regex)
28 #:use-module (srfi srfi-1) 29 #:use-module (srfi srfi-1)
@@ -46,6 +47,15 @@
46 (list (option '(#\n "dry-run") #f #f 47 (list (option '(#\n "dry-run") #f #f
47 (lambda (opt name arg result) 48 (lambda (opt name arg result)
48 (alist-cons 'dry-run? #t result))) 49 (alist-cons 'dry-run? #t result)))
50 (option '(#\s "select") #t #f
51 (lambda (opt name arg result)
52 (match arg
53 ((or "core" "non-core")
54 (alist-cons 'select (string->symbol arg)
55 result))
56 (x
57 (leave (_ "~a: invalid selection; expected `core' or `non-core'")
58 arg)))))
49 59
50 (option '(#\h "help") #f #f 60 (option '(#\h "help") #f #f
51 (lambda args 61 (lambda args
@@ -57,9 +67,16 @@
57 67
58(define (show-help) 68(define (show-help)
59 (display (_ "Usage: guix refresh [OPTION]... PACKAGE... 69 (display (_ "Usage: guix refresh [OPTION]... PACKAGE...
60Update package definitions to match the latest upstream version.\n")) 70Update package definitions to match the latest upstream version.
71
72When PACKAGE... is given, update only the specified packages. Otherwise
73update all the packages of the distribution, or the subset thereof
74specified with `--select'.\n"))
61 (display (_ " 75 (display (_ "
62 -n, --dry-run do not build the derivations")) 76 -n, --dry-run do not build the derivations"))
77 (display (_ "
78 -s, --select=SUBSET select all the packages in SUBSET, one of
79 `core' or `non-core'"))
63 (newline) 80 (newline)
64 (display (_ " 81 (display (_ "
65 -h, --help display this help and exit")) 82 -h, --help display this help and exit"))
@@ -83,6 +100,26 @@ Update package definitions to match the latest upstream version.\n"))
83 (alist-cons 'argument arg result)) 100 (alist-cons 'argument arg result))
84 %default-options)) 101 %default-options))
85 102
103 (define core-package?
104 (let* ((input->package (match-lambda
105 ((name (? package? package) _ ...) package)
106 (_ #f)))
107 (final-inputs (map input->package %final-inputs))
108 (core (append final-inputs
109 (append-map (compose (cut filter-map input->package <>)
110 package-transitive-inputs)
111 final-inputs)))
112 (names (delete-duplicates (map package-name core))))
113 (lambda (package)
114 "Return true if PACKAGE is likely a \"core package\"---i.e., one whose
115update would trigger a complete rebuild."
116 ;; Compare by name because packages in base.scm basically inherit
117 ;; other packages. So, even if those packages are not core packages
118 ;; themselves, updating them would also update those who inherit from
119 ;; them.
120 ;; XXX: Fails to catch MPFR/MPC, whose *source* is used as input.
121 (member (package-name package) names))))
122
86 (let* ((opts (parse-options)) 123 (let* ((opts (parse-options))
87 (dry-run? (assoc-ref opts 'dry-run?)) 124 (dry-run? (assoc-ref opts 'dry-run?))
88 (packages (match (concatenate 125 (packages (match (concatenate
@@ -96,42 +133,50 @@ Update package definitions to match the latest upstream version.\n"))
96 (_ #f)) 133 (_ #f))
97 opts)) 134 opts))
98 (() ; default to all packages 135 (() ; default to all packages
99 ;; TODO: Keep only the newest of each package. 136 (let ((select? (match (assoc-ref opts 'select)
100 (fold-packages cons '())) 137 ('core core-package?)
138 ('non-core (negate core-package?))
139 (_ (const #t)))))
140 ;; TODO: Keep only the newest of each package.
141 (fold-packages (lambda (package result)
142 (if (select? package)
143 (cons package result)
144 result))
145 '())))
101 (some ; user-specified packages 146 (some ; user-specified packages
102 some)))) 147 some))))
103 (with-error-handling 148 (with-error-handling
104 (if dry-run? 149 (if dry-run?
105 (for-each (lambda (package) 150 (for-each (lambda (package)
106 (match (false-if-exception (package-update-path package)) 151 (match (false-if-exception (package-update-path package))
107 ((new-version . directory) 152 ((new-version . directory)
108 (let ((loc (or (package-field-location package 'version) 153 (let ((loc (or (package-field-location package 'version)
109 (package-location package)))) 154 (package-location package))))
110 (format (current-error-port)
111 (_ "~a: ~a would be upgraded from ~a to ~a~%")
112 (location->string loc)
113 (package-name package) (package-version package)
114 new-version)))
115 (_ #f)))
116 packages)
117 (let ((store (open-connection)))
118 (for-each (lambda (package)
119 (let-values (((version tarball)
120 (catch #t
121 (lambda ()
122 (package-update store package))
123 (lambda _
124 (values #f #f))))
125 ((loc)
126 (or (package-field-location package
127 'version)
128 (package-location package))))
129 (when version
130 (format (current-error-port) 155 (format (current-error-port)
131 (_ "~a: ~a: updating from version ~a to version ~a...~%") 156 (_ "~a: ~a would be upgraded from ~a to ~a~%")
132 (location->string loc) (package-name package) 157 (location->string loc)
133 (package-version package) version) 158 (package-name package) (package-version package)
134 (let ((hash (call-with-input-file tarball 159 new-version)))
135 (compose sha256 get-bytevector-all)))) 160 (_ #f)))
136 (update-package-source package version hash))))) 161 packages)
137 packages)))))) 162 (let ((store (open-connection)))
163 (for-each (lambda (package)
164 (let-values (((version tarball)
165 (catch #t
166 (lambda ()
167 (package-update store package))
168 (lambda _
169 (values #f #f))))
170 ((loc)
171 (or (package-field-location package
172 'version)
173 (package-location package))))
174 (when version
175 (format (current-error-port)
176 (_ "~a: ~a: updating from version ~a to version ~a...~%")
177 (location->string loc) (package-name package)
178 (package-version package) version)
179 (let ((hash (call-with-input-file tarball
180 (compose sha256 get-bytevector-all))))
181 (update-package-source package version hash)))))
182 packages))))))