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 combinators)
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)))
169 (let ((official-gnu-packages (memoize official-gnu-packages)))
171 "Return true if PACKAGE is a GNU package. This procedure may access the
172 network to check in GNU's database."
173 (define (mirror-type url)
174 (let ((uri (string->uri url)))
175 (and (eq? (uri-scheme uri) 'mirror)
177 ((member (uri-host uri)
178 '("gnu" "gnupg" "gcc" "gnome"))
181 ((equal? (uri-host uri) "cran")
182 ;; Possibly GNU: mirror://cran could be either GNU R itself
183 ;; or a non-GNU package.
186 ;; Definitely non-GNU.
189 (define (gnu-home-page? package)
190 (and=> (package-home-page package)
192 (and=> (uri-host (string->uri url))
194 (member host '("www.gnu.org" "gnu.org")))))))
196 (or (gnu-home-page? package)
197 (let ((url (and=> (package-source package) origin-uri))
198 (name (package-name package)))
199 (case (and (string? url) (mirror-type url))
203 (and (member name (map gnu-package-name (official-gnu-packages)))
211 (define (ftp-server/directory package)
212 "Return the FTP server and directory where PACKAGE's tarball are stored."
213 (values (or (assoc-ref (package-properties package) 'ftp-server)
215 (or (assoc-ref (package-properties package) 'ftp-directory)
216 (string-append "/gnu/" (package-name package)))))
218 (define (sans-extension tarball)
219 "Return TARBALL without its .tar.* or .zip extension."
220 (let ((end (or (string-contains tarball ".tar")
221 (string-contains tarball ".zip"))))
222 (substring tarball 0 end)))
225 ;; The .zip extensions is notably used for freefont-ttf.
226 ;; The "-src" pattern is for "TeXmacs-1.0.7.9-src.tar.gz".
227 ;; The "-gnu[0-9]" pattern is for "icecat-38.4.0-gnu1.tar.bz2".
228 (make-regexp "^([^.]+)-([0-9]|[^-])+(-(src|gnu[0-9]))?\\.(tar\\.|zip$)"))
230 (define %alpha-tarball-rx
231 (make-regexp "^.*-.*[0-9](-|~)?(alpha|beta|rc|cvs|svn|git)-?[0-9\\.]*\\.tar\\."))
233 (define (release-file? project file)
234 "Return #f if FILE is not a release tarball of PROJECT, otherwise return
236 (and (not (string-suffix? ".sig" file))
237 (and=> (regexp-exec %tarball-rx file)
239 ;; Filter out unrelated files, like `guile-www-1.1.1'.
240 ;; Case-insensitive for things like "TeXmacs" vs. "texmacs".
241 ;; The "-src" suffix is for "freefont-src-20120503.tar.gz".
242 (and=> (match:substring match 1)
244 (or (string-ci=? name project)
246 (string-append project
248 (not (regexp-exec %alpha-tarball-rx file))
249 (let ((s (sans-extension file)))
250 (regexp-exec %package-name-rx s))))
252 (define (tarball->version tarball)
253 "Return the version TARBALL corresponds to. TARBALL is a file name like
254 \"coreutils-8.23.tar.xz\"."
255 (let-values (((name version)
256 (gnu-package-name->name+version (sans-extension tarball))))
259 (define* (releases project
261 (server "ftp.gnu.org")
262 (directory (string-append "/gnu/" project)))
263 "Return the list of <upstream-release> of PROJECT as a list of release
264 name/directory pairs."
265 ;; TODO: Parse something like fencepost.gnu.org:/gd/gnuorg/packages-ftp.
266 (define conn (ftp-open server))
268 (let loop ((directories (list directory))
273 (coalesce-sources result))
274 ((directory rest ...)
275 (let* ((files (ftp-list conn directory))
276 (subdirs (filter-map (match-lambda
277 ((name 'directory . _) name)
280 (define (file->url file)
281 (string-append "ftp://" server directory "/" file))
283 (define (file->source file)
284 (let ((url (file->url file)))
287 (version (tarball->version file))
289 (signature-urls (list (string-append url ".sig"))))))
291 (loop (append (map (cut string-append directory "/" <>)
295 ;; Filter out signatures, deltas, and files which
296 ;; are potentially not releases of PROJECT--e.g.,
297 ;; in /gnu/guile, filter out guile-oops and
298 ;; guile-www; in mit-scheme, filter out binaries.
299 (filter-map (match-lambda
301 (and (release-file? project file)
302 (file->source file)))
307 (define* (latest-ftp-release project
309 (server "ftp.gnu.org")
310 (directory (string-append "/gnu/" project))
311 (keep-file? (const #t))
312 (file->signature (cut string-append <> ".sig"))
313 (ftp-open ftp-open) (ftp-close ftp-close))
314 "Return an <upstream-source> for the latest release of PROJECT on SERVER
315 under DIRECTORY, or #f. Use FTP-OPEN and FTP-CLOSE to open (resp. close) FTP
316 connections; this can be useful to reuse connections.
318 KEEP-FILE? is a predicate to decide whether to enter a directory and to
319 consider a given file (source tarball) as a valid candidate based on its name.
321 FILE->SIGNATURE must be a procedure; it is passed a source file URL and must
322 return the corresponding signature URL, or #f it signatures are unavailable."
324 (if (version>? a b) a b))
326 (define (latest-release a b)
327 (if (version>? (upstream-source-version a) (upstream-source-version b))
330 (define contains-digit?
331 (cut string-any char-set:digit <>))
333 (define patch-directory-name?
334 ;; Return #t for patch directory names such as 'bash-4.2-patches'.
335 (cut string-suffix? "patches" <>))
337 (define conn (ftp-open server))
339 (define (file->url directory file)
340 (string-append "ftp://" server directory "/" file))
342 (define (file->source directory file)
343 (let ((url (file->url directory file)))
346 (version (tarball->version file))
348 (signature-urls (match (file->signature url)
350 (sig (list sig)))))))
352 (let loop ((directory directory)
354 (let* ((entries (ftp-list conn directory))
356 ;; Filter out sub-directories that do not contain digits---e.g.,
357 ;; /gnuzilla/lang and /gnupg/patches. Filter out "w32"
358 ;; directories as found on ftp.gnutls.org.
359 (subdirs (filter-map (match-lambda
360 (((? patch-directory-name? dir)
363 (("w32" 'directory . _)
365 (((? contains-digit? dir) 'directory . _)
366 (and (keep-file? dir) dir))
370 ;; Whether or not SUBDIRS is empty, compute the latest releases
371 ;; for the current directory. This is necessary for packages
372 ;; such as 'sharutils' that have a sub-directory that contains
373 ;; only an older release.
374 (releases (filter-map (match-lambda
376 (and (release-file? project file)
378 (file->source directory file)))
382 ;; Assume that SUBDIRS correspond to versions, and jump into the
383 ;; one with the highest version number.
384 (let* ((release (reduce latest-release #f
385 (coalesce-sources releases)))
386 (result (if (and result release)
387 (latest-release release result)
388 (or release result)))
389 (target (reduce latest #f subdirs)))
391 (loop (string-append directory "/" target)
397 (define* (latest-release package
399 (server "ftp.gnu.org")
400 (directory (string-append "/gnu/" package)))
401 "Return the <upstream-source> for the latest version of PACKAGE or #f.
402 PACKAGE must be the canonical name of a GNU package."
403 (latest-ftp-release package
405 #:directory directory))
407 (define-syntax-rule (false-if-ftp-error exp)
408 "Return #f if an FTP error is raise while evaluating EXP; return the result
413 (lambda (key port . rest)
414 (if (ftp-connection? port)
419 (define (latest-release* package)
420 "Like 'latest-release', but (1) take a <package> object, and (2) ignore FTP
421 errors that might occur when PACKAGE is not actually a GNU package, or not
422 hosted on ftp.gnu.org, or not under that name (this is the case for
423 \"emacs-auctex\", for instance.)"
424 (let-values (((server directory)
425 (ftp-server/directory package)))
426 (let ((name (or (assoc-ref (package-properties package) 'upstream-name)
427 (package-name package))))
428 (false-if-ftp-error (latest-release name
430 #:directory directory)))))
432 (define %package-name-rx
433 ;; Regexp for a package name, e.g., "foo-X.Y". Since TeXmacs uses
434 ;; "TeXmacs-X.Y-src", the `-src' suffix is allowed.
435 (make-regexp "^(.*)-(([0-9]|\\.)+)(-src)?"))
437 (define (gnu-package-name->name+version name+version)
438 "Return the package name and version number extracted from NAME+VERSION."
439 (let ((match (regexp-exec %package-name-rx name+version)))
441 (values name+version #f)
442 (values (match:substring match 1) (match:substring match 2)))))
444 (define (pure-gnu-package? package)
445 "Return true if PACKAGE is a non-Emacs and non-GNOME GNU package. This
446 excludes AucTeX, for instance, whose releases are now uploaded to
447 elpa.gnu.org, and all the GNOME packages."
448 (and (not (string-prefix? "emacs-" (package-name package)))
449 (not (gnome-package? package))
450 (gnu-package? package)))
452 (define (url-prefix-predicate prefix)
453 "Return a predicate that returns true when passed a package where one of its
454 source URLs starts with PREFIX."
456 (define matching-uri?
459 (string-prefix? prefix uri))
463 (match (package-source package)
465 (match (origin-uri origin)
466 ((? matching-uri?) #t)
470 (define gnome-package?
471 (url-prefix-predicate "mirror://gnome/"))
473 (define (latest-gnome-release package)
474 "Return the latest release of PACKAGE, the name of a GNOME package."
476 (char-set-complement (char-set #\.)))
478 (define (even-minor-version? version)
479 (match (string-tokenize version %not-dot)
480 (((= string->number major) (= string->number minor) . rest)
481 (and minor (even? minor)))
485 (define (even-numbered? file)
486 ;; Return true if FILE somehow denotes an even-numbered file name. The
487 ;; trick here is that we want this to match both directories such as
488 ;; "3.18.6" and actual file names such as "gtk+-3.18.6.tar.bz2".
489 (let-values (((name version) (package-name->name+version file)))
490 (even-minor-version? (or version name))))
492 (define upstream-name
493 ;; Some packages like "NetworkManager" have camel-case names.
494 (or (assoc-ref (package-properties package) 'upstream-name)
495 (package-name package)))
498 (latest-ftp-release upstream-name
499 #:server "ftp.gnome.org"
500 #:directory (string-append "/pub/gnome/sources/"
504 ;; <https://www.gnome.org/gnome-3/source/> explains
505 ;; that odd minor version numbers represent development
506 ;; releases, which we are usually not interested in.
507 #:keep-file? even-numbered?
509 ;; ftp.gnome.org provides no signatures, only
511 #:file->signature (const #f))))
514 (define (latest-kde-release package)
515 "Return the latest release of PACKAGE, the name of an KDE.org package."
516 (let ((uri (string->uri (origin-uri (package-source package)))))
519 (or (assoc-ref (package-properties package) 'upstream-name)
520 (package-name package))
521 #:server "mirrors.mit.edu"
523 (string-append "/kde" (dirname (dirname (uri-path uri))))
524 #:file->signature (const #f)))))
526 (define (latest-xorg-release package)
527 "Return the latest release of PACKAGE, the name of an X.org package."
528 (let ((uri (string->uri (origin-uri (package-source package)))))
531 (package-name package)
532 #:server "ftp.freedesktop.org"
534 (string-append "/pub/xorg/" (dirname (uri-path uri)))))))
536 (define (latest-kernel.org-release package)
537 "Return the latest release of PACKAGE, the name of a kernel.org package."
538 (let ((uri (string->uri (origin-uri (package-source package)))))
541 (package-name package)
542 #:server "ftp.free.fr" ;a mirror reachable over FTP
543 #:directory (string-append "/mirrors/ftp.kernel.org"
544 (dirname (uri-path uri)))
546 ;; kernel.org provides "foo-x.y.tar.sign" files, which are signatures of
547 ;; the uncompressed tarball.
548 #:file->signature (lambda (tarball)
549 (string-append (file-sans-extension tarball)
555 (description "Updater for GNU packages")
556 (pred pure-gnu-package?)
557 (latest latest-release*)))
559 (define %gnome-updater
562 (description "Updater for GNOME packages")
563 (pred gnome-package?)
564 (latest latest-gnome-release)))
569 (description "Updater for KDE packages")
570 (pred (url-prefix-predicate "mirror://kde/"))
571 (latest latest-kde-release)))
573 (define %xorg-updater
576 (description "Updater for X.org packages")
577 (pred (url-prefix-predicate "mirror://xorg/"))
578 (latest latest-xorg-release)))
580 (define %kernel.org-updater
583 (description "Updater for packages hosted on kernel.org")
584 (pred (url-prefix-predicate "mirror://kernel.org/"))
585 (latest latest-kernel.org-release)))
587 ;;; gnu-maintenance.scm ends here