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 (rnrs io ports)
30 #:use-module (system foreign)
31 #:use-module (guix http-client)
32 #:use-module (guix ftp-client)
33 #:use-module (guix utils)
34 #:use-module (guix memoization)
35 #:use-module (guix records)
36 #:use-module (guix upstream)
37 #:use-module (guix packages)
38 #:use-module (guix zlib)
39 #:export (gnu-package-name
40 gnu-package-mundane-name
41 gnu-package-copyright-holder
46 gnu-package-doc-category
47 gnu-package-doc-summary
48 gnu-package-doc-description
50 gnu-package-download-url
59 gnu-release-archive-types
60 gnu-package-name->name+version
70 ;;; Code for dealing with the maintenance of GNU packages, such as
77 ;;; List of GNU packages.
80 (define %gnumaint-base-url
81 "http://cvs.savannah.gnu.org/viewvc/*checkout*/womb/gnumaint/")
83 (define %package-list-url
85 (string-append %gnumaint-base-url "gnupackages.txt")))
87 (define %package-description-url
88 ;; This file contains package descriptions in recutils format.
89 ;; See <https://lists.gnu.org/archive/html/guix-devel/2013-10/msg00071.html>.
91 (string-append %gnumaint-base-url "pkgblurbs.txt")))
93 (define-record-type* <gnu-package-descriptor>
94 gnu-package-descriptor
95 make-gnu-package-descriptor
97 gnu-package-descriptor?
99 (name gnu-package-name)
100 (mundane-name gnu-package-mundane-name)
101 (copyright-holder gnu-package-copyright-holder)
102 (savannah gnu-package-savannah)
103 (fsd gnu-package-fsd)
104 (language gnu-package-language) ; list of strings
105 (logo gnu-package-logo)
106 (doc-category gnu-package-doc-category)
107 (doc-summary gnu-package-doc-summary)
108 (doc-description gnu-package-doc-description) ; taken from 'pkgdescr.txt'
109 (doc-urls gnu-package-doc-urls) ; list of strings
110 (download-url gnu-package-download-url))
112 (define* (official-gnu-packages
113 #:optional (fetch http-fetch/cached))
114 "Return a list of records, which are GNU packages. Use FETCH,
115 to fetch the list of GNU packages over HTTP."
116 (define (read-records port)
117 ;; Return a list of alists. Each alist contains fields of a GNU
119 (let loop ((alist (recutils->alist port))
123 (loop (recutils->alist port)
124 (cons alist result)))))
126 (define official-description
127 (let ((db (read-records (fetch %package-description-url #:text? #t))))
129 ;; Return the description found upstream for package NAME, or #f.
130 (and=> (find (lambda (alist)
131 (equal? name (assoc-ref alist "package")))
134 (let ((field (assoc-ref record "blurb")))
135 ;; The upstream description file uses "redirect PACKAGE" as
136 ;; a blurb in cases where the description of the two
137 ;; packages should be considered the same (e.g., GTK+ has
138 ;; "redirect gnome".) This is usually not acceptable for
139 ;; us because we prefer to have distinct descriptions in
140 ;; such cases. Thus, ignore the 'blurb' field when that
143 (not (string-prefix? "redirect " field))
147 (let ((name (assoc-ref alist "package")))
148 (alist->record `(("description" . ,(official-description name))
150 make-gnu-package-descriptor
151 (list "package" "mundane-name" "copyright-holder"
152 "savannah" "fsd" "language" "logo"
153 "doc-category" "doc-summary" "description"
156 '("doc-url" "language"))))
157 (let* ((port (fetch %package-list-url #:text? #t))
158 (lst (read-records port)))
162 (define (find-package name)
163 "Find GNU package called NAME and return it. Return #f if it was not
165 (find (lambda (package)
166 (string=? name (gnu-package-name package)))
167 (official-gnu-packages)))
170 (let ((official-gnu-packages (memoize official-gnu-packages)))
172 "Return true if PACKAGE is a GNU package. This procedure may access the
173 network to check in GNU's database."
174 (define (mirror-type url)
175 (let ((uri (string->uri url)))
176 (and (eq? (uri-scheme uri) 'mirror)
178 ((member (uri-host uri)
179 '("gnu" "gnupg" "gcc" "gnome"))
182 ((equal? (uri-host uri) "cran")
183 ;; Possibly GNU: mirror://cran could be either GNU R itself
184 ;; or a non-GNU package.
187 ;; Definitely non-GNU.
190 (define (gnu-home-page? package)
191 (letrec-syntax ((>> (syntax-rules ()
194 ((_ value proc rest ...)
197 (>> (proc next) rest ...)))))))
198 (>> package package-home-page
201 (member host '("www.gnu.org" "gnu.org"))))))
203 (or (gnu-home-page? package)
204 (let ((url (and=> (package-source package) origin-uri))
205 (name (package-upstream-name package)))
206 (case (and (string? url) (mirror-type url))
210 (and (member name (map gnu-package-name (official-gnu-packages)))
218 (define (ftp-server/directory package)
219 "Return the FTP server and directory where PACKAGE's tarball are stored."
220 (let ((name (package-upstream-name package)))
221 (values (or (assoc-ref (package-properties package) 'ftp-server)
223 (or (assoc-ref (package-properties package) 'ftp-directory)
224 (string-append "/gnu/" name)))))
226 (define (sans-extension tarball)
227 "Return TARBALL without its .tar.* or .zip extension."
228 (let ((end (or (string-contains tarball ".tar")
229 (string-contains tarball ".zip"))))
230 (substring tarball 0 end)))
233 ;; The .zip extensions is notably used for freefont-ttf.
234 ;; The "-src" pattern is for "TeXmacs-1.0.7.9-src.tar.gz".
235 ;; The "-gnu[0-9]" pattern is for "icecat-38.4.0-gnu1.tar.bz2".
236 (make-regexp "^([^.]+)-([0-9]|[^-])+(-(src|gnu[0-9]))?\\.(tar\\.|zip$)"))
238 (define %alpha-tarball-rx
239 (make-regexp "^.*-.*[0-9](-|~)?(alpha|beta|rc|cvs|svn|git)-?[0-9\\.]*\\.tar\\."))
241 (define (release-file? project file)
242 "Return #f if FILE is not a release tarball of PROJECT, otherwise return
244 (and (not (string-suffix? ".sig" file))
245 (and=> (regexp-exec %tarball-rx file)
247 ;; Filter out unrelated files, like `guile-www-1.1.1'.
248 ;; Case-insensitive for things like "TeXmacs" vs. "texmacs".
249 ;; The "-src" suffix is for "freefont-src-20120503.tar.gz".
250 (and=> (match:substring match 1)
252 (or (string-ci=? name project)
254 (string-append project
256 (not (regexp-exec %alpha-tarball-rx file))
257 (let ((s (sans-extension file)))
258 (regexp-exec %package-name-rx s))))
260 (define (tarball->version tarball)
261 "Return the version TARBALL corresponds to. TARBALL is a file name like
262 \"coreutils-8.23.tar.xz\"."
263 (let-values (((name version)
264 (gnu-package-name->name+version (sans-extension tarball))))
267 (define* (releases project
269 (server "ftp.gnu.org")
270 (directory (string-append "/gnu/" project)))
271 "Return the list of <upstream-release> of PROJECT as a list of release
272 name/directory pairs."
273 ;; TODO: Parse something like fencepost.gnu.org:/gd/gnuorg/packages-ftp.
274 (define conn (ftp-open server))
276 (let loop ((directories (list directory))
281 (coalesce-sources result))
282 ((directory rest ...)
283 (let* ((files (ftp-list conn directory))
284 (subdirs (filter-map (match-lambda
285 ((name 'directory . _) name)
288 (define (file->url file)
289 (string-append "ftp://" server directory "/" file))
291 (define (file->source file)
292 (let ((url (file->url file)))
295 (version (tarball->version file))
297 (signature-urls (list (string-append url ".sig"))))))
299 (loop (append (map (cut string-append directory "/" <>)
303 ;; Filter out signatures, deltas, and files which
304 ;; are potentially not releases of PROJECT--e.g.,
305 ;; in /gnu/guile, filter out guile-oops and
306 ;; guile-www; in mit-scheme, filter out binaries.
307 (filter-map (match-lambda
309 (and (release-file? project file)
310 (file->source file)))
315 (define* (latest-ftp-release project
317 (server "ftp.gnu.org")
318 (directory (string-append "/gnu/" project))
319 (keep-file? (const #t))
320 (file->signature (cut string-append <> ".sig"))
321 (ftp-open ftp-open) (ftp-close ftp-close))
322 "Return an <upstream-source> for the latest release of PROJECT on SERVER
323 under DIRECTORY, or #f. Use FTP-OPEN and FTP-CLOSE to open (resp. close) FTP
324 connections; this can be useful to reuse connections.
326 KEEP-FILE? is a predicate to decide whether to enter a directory and to
327 consider a given file (source tarball) as a valid candidate based on its name.
329 FILE->SIGNATURE must be a procedure; it is passed a source file URL and must
330 return the corresponding signature URL, or #f it signatures are unavailable."
332 (if (version>? a b) a b))
334 (define (latest-release a b)
335 (if (version>? (upstream-source-version a) (upstream-source-version b))
338 (define contains-digit?
339 (cut string-any char-set:digit <>))
341 (define patch-directory-name?
342 ;; Return #t for patch directory names such as 'bash-4.2-patches'.
343 (cut string-suffix? "patches" <>))
345 (define conn (ftp-open server))
347 (define (file->url directory file)
348 (string-append "ftp://" server directory "/" file))
350 (define (file->source directory file)
351 (let ((url (file->url directory file)))
354 (version (tarball->version file))
356 (signature-urls (match (file->signature url)
358 (sig (list sig)))))))
360 (let loop ((directory directory)
362 (let* ((entries (ftp-list conn directory))
364 ;; Filter out sub-directories that do not contain digits---e.g.,
365 ;; /gnuzilla/lang and /gnupg/patches. Filter out "w32"
366 ;; directories as found on ftp.gnutls.org.
367 (subdirs (filter-map (match-lambda
368 (((? patch-directory-name? dir)
371 (("w32" 'directory . _)
373 (((? contains-digit? dir) 'directory . _)
374 (and (keep-file? dir) dir))
378 ;; Whether or not SUBDIRS is empty, compute the latest releases
379 ;; for the current directory. This is necessary for packages
380 ;; such as 'sharutils' that have a sub-directory that contains
381 ;; only an older release.
382 (releases (filter-map (match-lambda
384 (and (release-file? project file)
386 (file->source directory file)))
390 ;; Assume that SUBDIRS correspond to versions, and jump into the
391 ;; one with the highest version number.
392 (let* ((release (reduce latest-release #f
393 (coalesce-sources releases)))
394 (result (if (and result release)
395 (latest-release release result)
396 (or release result)))
397 (target (reduce latest #f subdirs)))
399 (loop (string-append directory "/" target)
405 (define* (latest-release package
407 (server "ftp.gnu.org")
408 (directory (string-append "/gnu/" package)))
409 "Return the <upstream-source> for the latest version of PACKAGE or #f.
410 PACKAGE must be the canonical name of a GNU package."
411 (latest-ftp-release package
413 #:directory directory))
415 (define-syntax-rule (false-if-ftp-error exp)
416 "Return #f if an FTP error is raise while evaluating EXP; return the result
421 (lambda (key port . rest)
422 (if (ftp-connection? port)
427 (define (latest-release* package)
428 "Like 'latest-release', but (1) take a <package> object, and (2) ignore FTP
429 errors that might occur when PACKAGE is not actually a GNU package, or not
430 hosted on ftp.gnu.org, or not under that name (this is the case for
431 \"emacs-auctex\", for instance.)"
432 (let-values (((server directory)
433 (ftp-server/directory package)))
434 (false-if-ftp-error (latest-release (package-upstream-name package)
436 #:directory directory))))
438 (define %gnu-file-list-uri
439 ;; URI of the file list for ftp.gnu.org.
440 (string->uri "https://ftp.gnu.org/find.txt.gz"))
442 (define ftp.gnu.org-files
444 "Return the list of files available at ftp.gnu.org."
446 ;; XXX: Memoize the whole procedure to work around the fact that
447 ;; 'http-fetch/cached' caches the gzipped version.
449 (define (trim-leading-components str)
450 ;; Trim the leading ".", if any, in "./gnu/foo".
451 (string-trim str (char-set #\.)))
453 (define (string->lines str)
454 (string-tokenize str (char-set-complement (char-set #\newline))))
456 ;; Since https://ftp.gnu.org honors 'If-Modified-Since', the hard-coded
457 ;; TTL can be relatively short.
458 (let ((port (http-fetch/cached %gnu-file-list-uri #:ttl (* 15 60))))
459 (map trim-leading-components
460 (call-with-gzip-input-port port
461 (compose string->lines get-string-all))))))
463 (define (latest-gnu-release package)
464 "Return the latest release of PACKAGE, a GNU package available via
467 This method does not rely on FTP access at all; instead, it browses the file
468 list available from %GNU-FILE-LIST-URI over HTTP(S)."
469 (let-values (((server directory)
470 (ftp-server/directory package))
472 (package-upstream-name package)))
473 (let* ((files (ftp.gnu.org-files))
474 (relevant (filter (lambda (file)
475 (and (string-prefix? "/gnu" file)
476 (string-contains file directory)
477 (release-file? name (basename file))))
479 (match (sort relevant (lambda (file1 file2)
480 (version>? (sans-extension (basename file1))
481 (sans-extension (basename file2)))))
482 ((and tarballs (reference _ ...))
483 (let* ((version (tarball->version reference))
484 (tarballs (filter (lambda (file)
485 (string=? (sans-extension
488 (basename reference))))
493 (urls (map (lambda (file)
494 (string-append "mirror://gnu/"
496 (string-length "/gnu/"))))
498 (signature-urls (map (cut string-append <> ".sig") urls)))))
502 (define %package-name-rx
503 ;; Regexp for a package name, e.g., "foo-X.Y". Since TeXmacs uses
504 ;; "TeXmacs-X.Y-src", the `-src' suffix is allowed.
505 (make-regexp "^(.*)-(([0-9]|\\.)+)(-src)?"))
507 (define (gnu-package-name->name+version name+version)
508 "Return the package name and version number extracted from NAME+VERSION."
509 (let ((match (regexp-exec %package-name-rx name+version)))
511 (values name+version #f)
512 (values (match:substring match 1) (match:substring match 2)))))
514 (define gnome-package?
515 (url-prefix-predicate "mirror://gnome/"))
517 (define (pure-gnu-package? package)
518 "Return true if PACKAGE is a non-Emacs and non-GNOME GNU package. This
519 excludes AucTeX, for instance, whose releases are now uploaded to
520 elpa.gnu.org, and all the GNOME packages; EMMS is included though, because its
521 releases are on gnu.org."
522 (and (or (not (string-prefix? "emacs-" (package-name package)))
523 (gnu-hosted? package))
524 (not (gnome-package? package))
525 (gnu-package? package)))
528 (url-prefix-predicate "mirror://gnu/"))
530 (define (latest-kde-release package)
531 "Return the latest release of PACKAGE, the name of an KDE.org package."
532 (let ((uri (string->uri (origin-uri (package-source package)))))
535 (package-upstream-name package)
536 #:server "mirrors.mit.edu"
538 (string-append "/kde" (dirname (dirname (uri-path uri))))
539 #:file->signature (const #f)))))
541 (define (latest-xorg-release package)
542 "Return the latest release of PACKAGE, the name of an X.org package."
543 (let ((uri (string->uri (origin-uri (package-source package)))))
546 (package-name package)
547 #:server "ftp.freedesktop.org"
549 (string-append "/pub/xorg/" (dirname (uri-path uri)))))))
551 (define (latest-kernel.org-release package)
552 "Return the latest release of PACKAGE, the name of a kernel.org package."
553 (let ((uri (string->uri (origin-uri (package-source package)))))
556 (package-name package)
557 #:server "ftp.free.fr" ;a mirror reachable over FTP
558 #:directory (string-append "/mirrors/ftp.kernel.org"
559 (dirname (uri-path uri)))
561 ;; kernel.org provides "foo-x.y.tar.sign" files, which are signatures of
562 ;; the uncompressed tarball.
563 #:file->signature (lambda (tarball)
564 (string-append (file-sans-extension tarball)
568 ;; This is for everything at ftp.gnu.org.
571 (description "Updater for GNU packages")
573 (latest latest-gnu-release)))
575 (define %gnu-ftp-updater
576 ;; This is for GNU packages taken from alternate locations, such as
577 ;; alpha.gnu.org, ftp.gnupg.org, etc. It is obsolescent.
580 (description "Updater for GNU packages only available via FTP")
581 (pred (lambda (package)
582 (and (not (gnu-hosted? package))
583 (pure-gnu-package? package))))
584 (latest latest-release*)))
589 (description "Updater for KDE packages")
590 (pred (url-prefix-predicate "mirror://kde/"))
591 (latest latest-kde-release)))
593 (define %xorg-updater
596 (description "Updater for X.org packages")
597 (pred (url-prefix-predicate "mirror://xorg/"))
598 (latest latest-xorg-release)))
600 (define %kernel.org-updater
603 (description "Updater for packages hosted on kernel.org")
604 (pred (url-prefix-predicate "mirror://kernel.org/"))
605 (latest latest-kernel.org-release)))
607 ;;; gnu-maintenance.scm ends here