build: Always check for gzip/bzip2/xz.
[jackhill/guix/guix.git] / guix / gnu-maintenance.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
c4e8d513 2;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
f9bbf2a8 3;;; Copyright © 2012, 2013 Nikita Karetnikov <nikita@karetnikov.org>
22189ed1 4;;;
233e7676 5;;; This file is part of GNU Guix.
22189ed1 6;;;
233e7676 7;;; GNU Guix is free software; you can redistribute it and/or modify it
22189ed1
NK
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.
11;;;
233e7676 12;;; GNU Guix is distributed in the hope that it will be useful, but
22189ed1
NK
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.
16;;;
17;;; You should have received a copy of the GNU General Public License
233e7676 18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22189ed1
NK
19
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)
98fefb21 25 #:use-module (ice-9 match)
22189ed1
NK
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-11)
28 #:use-module (srfi srfi-26)
98fefb21 29 #:use-module (system foreign)
3b8258c5 30 #:use-module (guix http-client)
98fefb21 31 #:use-module (guix ftp-client)
0d1e6ce4 32 #:use-module (guix utils)
c0cd1b3e 33 #:use-module (guix records)
0a7c5a09 34 #:use-module (guix upstream)
ef010c0f 35 #:use-module (guix packages)
f9bbf2a8
NK
36 #:export (gnu-package-name
37 gnu-package-mundane-name
38 gnu-package-copyright-holder
39 gnu-package-savannah
40 gnu-package-fsd
41 gnu-package-language
42 gnu-package-logo
43 gnu-package-doc-category
44 gnu-package-doc-summary
c4ca9411 45 gnu-package-doc-description
f9bbf2a8
NK
46 gnu-package-doc-urls
47 gnu-package-download-url
48
49 official-gnu-packages
50 find-packages
ef010c0f 51 gnu-package?
f9bbf2a8 52
202440e0 53 release-file?
98fefb21
LC
54 releases
55 latest-release
7047133f 56 gnu-release-archive-types
0fdd3bea 57 gnu-package-name->name+version
7047133f 58
e80c0f85
LC
59 %gnu-updater
60 %gnome-updater))
98fefb21
LC
61
62;;; Commentary:
63;;;
64;;; Code for dealing with the maintenance of GNU packages, such as
65;;; auto-updates.
66;;;
67;;; Code:
68
69\f
70;;;
71;;; List of GNU packages.
72;;;
22189ed1 73
129f9e11
LC
74(define %gnumaint-base-url
75 "http://cvs.savannah.gnu.org/viewvc/*checkout*/gnumaint/")
76
22189ed1 77(define %package-list-url
1c9e7d65 78 (string->uri
129f9e11 79 (string-append %gnumaint-base-url "gnupackages.txt?root=womb")))
22189ed1 80
129f9e11
LC
81(define %package-description-url
82 ;; This file contains package descriptions in recutils format.
83 ;; See <https://lists.gnu.org/archive/html/guix-devel/2013-10/msg00071.html>.
84 (string->uri
1a75f8d9 85 (string-append %gnumaint-base-url "pkgblurbs.txt?root=womb")))
c4ca9411 86
f9bbf2a8
NK
87(define-record-type* <gnu-package-descriptor>
88 gnu-package-descriptor
89 make-gnu-package-descriptor
90
91 gnu-package-descriptor?
92
93 (name gnu-package-name)
94 (mundane-name gnu-package-mundane-name)
95 (copyright-holder gnu-package-copyright-holder)
96 (savannah gnu-package-savannah)
97 (fsd gnu-package-fsd)
b0efe83a 98 (language gnu-package-language) ; list of strings
f9bbf2a8
NK
99 (logo gnu-package-logo)
100 (doc-category gnu-package-doc-category)
101 (doc-summary gnu-package-doc-summary)
129f9e11 102 (doc-description gnu-package-doc-description) ; taken from 'pkgdescr.txt'
b0efe83a 103 (doc-urls gnu-package-doc-urls) ; list of strings
f9bbf2a8
NK
104 (download-url gnu-package-download-url))
105
9aec35d2
LC
106(define* (official-gnu-packages
107 #:optional (fetch http-fetch/cached))
108 "Return a list of records, which are GNU packages. Use FETCH,
109to fetch the list of GNU packages over HTTP."
c4ca9411 110 (define (read-records port)
f9bbf2a8
NK
111 ;; Return a list of alists. Each alist contains fields of a GNU
112 ;; package.
b0efe83a
LC
113 (let loop ((alist (recutils->alist port))
114 (result '()))
115 (if (null? alist)
c4ca9411 116 (reverse result)
b0efe83a
LC
117 (loop (recutils->alist port)
118 (cons alist result)))))
f9bbf2a8 119
129f9e11 120 (define official-description
9aec35d2 121 (let ((db (read-records (fetch %package-description-url #:text? #t))))
c4ca9411 122 (lambda (name)
129f9e11 123 ;; Return the description found upstream for package NAME, or #f.
c4ca9411 124 (and=> (find (lambda (alist)
129f9e11
LC
125 (equal? name (assoc-ref alist "package")))
126 db)
4d5f0bae
LC
127 (lambda (record)
128 (let ((field (assoc-ref record "blurb")))
129 ;; The upstream description file uses "redirect PACKAGE" as
130 ;; a blurb in cases where the description of the two
131 ;; packages should be considered the same (e.g., GTK+ has
132 ;; "redirect gnome".) This is usually not acceptable for
133 ;; us because we prefer to have distinct descriptions in
134 ;; such cases. Thus, ignore the 'blurb' field when that
135 ;; happens.
136 (and field
137 (not (string-prefix? "redirect " field))
138 field)))))))
c4ca9411
LC
139
140 (map (lambda (alist)
141 (let ((name (assoc-ref alist "package")))
129f9e11 142 (alist->record `(("description" . ,(official-description name))
c4ca9411
LC
143 ,@alist)
144 make-gnu-package-descriptor
145 (list "package" "mundane-name" "copyright-holder"
146 "savannah" "fsd" "language" "logo"
147 "doc-category" "doc-summary" "description"
148 "doc-url"
149 "download-url")
150 '("doc-url" "language"))))
2134228a
LC
151 (let* ((port (fetch %package-list-url #:text? #t))
152 (lst (read-records port)))
153 (close-port port)
154 lst)))
22189ed1 155
f9bbf2a8
NK
156(define (find-packages regexp)
157 "Find GNU packages which satisfy REGEXP."
158 (let ((name-rx (make-regexp regexp)))
159 (filter (lambda (package)
160 (false-if-exception
161 (regexp-exec name-rx (gnu-package-name package))))
162 (official-gnu-packages))))
ef010c0f
LC
163
164(define gnu-package?
165 (memoize
65b96a0c
LC
166 (let ((official-gnu-packages (memoize official-gnu-packages)))
167 (lambda (package)
168 "Return true if PACKAGE is a GNU package. This procedure may access the
ef010c0f 169network to check in GNU's database."
187eb5f6
LC
170 (define (mirror-type url)
171 (let ((uri (string->uri url)))
172 (and (eq? (uri-scheme uri) 'mirror)
c4e8d513
LC
173 (cond
174 ((member (uri-host uri)
175 '("gnu" "gnupg" "gcc" "gnome"))
176 ;; Definitely GNU.
177 'gnu)
178 ((equal? (uri-host uri) "cran")
179 ;; Possibly GNU: mirror://cran could be either GNU R itself
180 ;; or a non-GNU package.
181 #f)
182 (else
183 ;; Definitely non-GNU.
184 'non-gnu)))))
187eb5f6 185
55d1f529
LC
186 (define (gnu-home-page? package)
187 (and=> (package-home-page package)
188 (lambda (url)
189 (and=> (uri-host (string->uri url))
190 (lambda (host)
191 (member host '("www.gnu.org" "gnu.org")))))))
192
193 (or (gnu-home-page? package)
194 (let ((url (and=> (package-source package) origin-uri))
195 (name (package-name package)))
196 (case (and (string? url) (mirror-type url))
197 ((gnu) #t)
198 ((non-gnu) #f)
199 (else
200 (and (member name (map gnu-package-name (official-gnu-packages)))
201 #t)))))))))
ef010c0f 202
98fefb21
LC
203\f
204;;;
205;;; Latest release.
206;;;
207
208(define (ftp-server/directory project)
209 "Return the FTP server and directory where PROJECT's tarball are
210stored."
211 (define quirks
212 '(("commoncpp2" "ftp.gnu.org" "/gnu/commoncpp")
213 ("ucommon" "ftp.gnu.org" "/gnu/commoncpp")
214 ("libzrtpcpp" "ftp.gnu.org" "/gnu/ccrtp")
215 ("libosip2" "ftp.gnu.org" "/gnu/osip")
216 ("libgcrypt" "ftp.gnupg.org" "/gcrypt/libgcrypt")
217 ("libgpg-error" "ftp.gnupg.org" "/gcrypt/libgpg-error")
218 ("libassuan" "ftp.gnupg.org" "/gcrypt/libassuan")
219 ("gnupg" "ftp.gnupg.org" "/gcrypt/gnupg")
220 ("freefont-ttf" "ftp.gnu.org" "/gnu/freefont")
221 ("gnu-ghostscript" "ftp.gnu.org" "/gnu/ghostscript")
222 ("mit-scheme" "ftp.gnu.org" "/gnu/mit-scheme/stable.pkg")
223 ("icecat" "ftp.gnu.org" "/gnu/gnuzilla")
224 ("source-highlight" "ftp.gnu.org" "/gnu/src-highlite")
a4007c98 225 ("gnutls" "ftp.gnutls.org" "/gcrypt/gnutls")
fa04a04f
LC
226
227 ;; FIXME: ftp.texmacs.org is currently outdated; texmacs.org refers to
228 ;; its own http URL instead.
98fefb21
LC
229 ("TeXmacs" "ftp.texmacs.org" "/TeXmacs/targz")))
230
231 (match (assoc project quirks)
232 ((_ server directory)
233 (values server directory))
234 (_
235 (values "ftp.gnu.org" (string-append "/gnu/" project)))))
236
cac137aa 237(define (sans-extension tarball)
f5d9604f
LC
238 "Return TARBALL without its .tar.* or .zip extension."
239 (let ((end (or (string-contains tarball ".tar")
240 (string-contains tarball ".zip"))))
cac137aa 241 (substring tarball 0 end)))
98fefb21 242
d55a99fe 243(define %tarball-rx
f00dccf4
LC
244 ;; The .zip extensions is notably used for freefont-ttf.
245 ;; The "-src" pattern is for "TeXmacs-1.0.7.9-src.tar.gz".
246 ;; The "-gnu[0-9]" pattern is for "icecat-38.4.0-gnu1.tar.bz2".
247 (make-regexp "^([^.]+)-([0-9]|[^-])+(-(src|gnu[0-9]))?\\.(tar\\.|zip$)"))
d55a99fe
LC
248
249(define %alpha-tarball-rx
250 (make-regexp "^.*-.*[0-9](-|~)?(alpha|beta|rc|cvs|svn|git)-?[0-9\\.]*\\.tar\\."))
251
501d7647 252(define (release-file? project file)
cac137aa 253 "Return #f if FILE is not a release tarball of PROJECT, otherwise return
501d7647 254true."
cac137aa 255 (and (not (string-suffix? ".sig" file))
d55a99fe
LC
256 (and=> (regexp-exec %tarball-rx file)
257 (lambda (match)
258 ;; Filter out unrelated files, like `guile-www-1.1.1'.
fa04a04f
LC
259 ;; Case-insensitive for things like "TeXmacs" vs. "texmacs".
260 (and=> (match:substring match 1)
261 (lambda (name)
262 (string-ci=? name project)))))
cac137aa
LC
263 (not (regexp-exec %alpha-tarball-rx file))
264 (let ((s (sans-extension file)))
501d7647
LC
265 (regexp-exec %package-name-rx s))))
266
267(define (tarball->version tarball)
268 "Return the version TARBALL corresponds to. TARBALL is a file name like
269\"coreutils-8.23.tar.xz\"."
270 (let-values (((name version)
271 (gnu-package-name->name+version (sans-extension tarball))))
272 version))
273
cac137aa
LC
274(define (releases project)
275 "Return the list of releases of PROJECT as a list of release name/directory
276pairs. Example: (\"mit-scheme-9.0.1\" . \"/gnu/mit-scheme/stable.pkg/9.0.1\"). "
277 ;; TODO: Parse something like fencepost.gnu.org:/gd/gnuorg/packages-ftp.
98fefb21
LC
278 (let-values (((server directory) (ftp-server/directory project)))
279 (define conn (ftp-open server))
280
281 (let loop ((directories (list directory))
282 (result '()))
6a917ef7
LC
283 (match directories
284 (()
285 (ftp-close conn)
0a7c5a09 286 (coalesce-sources result))
6a917ef7
LC
287 ((directory rest ...)
288 (let* ((files (ftp-list conn directory))
289 (subdirs (filter-map (match-lambda
0a7c5a09
LC
290 ((name 'directory . _) name)
291 (_ #f))
6a917ef7 292 files)))
0a7c5a09
LC
293 (define (file->url file)
294 (string-append "ftp://" server directory "/" file))
295
296 (define (file->source file)
297 (let ((url (file->url file)))
298 (upstream-source
299 (package project)
300 (version (tarball->version file))
301 (urls (list url))
302 (signature-urls (list (string-append url ".sig"))))))
303
6a917ef7
LC
304 (loop (append (map (cut string-append directory "/" <>)
305 subdirs)
306 rest)
307 (append
308 ;; Filter out signatures, deltas, and files which
309 ;; are potentially not releases of PROJECT--e.g.,
310 ;; in /gnu/guile, filter out guile-oops and
311 ;; guile-www; in mit-scheme, filter out binaries.
312 (filter-map (match-lambda
0a7c5a09
LC
313 ((file 'file . _)
314 (and (release-file? project file)
315 (file->source file)))
316 (_ #f))
6a917ef7
LC
317 files)
318 result))))))))
98fefb21 319
e946f2ec
LC
320(define* (latest-ftp-release project
321 #:key
322 (server "ftp.gnu.org")
323 (directory (string-append "/gnu/" project))
c4991257 324 (keep-file? (const #t))
6efa6f76 325 (file->signature (cut string-append <> ".sig"))
e946f2ec
LC
326 (ftp-open ftp-open) (ftp-close ftp-close))
327 "Return an <upstream-source> for the latest release of PROJECT on SERVER
328under DIRECTORY, or #f. Use FTP-OPEN and FTP-CLOSE to open (resp. close) FTP
c4991257
LC
329connections; this can be useful to reuse connections.
330
331KEEP-FILE? is a predicate to decide whether to consider a given file (source
332tarball) as a valid candidate based on its name.
333
334FILE->SIGNATURE must be a procedure; it is passed a source file URL and must
335return the corresponding signature URL, or #f it signatures are unavailable."
cac137aa
LC
336 (define (latest a b)
337 (if (version>? a b) a b))
338
501d7647 339 (define (latest-release a b)
0a7c5a09 340 (if (version>? (upstream-source-version a) (upstream-source-version b))
501d7647
LC
341 a b))
342
cac137aa
LC
343 (define contains-digit?
344 (cut string-any char-set:digit <>))
345
a74da6b0
LC
346 (define patch-directory-name?
347 ;; Return #t for patch directory names such as 'bash-4.2-patches'.
348 (cut string-suffix? "patches" <>))
349
e946f2ec
LC
350 (define conn (ftp-open server))
351
352 (define (file->url directory file)
353 (string-append "ftp://" server directory "/" file))
354
355 (define (file->source directory file)
356 (let ((url (file->url directory file)))
357 (upstream-source
358 (package project)
359 (version (tarball->version file))
360 (urls (list url))
6efa6f76
LC
361 (signature-urls (match (file->signature url)
362 (#f #f)
363 (sig (list sig)))))))
e946f2ec
LC
364
365 (let loop ((directory directory)
366 (result #f))
367 (let* ((entries (ftp-list conn directory))
368
369 ;; Filter out sub-directories that do not contain digits---e.g.,
370 ;; /gnuzilla/lang and /gnupg/patches. Filter out "w32"
371 ;; directories as found on ftp.gnutls.org.
372 (subdirs (filter-map (match-lambda
373 (((? patch-directory-name? dir)
374 'directory . _)
375 #f)
376 (("w32" 'directory . _)
377 #f)
378 (((? contains-digit? dir) 'directory . _)
379 dir)
380 (_ #f))
381 entries))
382
383 ;; Whether or not SUBDIRS is empty, compute the latest releases
384 ;; for the current directory. This is necessary for packages
385 ;; such as 'sharutils' that have a sub-directory that contains
386 ;; only an older release.
387 (releases (filter-map (match-lambda
388 ((file 'file . _)
389 (and (release-file? project file)
c4991257 390 (keep-file? file)
e946f2ec
LC
391 (file->source directory file)))
392 (_ #f))
393 entries)))
394
395 ;; Assume that SUBDIRS correspond to versions, and jump into the
396 ;; one with the highest version number.
397 (let* ((release (reduce latest-release #f
398 (coalesce-sources releases)))
399 (result (if (and result release)
400 (latest-release release result)
401 (or release result)))
402 (target (reduce latest #f subdirs)))
403 (if target
404 (loop (string-append directory "/" target)
405 result)
406 (begin
407 (ftp-close conn)
408 result))))))
409
410(define (latest-release package . rest)
411 "Return the <upstream-source> for the latest version of PACKAGE or #f.
412PACKAGE is the name of a GNU package. This procedure automatically uses the
413right FTP server and directory for PACKAGE."
414 (let-values (((server directory) (ftp-server/directory package)))
415 (apply latest-ftp-release package
416 #:server server
417 #:directory directory
418 rest)))
98fefb21 419
e80c0f85
LC
420(define-syntax-rule (false-if-ftp-error exp)
421 "Return #f if an FTP error is raise while evaluating EXP; return the result
422of EXP otherwise."
0a7c5a09
LC
423 (catch 'ftp-error
424 (lambda ()
e80c0f85 425 exp)
0a7c5a09
LC
426 (lambda (key port . rest)
427 (if (ftp-connection? port)
428 (ftp-close port)
429 (close-port port))
430 #f)))
7047133f 431
e80c0f85
LC
432(define (latest-release* package)
433 "Like 'latest-release', but ignore FTP errors that might occur when PACKAGE
434is not actually a GNU package, or not hosted on ftp.gnu.org, or not under that
435name (this is the case for \"emacs-auctex\", for instance.)"
436 (false-if-ftp-error (latest-release package)))
437
98fefb21
LC
438(define %package-name-rx
439 ;; Regexp for a package name, e.g., "foo-X.Y". Since TeXmacs uses
440 ;; "TeXmacs-X.Y-src", the `-src' suffix is allowed.
441 (make-regexp "^(.*)-(([0-9]|\\.)+)(-src)?"))
442
443(define (gnu-package-name->name+version name+version)
444 "Return the package name and version number extracted from NAME+VERSION."
445 (let ((match (regexp-exec %package-name-rx name+version)))
446 (if (not match)
447 (values name+version #f)
448 (values (match:substring match 1) (match:substring match 2)))))
449
e80c0f85
LC
450(define (pure-gnu-package? package)
451 "Return true if PACKAGE is a non-Emacs and non-GNOME GNU package. This
452excludes AucTeX, for instance, whose releases are now uploaded to
453elpa.gnu.org, and all the GNOME packages."
0a7c5a09 454 (and (not (string-prefix? "emacs-" (package-name package)))
e80c0f85 455 (not (gnome-package? package))
0a7c5a09 456 (gnu-package? package)))
0fdd3bea 457
e80c0f85
LC
458(define (gnome-package? package)
459 "Return true if PACKAGE is a GNOME package, hosted on gnome.org."
460 (define gnome-uri?
461 (match-lambda
462 ((? string? uri)
463 (string-prefix? "mirror://gnome/" uri))
464 (_
465 #f)))
466
467 (match (package-source package)
468 ((? origin? origin)
469 (match (origin-uri origin)
470 ((? gnome-uri?) #t)
471 (_ #f)))
472 (_ #f)))
473
474(define (latest-gnome-release package)
475 "Return the latest release of PACKAGE, the name of a GNOME package."
c4991257
LC
476 (define %not-dot
477 (char-set-complement (char-set #\.)))
478
479 (define (even-minor-version? version)
480 (match (string-tokenize (version-major+minor version)
481 %not-dot)
482 (((= string->number major) (= string->number minor))
483 (even? minor))
484 (_
485 #t))) ;cross fingers
486
487 (define (even-numbered-tarball? file)
488 (let-values (((name version) (gnu-package-name->name+version file)))
489 (and version
490 (even-minor-version? version))))
491
e80c0f85
LC
492 (false-if-ftp-error
493 (latest-ftp-release package
494 #:server "ftp.gnome.org"
495 #:directory (string-append "/pub/gnome/sources/"
496 (match package
497 ("gconf" "GConf")
6efa6f76
LC
498 (x x)))
499
c4991257
LC
500
501 ;; <https://www.gnome.org/gnome-3/source/> explains
502 ;; that odd minor version numbers represent development
503 ;; releases, which we are usually not interested in.
504 #:keep-file? even-numbered-tarball?
505
6efa6f76
LC
506 ;; ftp.gnome.org provides no signatures, only
507 ;; checksums.
508 #:file->signature (const #f))))
e80c0f85 509
0a7c5a09 510(define %gnu-updater
7e6b490d
AK
511 (upstream-updater
512 (name 'gnu)
513 (description "Updater for GNU packages")
e80c0f85 514 (pred pure-gnu-package?)
7e6b490d 515 (latest latest-release*)))
0fdd3bea 516
e80c0f85
LC
517(define %gnome-updater
518 (upstream-updater
519 (name 'gnome)
520 (description "Updater for GNOME packages")
521 (pred gnome-package?)
522 (latest latest-gnome-release)))
523
98fefb21 524;;; gnu-maintenance.scm ends here