1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix scripts refresh)
20 #:use-module (guix ui)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix packages)
24 #:use-module (guix gnu-maintenance)
25 #:use-module (gnu packages)
26 #:use-module ((gnu packages base) #:select (%final-inputs))
27 #:use-module (ice-9 match)
28 #:use-module (ice-9 regex)
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-11)
31 #:use-module (srfi srfi-26)
32 #:use-module (srfi srfi-37)
33 #:use-module (rnrs io ports)
34 #:export (guix-refresh))
38 ;;; Command-line options.
41 (define %default-options
42 ;; Alist of default option values.
46 ;; Specification of the command-line options.
47 (list (option '(#\n "dry-run") #f #f
48 (lambda (opt name arg result)
49 (alist-cons 'dry-run? #t result)))
50 (option '(#\s "select") #t #f
51 (lambda (opt name arg result)
53 ((or "core" "non-core")
54 (alist-cons 'select (string->symbol arg)
57 (leave (_ "~a: invalid selection; expected `core' or `non-core'")
60 (option '(#\h "help") #f #f
64 (option '(#\V "version") #f #f
66 (show-version-and-exit "guix refresh")))))
69 (display (_ "Usage: guix refresh [OPTION]... PACKAGE...
70 Update package definitions to match the latest upstream version.
72 When PACKAGE... is given, update only the specified packages. Otherwise
73 update all the packages of the distribution, or the subset thereof
74 specified with `--select'.\n"))
76 -n, --dry-run do not build the derivations"))
78 -s, --select=SUBSET select all the packages in SUBSET, one of
79 `core' or `non-core'"))
82 -h, --help display this help and exit"))
84 -V, --version display version information and exit"))
86 (show-bug-report-information))
93 (define (guix-refresh . args)
94 (define (parse-options)
95 ;; Return the alist of option values.
96 (args-fold* args %options
97 (lambda (opt name arg result)
98 (leave (_ "~A: unrecognized option~%") name))
100 (alist-cons 'argument arg result))
103 (define core-package?
104 (let* ((input->package (match-lambda
105 ((name (? package? package) _ ...) package)
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)
112 (names (delete-duplicates (map package-name core))))
114 "Return true if PACKAGE is likely a \"core package\"---i.e., one whose
115 update 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
120 ;; XXX: Fails to catch MPFR/MPC, whose *source* is used as input.
121 (member (package-name package) names))))
123 (let* ((opts (parse-options))
124 (dry-run? (assoc-ref opts 'dry-run?))
125 (packages (match (concatenate
126 (filter-map (match-lambda
128 (let ((p (find-packages-by-name value)))
130 (leave (_ "~a: no package by that name")
135 (() ; default to all packages
136 (let ((select? (match (assoc-ref opts 'select)
137 ('core core-package?)
138 ('non-core (negate core-package?))
140 ;; TODO: Keep only the newest of each package.
141 (fold-packages (lambda (package result)
142 (if (select? package)
143 (cons package result)
146 (some ; user-specified packages
150 (for-each (lambda (package)
151 (match (false-if-exception (package-update-path package))
152 ((new-version . directory)
153 (let ((loc (or (package-field-location package 'version)
154 (package-location package))))
155 (format (current-error-port)
156 (_ "~a: ~a would be upgraded from ~a to ~a~%")
157 (location->string loc)
158 (package-name package) (package-version package)
162 (let ((store (open-connection)))
163 (for-each (lambda (package)
164 (let-values (((version tarball)
167 (package-update store package))
171 (or (package-field-location package
173 (package-location package))))
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)))))