1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2012, 2013 Nikita Karetnikov <nikita@karetnikov.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix gnu-maintenance)
21 #:use-module (web uri)
22 #:use-module (web client)
23 #:use-module (web response)
24 #:use-module (ice-9 regex)
25 #:use-module (ice-9 match)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-11)
28 #:use-module (srfi srfi-26)
29 #:use-module (system foreign)
30 #:use-module (guix http-client)
31 #:use-module (guix ftp-client)
32 #:use-module (guix utils)
33 #:use-module (guix memoization)
34 #:use-module (guix records)
35 #:use-module (guix upstream)
36 #:use-module (guix packages)
37 #:export (gnu-package-name
38 gnu-package-mundane-name
39 gnu-package-copyright-holder
44 gnu-package-doc-category
45 gnu-package-doc-summary
46 gnu-package-doc-description
48 gnu-package-download-url
57 gnu-release-archive-types
58 gnu-package-name->name+version
68 ;;; Code for dealing with the maintenance of GNU packages, such as
75 ;;; List of GNU packages.
78 (define %gnumaint-base-url
79 "http://cvs.savannah.gnu.org/viewvc/*checkout*/womb/gnumaint/")
81 (define %package-list-url
83 (string-append %gnumaint-base-url "gnupackages.txt")))
85 (define %package-description-url
86 ;; This file contains package descriptions in recutils format.
87 ;; See <https://lists.gnu.org/archive/html/guix-devel/2013-10/msg00071.html>.
89 (string-append %gnumaint-base-url "pkgblurbs.txt")))
91 (define-record-type* <gnu-package-descriptor>
92 gnu-package-descriptor
93 make-gnu-package-descriptor
95 gnu-package-descriptor?
97 (name gnu-package-name)
98 (mundane-name gnu-package-mundane-name)
99 (copyright-holder gnu-package-copyright-holder)
100 (savannah gnu-package-savannah)
101 (fsd gnu-package-fsd)
102 (language gnu-package-language) ; list of strings
103 (logo gnu-package-logo)
104 (doc-category gnu-package-doc-category)
105 (doc-summary gnu-package-doc-summary)
106 (doc-description gnu-package-doc-description) ; taken from 'pkgdescr.txt'
107 (doc-urls gnu-package-doc-urls) ; list of strings
108 (download-url gnu-package-download-url))
110 (define* (official-gnu-packages
111 #:optional (fetch http-fetch/cached))
112 "Return a list of records, which are GNU packages. Use FETCH,
113 to fetch the list of GNU packages over HTTP."
114 (define (read-records port)
115 ;; Return a list of alists. Each alist contains fields of a GNU
117 (let loop ((alist (recutils->alist port))
121 (loop (recutils->alist port)
122 (cons alist result)))))
124 (define official-description
125 (let ((db (read-records (fetch %package-description-url #:text? #t))))
127 ;; Return the description found upstream for package NAME, or #f.
128 (and=> (find (lambda (alist)
129 (equal? name (assoc-ref alist "package")))
132 (let ((field (assoc-ref record "blurb")))
133 ;; The upstream description file uses "redirect PACKAGE" as
134 ;; a blurb in cases where the description of the two
135 ;; packages should be considered the same (e.g., GTK+ has
136 ;; "redirect gnome".) This is usually not acceptable for
137 ;; us because we prefer to have distinct descriptions in
138 ;; such cases. Thus, ignore the 'blurb' field when that
141 (not (string-prefix? "redirect " field))
145 (let ((name (assoc-ref alist "package")))
146 (alist->record `(("description" . ,(official-description name))
148 make-gnu-package-descriptor
149 (list "package" "mundane-name" "copyright-holder"
150 "savannah" "fsd" "language" "logo"
151 "doc-category" "doc-summary" "description"
154 '("doc-url" "language"))))
155 (let* ((port (fetch %package-list-url #:text? #t))
156 (lst (read-records port)))
160 (define (find-package name)
161 "Find GNU package called NAME and return it. Return #f if it was not
163 (find (lambda (package)
164 (string=? name (gnu-package-name package)))
165 (official-gnu-packages)))
168 (let ((official-gnu-packages (memoize official-gnu-packages)))
170 "Return true if PACKAGE is a GNU package. This procedure may access the
171 network to check in GNU's database."
172 (define (mirror-type url)
173 (let ((uri (string->uri url)))
174 (and (eq? (uri-scheme uri) 'mirror)
176 ((member (uri-host uri)
177 '("gnu" "gnupg" "gcc" "gnome"))
180 ((equal? (uri-host uri) "cran")
181 ;; Possibly GNU: mirror://cran could be either GNU R itself
182 ;; or a non-GNU package.
185 ;; Definitely non-GNU.
188 (define (gnu-home-page? package)
189 (letrec-syntax ((>> (syntax-rules ()
192 ((_ value proc rest ...)
195 (>> (proc next) rest ...)))))))
196 (>> package package-home-page
199 (member host '("www.gnu.org" "gnu.org"))))))
201 (or (gnu-home-page? package)
202 (let ((url (and=> (package-source package) origin-uri))
203 (name (package-upstream-name package)))
204 (case (and (string? url) (mirror-type url))
208 (and (member name (map gnu-package-name (official-gnu-packages)))
216 (define (ftp-server/directory package)
217 "Return the FTP server and directory where PACKAGE's tarball are stored."
218 (let ((name (package-upstream-name package)))
219 (values (or (assoc-ref (package-properties package) 'ftp-server)
221 (or (assoc-ref (package-properties package) 'ftp-directory)
222 (string-append "/gnu/" name)))))
224 (define (sans-extension tarball)
225 "Return TARBALL without its .tar.* or .zip extension."
226 (let ((end (or (string-contains tarball ".tar")
227 (string-contains tarball ".zip"))))
228 (substring tarball 0 end)))
231 ;; The .zip extensions is notably used for freefont-ttf.
232 ;; The "-src" pattern is for "TeXmacs-1.0.7.9-src.tar.gz".
233 ;; The "-gnu[0-9]" pattern is for "icecat-38.4.0-gnu1.tar.bz2".
234 (make-regexp "^([^.]+)-([0-9]|[^-])+(-(src|gnu[0-9]))?\\.(tar\\.|zip$)"))
236 (define %alpha-tarball-rx
237 (make-regexp "^.*-.*[0-9](-|~)?(alpha|beta|rc|cvs|svn|git)-?[0-9\\.]*\\.tar\\."))
239 (define (release-file? project file)
240 "Return #f if FILE is not a release tarball of PROJECT, otherwise return
242 (and (not (string-suffix? ".sig" file))
243 (and=> (regexp-exec %tarball-rx file)
245 ;; Filter out unrelated files, like `guile-www-1.1.1'.
246 ;; Case-insensitive for things like "TeXmacs" vs. "texmacs".
247 ;; The "-src" suffix is for "freefont-src-20120503.tar.gz".
248 (and=> (match:substring match 1)
250 (or (string-ci=? name project)
252 (string-append project
254 (not (regexp-exec %alpha-tarball-rx file))
255 (let ((s (sans-extension file)))
256 (regexp-exec %package-name-rx s))))
258 (define (tarball->version tarball)
259 "Return the version TARBALL corresponds to. TARBALL is a file name like
260 \"coreutils-8.23.tar.xz\"."
261 (let-values (((name version)
262 (gnu-package-name->name+version (sans-extension tarball))))
265 (define* (releases project
267 (server "ftp.gnu.org")
268 (directory (string-append "/gnu/" project)))
269 "Return the list of <upstream-release> of PROJECT as a list of release
270 name/directory pairs."
271 ;; TODO: Parse something like fencepost.gnu.org:/gd/gnuorg/packages-ftp.
272 (define conn (ftp-open server))
274 (let loop ((directories (list directory))
279 (coalesce-sources result))
280 ((directory rest ...)
281 (let* ((files (ftp-list conn directory))
282 (subdirs (filter-map (match-lambda
283 ((name 'directory . _) name)
286 (define (file->url file)
287 (string-append "ftp://" server directory "/" file))
289 (define (file->source file)
290 (let ((url (file->url file)))
293 (version (tarball->version file))
295 (signature-urls (list (string-append url ".sig"))))))
297 (loop (append (map (cut string-append directory "/" <>)
301 ;; Filter out signatures, deltas, and files which
302 ;; are potentially not releases of PROJECT--e.g.,
303 ;; in /gnu/guile, filter out guile-oops and
304 ;; guile-www; in mit-scheme, filter out binaries.
305 (filter-map (match-lambda
307 (and (release-file? project file)
308 (file->source file)))
313 (define* (latest-ftp-release project
315 (server "ftp.gnu.org")
316 (directory (string-append "/gnu/" project))
317 (keep-file? (const #t))
318 (file->signature (cut string-append <> ".sig"))
319 (ftp-open ftp-open) (ftp-close ftp-close))
320 "Return an <upstream-source> for the latest release of PROJECT on SERVER
321 under DIRECTORY, or #f. Use FTP-OPEN and FTP-CLOSE to open (resp. close) FTP
322 connections; this can be useful to reuse connections.
324 KEEP-FILE? is a predicate to decide whether to enter a directory and to
325 consider a given file (source tarball) as a valid candidate based on its name.
327 FILE->SIGNATURE must be a procedure; it is passed a source file URL and must
328 return the corresponding signature URL, or #f it signatures are unavailable."
330 (if (version>? a b) a b))
332 (define (latest-release a b)
333 (if (version>? (upstream-source-version a) (upstream-source-version b))
336 (define contains-digit?
337 (cut string-any char-set:digit <>))
339 (define patch-directory-name?
340 ;; Return #t for patch directory names such as 'bash-4.2-patches'.
341 (cut string-suffix? "patches" <>))
343 (define conn (ftp-open server))
345 (define (file->url directory file)
346 (string-append "ftp://" server directory "/" file))
348 (define (file->source directory file)
349 (let ((url (file->url directory file)))
352 (version (tarball->version file))
354 (signature-urls (match (file->signature url)
356 (sig (list sig)))))))
358 (let loop ((directory directory)
360 (let* ((entries (ftp-list conn directory))
362 ;; Filter out sub-directories that do not contain digits---e.g.,
363 ;; /gnuzilla/lang and /gnupg/patches. Filter out "w32"
364 ;; directories as found on ftp.gnutls.org.
365 (subdirs (filter-map (match-lambda
366 (((? patch-directory-name? dir)
369 (("w32" 'directory . _)
371 (((? contains-digit? dir) 'directory . _)
372 (and (keep-file? dir) dir))
376 ;; Whether or not SUBDIRS is empty, compute the latest releases
377 ;; for the current directory. This is necessary for packages
378 ;; such as 'sharutils' that have a sub-directory that contains
379 ;; only an older release.
380 (releases (filter-map (match-lambda
382 (and (release-file? project file)
384 (file->source directory file)))
388 ;; Assume that SUBDIRS correspond to versions, and jump into the
389 ;; one with the highest version number.
390 (let* ((release (reduce latest-release #f
391 (coalesce-sources releases)))
392 (result (if (and result release)
393 (latest-release release result)
394 (or release result)))
395 (target (reduce latest #f subdirs)))
397 (loop (string-append directory "/" target)
403 (define* (latest-release package
405 (server "ftp.gnu.org")
406 (directory (string-append "/gnu/" package)))
407 "Return the <upstream-source> for the latest version of PACKAGE or #f.
408 PACKAGE must be the canonical name of a GNU package."
409 (latest-ftp-release package
411 #:directory directory))
413 (define-syntax-rule (false-if-ftp-error exp)
414 "Return #f if an FTP error is raise while evaluating EXP; return the result
419 (lambda (key port . rest)
420 (if (ftp-connection? port)
425 (define (latest-release* package)
426 "Like 'latest-release', but (1) take a <package> object, and (2) ignore FTP
427 errors that might occur when PACKAGE is not actually a GNU package, or not
428 hosted on ftp.gnu.org, or not under that name (this is the case for
429 \"emacs-auctex\", for instance.)"
430 (let-values (((server directory)
431 (ftp-server/directory package)))
432 (false-if-ftp-error (latest-release (package-upstream-name package)
434 #:directory directory))))
436 (define %package-name-rx
437 ;; Regexp for a package name, e.g., "foo-X.Y". Since TeXmacs uses
438 ;; "TeXmacs-X.Y-src", the `-src' suffix is allowed.
439 (make-regexp "^(.*)-(([0-9]|\\.)+)(-src)?"))
441 (define (gnu-package-name->name+version name+version)
442 "Return the package name and version number extracted from NAME+VERSION."
443 (let ((match (regexp-exec %package-name-rx name+version)))
445 (values name+version #f)
446 (values (match:substring match 1) (match:substring match 2)))))
448 (define (pure-gnu-package? package)
449 "Return true if PACKAGE is a non-Emacs and non-GNOME GNU package. This
450 excludes AucTeX, for instance, whose releases are now uploaded to
451 elpa.gnu.org, and all the GNOME packages; EMMS is included though, because its
452 releases are on gnu.org."
453 (and (or (not (string-prefix? "emacs-" (package-name package)))
454 (gnu-hosted? package))
455 (not (gnome-package? package))
456 (gnu-package? package)))
458 (define (url-prefix-predicate prefix)
459 "Return a predicate that returns true when passed a package where one of its
460 source URLs starts with PREFIX."
462 (define matching-uri?
465 (string-prefix? prefix uri))
469 (match (package-source package)
471 (match (origin-uri origin)
472 ((? matching-uri?) #t)
477 (url-prefix-predicate "mirror://gnu/"))
479 (define gnome-package?
480 (url-prefix-predicate "mirror://gnome/"))
482 (define (latest-gnome-release package)
483 "Return the latest release of PACKAGE, the name of a GNOME package."
485 (char-set-complement (char-set #\.)))
487 (define (even-minor-version? version)
488 (match (string-tokenize version %not-dot)
489 (((= string->number major) (= string->number minor) . rest)
490 (and minor (even? minor)))
494 (define (even-numbered? file)
495 ;; Return true if FILE somehow denotes an even-numbered file name. The
496 ;; trick here is that we want this to match both directories such as
497 ;; "3.18.6" and actual file names such as "gtk+-3.18.6.tar.bz2".
498 (let-values (((name version) (package-name->name+version file)))
499 (even-minor-version? (or version name))))
501 (define upstream-name
502 ;; Some packages like "NetworkManager" have camel-case names.
503 (package-upstream-name package))
506 (latest-ftp-release upstream-name
507 #:server "ftp.gnome.org"
508 #:directory (string-append "/pub/gnome/sources/"
512 ;; <https://www.gnome.org/gnome-3/source/> explains
513 ;; that odd minor version numbers represent development
514 ;; releases, which we are usually not interested in.
515 #:keep-file? even-numbered?
517 ;; ftp.gnome.org provides no signatures, only
519 #:file->signature (const #f))))
522 (define (latest-kde-release package)
523 "Return the latest release of PACKAGE, the name of an KDE.org package."
524 (let ((uri (string->uri (origin-uri (package-source package)))))
527 (package-upstream-name package)
528 #:server "mirrors.mit.edu"
530 (string-append "/kde" (dirname (dirname (uri-path uri))))
531 #:file->signature (const #f)))))
533 (define (latest-xorg-release package)
534 "Return the latest release of PACKAGE, the name of an X.org package."
535 (let ((uri (string->uri (origin-uri (package-source package)))))
538 (package-name package)
539 #:server "ftp.freedesktop.org"
541 (string-append "/pub/xorg/" (dirname (uri-path uri)))))))
543 (define (latest-kernel.org-release package)
544 "Return the latest release of PACKAGE, the name of a kernel.org package."
545 (let ((uri (string->uri (origin-uri (package-source package)))))
548 (package-name package)
549 #:server "ftp.free.fr" ;a mirror reachable over FTP
550 #:directory (string-append "/mirrors/ftp.kernel.org"
551 (dirname (uri-path uri)))
553 ;; kernel.org provides "foo-x.y.tar.sign" files, which are signatures of
554 ;; the uncompressed tarball.
555 #:file->signature (lambda (tarball)
556 (string-append (file-sans-extension tarball)
562 (description "Updater for GNU packages")
563 (pred pure-gnu-package?)
564 (latest latest-release*)))
566 (define %gnome-updater
569 (description "Updater for GNOME packages")
570 (pred gnome-package?)
571 (latest latest-gnome-release)))
576 (description "Updater for KDE packages")
577 (pred (url-prefix-predicate "mirror://kde/"))
578 (latest latest-kde-release)))
580 (define %xorg-updater
583 (description "Updater for X.org packages")
584 (pred (url-prefix-predicate "mirror://xorg/"))
585 (latest latest-xorg-release)))
587 (define %kernel.org-updater
590 (description "Updater for packages hosted on kernel.org")
591 (pred (url-prefix-predicate "mirror://kernel.org/"))
592 (latest latest-kernel.org-release)))
594 ;;; gnu-maintenance.scm ends here