gnu-maintenance.scm 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2012, 2013 Nikita Karetnikov <nikita@karetnikov.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  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.
  11. ;;;
  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.
  16. ;;;
  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/>.
  19. (define-module (guix gnu-maintenance)
  20. #:use-module (web uri)
  21. #:use-module (web client)
  22. #:use-module (web response)
  23. #:use-module (sxml simple)
  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 (zlib)
  39. #:export (gnu-package-name
  40. gnu-package-mundane-name
  41. gnu-package-copyright-holder
  42. gnu-package-savannah
  43. gnu-package-fsd
  44. gnu-package-language
  45. gnu-package-logo
  46. gnu-package-doc-category
  47. gnu-package-doc-summary
  48. gnu-package-doc-description
  49. gnu-package-doc-urls
  50. gnu-package-download-url
  51. official-gnu-packages
  52. find-package
  53. gnu-package?
  54. release-file?
  55. releases
  56. latest-release
  57. gnu-release-archive-types
  58. gnu-package-name->name+version
  59. %gnu-updater
  60. %gnu-ftp-updater
  61. %savannah-updater
  62. %xorg-updater
  63. %kernel.org-updater))
  64. ;;; Commentary:
  65. ;;;
  66. ;;; Code for dealing with the maintenance of GNU packages, such as
  67. ;;; auto-updates.
  68. ;;;
  69. ;;; Code:
  70. ;;;
  71. ;;; List of GNU packages.
  72. ;;;
  73. (define %gnumaint-base-url
  74. "https://web.cvs.savannah.gnu.org/viewvc/*checkout*/www/www/prep/gnumaint/")
  75. (define %package-list-url
  76. (string->uri
  77. (string-append %gnumaint-base-url "rec/gnupackages.rec")))
  78. (define %package-description-url
  79. ;; This file contains package descriptions in recutils format.
  80. ;; See <https://lists.gnu.org/archive/html/guix-devel/2013-10/msg00071.html>
  81. ;; and <https://lists.gnu.org/archive/html/guix-devel/2018-06/msg00362.html>.
  82. (string->uri
  83. (string-append %gnumaint-base-url "rec/pkgblurbs.rec")))
  84. (define-record-type* <gnu-package-descriptor>
  85. gnu-package-descriptor
  86. make-gnu-package-descriptor
  87. gnu-package-descriptor?
  88. (name gnu-package-name)
  89. (mundane-name gnu-package-mundane-name)
  90. (copyright-holder gnu-package-copyright-holder)
  91. (savannah gnu-package-savannah)
  92. (fsd gnu-package-fsd)
  93. (language gnu-package-language) ; list of strings
  94. (logo gnu-package-logo)
  95. (doc-category gnu-package-doc-category)
  96. (doc-summary gnu-package-doc-summary)
  97. (doc-description gnu-package-doc-description) ; taken from 'pkgdescr.txt'
  98. (doc-urls gnu-package-doc-urls) ; list of strings
  99. (download-url gnu-package-download-url))
  100. (define* (official-gnu-packages
  101. #:optional (fetch http-fetch/cached))
  102. "Return a list of records, which are GNU packages. Use FETCH,
  103. to fetch the list of GNU packages over HTTP."
  104. (define (read-records port)
  105. ;; Return a list of alists. Each alist contains fields of a GNU
  106. ;; package.
  107. (let loop ((alist (recutils->alist port))
  108. (result '()))
  109. (if (null? alist)
  110. (reverse result)
  111. (loop (recutils->alist port)
  112. ;; Ignore things like "%rec" (info "(recutils) Record
  113. ;; Descriptors").
  114. (if (assoc-ref alist "package")
  115. (cons alist result)
  116. result)))))
  117. (define official-description
  118. (let ((db (read-records (fetch %package-description-url #:text? #t))))
  119. (lambda (name)
  120. ;; Return the description found upstream for package NAME, or #f.
  121. (and=> (find (lambda (alist)
  122. (equal? name (assoc-ref alist "package")))
  123. db)
  124. (lambda (record)
  125. (let ((field (assoc-ref record "blurb")))
  126. ;; The upstream description file uses "redirect PACKAGE" as
  127. ;; a blurb in cases where the description of the two
  128. ;; packages should be considered the same (e.g., GTK+ has
  129. ;; "redirect gnome".) This is usually not acceptable for
  130. ;; us because we prefer to have distinct descriptions in
  131. ;; such cases. Thus, ignore the 'blurb' field when that
  132. ;; happens.
  133. (and field
  134. (not (string-prefix? "redirect " field))
  135. field)))))))
  136. (map (lambda (alist)
  137. (let ((name (assoc-ref alist "package")))
  138. (alist->record `(("description" . ,(official-description name))
  139. ,@alist)
  140. make-gnu-package-descriptor
  141. (list "package" "mundane_name" "copyright_holder"
  142. "savannah" "fsd" "language" "logo"
  143. "doc_category" "doc_summary" "description"
  144. "doc_url"
  145. "download_url")
  146. '("doc_url" "language"))))
  147. (let* ((port (fetch %package-list-url #:text? #t))
  148. (lst (read-records port)))
  149. (close-port port)
  150. lst)))
  151. (define (find-package name)
  152. "Find GNU package called NAME and return it. Return #f if it was not
  153. found."
  154. (find (lambda (package)
  155. (string=? name (gnu-package-name package)))
  156. (official-gnu-packages)))
  157. (define gnu-package?
  158. (let ((official-gnu-packages (memoize official-gnu-packages)))
  159. (mlambdaq (package)
  160. "Return true if PACKAGE is a GNU package. This procedure may access the
  161. network to check in GNU's database."
  162. (define (mirror-type url)
  163. (let ((uri (string->uri url)))
  164. (and (eq? (uri-scheme uri) 'mirror)
  165. (cond
  166. ((member (uri-host uri)
  167. '("gnu" "gnupg" "gcc" "gnome"))
  168. ;; Definitely GNU.
  169. 'gnu)
  170. ((equal? (uri-host uri) "cran")
  171. ;; Possibly GNU: mirror://cran could be either GNU R itself
  172. ;; or a non-GNU package.
  173. #f)
  174. (else
  175. ;; Definitely non-GNU.
  176. 'non-gnu)))))
  177. (define (gnu-home-page? package)
  178. (letrec-syntax ((>> (syntax-rules ()
  179. ((_ value proc)
  180. (and=> value proc))
  181. ((_ value proc rest ...)
  182. (and=> value
  183. (lambda (next)
  184. (>> (proc next) rest ...)))))))
  185. (>> package package-home-page
  186. string->uri uri-host
  187. (lambda (host)
  188. (member host '("www.gnu.org" "gnu.org"))))))
  189. (or (gnu-home-page? package)
  190. (match (package-source package)
  191. ((? origin? origin)
  192. (let ((url (origin-uri origin))
  193. (name (package-upstream-name package)))
  194. (case (and (string? url) (mirror-type url))
  195. ((gnu) #t)
  196. ((non-gnu) #f)
  197. (else
  198. (and (member name (map gnu-package-name (official-gnu-packages)))
  199. #t)))))
  200. (_ #f))))))
  201. ;;;
  202. ;;; Latest FTP release.
  203. ;;;
  204. (define (ftp-server/directory package)
  205. "Return the FTP server and directory where PACKAGE's tarball are stored."
  206. (let ((name (package-upstream-name package)))
  207. (values (or (assoc-ref (package-properties package) 'ftp-server)
  208. "ftp.gnu.org")
  209. (or (assoc-ref (package-properties package) 'ftp-directory)
  210. (string-append "/gnu/" name)))))
  211. (define %tarball-rx
  212. ;; The .zip extensions is notably used for freefont-ttf.
  213. ;; The "-src" pattern is for "TeXmacs-1.0.7.9-src.tar.gz".
  214. ;; The "-gnu[0-9]" pattern is for "icecat-38.4.0-gnu1.tar.bz2".
  215. (make-regexp "^([^.]+)-([0-9]|[^-])+(-(src|gnu[0-9]))?\\.(tar\\.|zip$)"))
  216. (define %alpha-tarball-rx
  217. (make-regexp "^.*-.*[0-9](-|~)?(alpha|beta|rc|RC|cvs|svn|git)-?[0-9\\.]*\\.tar\\."))
  218. (define (release-file? project file)
  219. "Return #f if FILE is not a release tarball of PROJECT, otherwise return
  220. true."
  221. (and (not (member (file-extension file) '("sig" "sign" "asc")))
  222. (and=> (regexp-exec %tarball-rx file)
  223. (lambda (match)
  224. ;; Filter out unrelated files, like `guile-www-1.1.1'.
  225. ;; Case-insensitive for things like "TeXmacs" vs. "texmacs".
  226. ;; The "-src" suffix is for "freefont-src-20120503.tar.gz".
  227. (and=> (match:substring match 1)
  228. (lambda (name)
  229. (or (string-ci=? name project)
  230. (string-ci=? name
  231. (string-append project
  232. "-src")))))))
  233. (not (regexp-exec %alpha-tarball-rx file))
  234. (let ((s (tarball-sans-extension file)))
  235. (regexp-exec %package-name-rx s))))
  236. (define (tarball->version tarball)
  237. "Return the version TARBALL corresponds to. TARBALL is a file name like
  238. \"coreutils-8.23.tar.xz\"."
  239. (let-values (((name version)
  240. (gnu-package-name->name+version
  241. (tarball-sans-extension tarball))))
  242. version))
  243. (define* (releases project
  244. #:key
  245. (server "ftp.gnu.org")
  246. (directory (string-append "/gnu/" project)))
  247. "Return the list of <upstream-release> of PROJECT as a list of release
  248. name/directory pairs."
  249. ;; TODO: Parse something like fencepost.gnu.org:/gd/gnuorg/packages-ftp.
  250. (define conn (ftp-open server))
  251. (let loop ((directories (list directory))
  252. (result '()))
  253. (match directories
  254. (()
  255. (ftp-close conn)
  256. (coalesce-sources result))
  257. ((directory rest ...)
  258. (let* ((files (ftp-list conn directory))
  259. (subdirs (filter-map (match-lambda
  260. ((name 'directory . _) name)
  261. (_ #f))
  262. files)))
  263. (define (file->url file)
  264. (string-append "ftp://" server directory "/" file))
  265. (define (file->source file)
  266. (let ((url (file->url file)))
  267. (upstream-source
  268. (package project)
  269. (version (tarball->version file))
  270. (urls (list url))
  271. (signature-urls (list (string-append url ".sig"))))))
  272. (loop (append (map (cut string-append directory "/" <>)
  273. subdirs)
  274. rest)
  275. (append
  276. ;; Filter out signatures, deltas, and files which
  277. ;; are potentially not releases of PROJECT--e.g.,
  278. ;; in /gnu/guile, filter out guile-oops and
  279. ;; guile-www; in mit-scheme, filter out binaries.
  280. (filter-map (match-lambda
  281. ((file 'file . _)
  282. (and (release-file? project file)
  283. (file->source file)))
  284. (_ #f))
  285. files)
  286. result)))))))
  287. (define* (latest-ftp-release project
  288. #:key
  289. (server "ftp.gnu.org")
  290. (directory (string-append "/gnu/" project))
  291. (keep-file? (const #t))
  292. (file->signature (cut string-append <> ".sig"))
  293. (ftp-open ftp-open) (ftp-close ftp-close))
  294. "Return an <upstream-source> for the latest release of PROJECT on SERVER
  295. under DIRECTORY, or #f. Use FTP-OPEN and FTP-CLOSE to open (resp. close) FTP
  296. connections; this can be useful to reuse connections.
  297. KEEP-FILE? is a predicate to decide whether to enter a directory and to
  298. consider a given file (source tarball) as a valid candidate based on its name.
  299. FILE->SIGNATURE must be a procedure; it is passed a source file URL and must
  300. return the corresponding signature URL, or #f it signatures are unavailable."
  301. (define (latest a b)
  302. (if (version>? a b) a b))
  303. (define (latest-release a b)
  304. (if (version>? (upstream-source-version a) (upstream-source-version b))
  305. a b))
  306. (define patch-directory-name?
  307. ;; Return #t for patch directory names such as 'bash-4.2-patches'.
  308. (cut string-suffix? "patches" <>))
  309. (define conn (ftp-open server))
  310. (define (file->url directory file)
  311. (string-append "ftp://" server directory "/" file))
  312. (define (file->source directory file)
  313. (let ((url (file->url directory file)))
  314. (upstream-source
  315. (package project)
  316. (version (tarball->version file))
  317. (urls (list url))
  318. (signature-urls (match (file->signature url)
  319. (#f #f)
  320. (sig (list sig)))))))
  321. (let loop ((directory directory)
  322. (result #f))
  323. (let* ((entries (ftp-list conn directory))
  324. ;; Filter out things like /gnupg/patches. Filter out "w32"
  325. ;; directories as found on ftp.gnutls.org.
  326. (subdirs (filter-map (match-lambda
  327. (((? patch-directory-name? dir)
  328. 'directory . _)
  329. #f)
  330. (("w32" 'directory . _)
  331. #f)
  332. (("unstable" 'directory . _)
  333. ;; As seen at ftp.gnupg.org/gcrypt/pinentry.
  334. #f)
  335. ((directory 'directory . _)
  336. directory)
  337. (_ #f))
  338. entries))
  339. ;; Whether or not SUBDIRS is empty, compute the latest releases
  340. ;; for the current directory. This is necessary for packages
  341. ;; such as 'sharutils' that have a sub-directory that contains
  342. ;; only an older release.
  343. (releases (filter-map (match-lambda
  344. ((file 'file . _)
  345. (and (release-file? project file)
  346. (keep-file? file)
  347. (file->source directory file)))
  348. (_ #f))
  349. entries)))
  350. ;; Assume that SUBDIRS correspond to versions, and jump into the
  351. ;; one with the highest version number.
  352. (let* ((release (reduce latest-release #f
  353. (coalesce-sources releases)))
  354. (result (if (and result release)
  355. (latest-release release result)
  356. (or release result)))
  357. (target (reduce latest #f subdirs)))
  358. (if target
  359. (loop (string-append directory "/" target)
  360. result)
  361. (begin
  362. (ftp-close conn)
  363. result))))))
  364. (define* (latest-release package
  365. #:key
  366. (server "ftp.gnu.org")
  367. (directory (string-append "/gnu/" package)))
  368. "Return the <upstream-source> for the latest version of PACKAGE or #f.
  369. PACKAGE must be the canonical name of a GNU package."
  370. (latest-ftp-release package
  371. #:server server
  372. #:directory directory))
  373. (define-syntax-rule (false-if-ftp-error exp)
  374. "Return #f if an FTP error is raise while evaluating EXP; return the result
  375. of EXP otherwise."
  376. (catch 'ftp-error
  377. (lambda ()
  378. exp)
  379. (lambda (key port . rest)
  380. (if (ftp-connection? port)
  381. (ftp-close port)
  382. (close-port port))
  383. #f)))
  384. (define (latest-release* package)
  385. "Like 'latest-release', but (1) take a <package> object, and (2) ignore FTP
  386. errors that might occur when PACKAGE is not actually a GNU package, or not
  387. hosted on ftp.gnu.org, or not under that name (this is the case for
  388. \"emacs-auctex\", for instance.)"
  389. (let-values (((server directory)
  390. (ftp-server/directory package)))
  391. (false-if-ftp-error (latest-release (package-upstream-name package)
  392. #:server server
  393. #:directory directory))))
  394. ;;;
  395. ;;; Latest HTTP release.
  396. ;;;
  397. (define (html->sxml port)
  398. "Read HTML from PORT and return the corresponding SXML tree."
  399. (let ((str (get-string-all port)))
  400. (catch #t
  401. (lambda ()
  402. ;; XXX: This is the poor developer's HTML-to-XML converter. It's good
  403. ;; enough for directory listings at <https://kernel.org/pub> but if
  404. ;; needed we could resort to (htmlprag) from Guile-Lib.
  405. (call-with-input-string (string-replace-substring str "<hr>" "<hr />")
  406. xml->sxml))
  407. (const '(html))))) ;parse error
  408. (define (html-links sxml)
  409. "Return the list of links found in SXML, the SXML tree of an HTML page."
  410. (let loop ((sxml sxml)
  411. (links '()))
  412. (match sxml
  413. (('a ('@ attributes ...) body ...)
  414. (match (assq 'href attributes)
  415. (#f (fold loop links body))
  416. (('href url) (fold loop (cons url links) body))))
  417. ((tag ('@ _ ...) body ...)
  418. (fold loop links body))
  419. ((tag body ...)
  420. (fold loop links body))
  421. (_
  422. links))))
  423. (define* (latest-html-release package
  424. #:key
  425. (base-url "https://kernel.org/pub")
  426. (directory (string-append "/" package))
  427. (file->signature (cut string-append <> ".sig")))
  428. "Return an <upstream-source> for the latest release of PACKAGE (a string) on
  429. SERVER under DIRECTORY, or #f. BASE-URL should be the URL of an HTML page,
  430. typically a directory listing as found on 'https://kernel.org/pub'.
  431. FILE->SIGNATURE must be a procedure; it is passed a source file URL and must
  432. return the corresponding signature URL, or #f it signatures are unavailable."
  433. (let* ((uri (string->uri (string-append base-url directory "/")))
  434. (port (http-fetch/cached uri #:ttl 3600))
  435. (sxml (html->sxml port)))
  436. (define (url->release url)
  437. (and (string=? url (basename url)) ;relative reference?
  438. (release-file? package url)
  439. (let-values (((name version)
  440. (package-name->name+version
  441. (tarball-sans-extension url)
  442. #\-)))
  443. (upstream-source
  444. (package name)
  445. (version version)
  446. (urls (list (string-append base-url directory "/" url)))
  447. (signature-urls
  448. (list (file->signature
  449. (string-append base-url directory "/" url))))))))
  450. (define candidates
  451. (filter-map url->release (html-links sxml)))
  452. (close-port port)
  453. (match candidates
  454. (() #f)
  455. ((first . _)
  456. ;; Select the most recent release and return it.
  457. (reduce (lambda (r1 r2)
  458. (if (version>? (upstream-source-version r1)
  459. (upstream-source-version r2))
  460. r1 r2))
  461. first
  462. (coalesce-sources candidates))))))
  463. ;;;
  464. ;;; Updaters.
  465. ;;;
  466. (define %gnu-file-list-uri
  467. ;; URI of the file list for ftp.gnu.org.
  468. (string->uri "https://ftp.gnu.org/find.txt.gz"))
  469. (define ftp.gnu.org-files
  470. (mlambda ()
  471. "Return the list of files available at ftp.gnu.org."
  472. ;; XXX: Memoize the whole procedure to work around the fact that
  473. ;; 'http-fetch/cached' caches the gzipped version.
  474. (define (trim-leading-components str)
  475. ;; Trim the leading ".", if any, in "./gnu/foo".
  476. (string-trim str (char-set #\.)))
  477. (define (string->lines str)
  478. (string-tokenize str (char-set-complement (char-set #\newline))))
  479. ;; Since https://ftp.gnu.org honors 'If-Modified-Since', the hard-coded
  480. ;; TTL can be relatively short.
  481. (let ((port (http-fetch/cached %gnu-file-list-uri #:ttl (* 15 60))))
  482. (map trim-leading-components
  483. (call-with-gzip-input-port port
  484. (compose string->lines get-string-all))))))
  485. (define (latest-gnu-release package)
  486. "Return the latest release of PACKAGE, a GNU package available via
  487. ftp.gnu.org.
  488. This method does not rely on FTP access at all; instead, it browses the file
  489. list available from %GNU-FILE-LIST-URI over HTTP(S)."
  490. (let-values (((server directory)
  491. (ftp-server/directory package))
  492. ((name)
  493. (package-upstream-name package)))
  494. (let* ((files (ftp.gnu.org-files))
  495. (relevant (filter (lambda (file)
  496. (and (string-prefix? "/gnu" file)
  497. (string-contains file directory)
  498. (release-file? name (basename file))))
  499. files)))
  500. (match (sort relevant (lambda (file1 file2)
  501. (version>? (tarball-sans-extension
  502. (basename file1))
  503. (tarball-sans-extension
  504. (basename file2)))))
  505. ((and tarballs (reference _ ...))
  506. (let* ((version (tarball->version reference))
  507. (tarballs (filter (lambda (file)
  508. (string=? (tarball-sans-extension
  509. (basename file))
  510. (tarball-sans-extension
  511. (basename reference))))
  512. tarballs)))
  513. (upstream-source
  514. (package name)
  515. (version version)
  516. (urls (map (lambda (file)
  517. (string-append "mirror://gnu/"
  518. (string-drop file
  519. (string-length "/gnu/"))))
  520. tarballs))
  521. (signature-urls (map (cut string-append <> ".sig") urls)))))
  522. (()
  523. #f)))))
  524. (define %package-name-rx
  525. ;; Regexp for a package name, e.g., "foo-X.Y". Since TeXmacs uses
  526. ;; "TeXmacs-X.Y-src", the `-src' suffix is allowed.
  527. (make-regexp "^(.*)-(([0-9]|\\.)+)(-src)?"))
  528. (define (gnu-package-name->name+version name+version)
  529. "Return the package name and version number extracted from NAME+VERSION."
  530. (let ((match (regexp-exec %package-name-rx name+version)))
  531. (if (not match)
  532. (values name+version #f)
  533. (values (match:substring match 1) (match:substring match 2)))))
  534. (define gnome-package?
  535. (url-prefix-predicate "mirror://gnome/"))
  536. (define (pure-gnu-package? package)
  537. "Return true if PACKAGE is a non-Emacs and non-GNOME GNU package. This
  538. excludes AucTeX, for instance, whose releases are now uploaded to
  539. elpa.gnu.org, and all the GNOME packages; EMMS is included though, because its
  540. releases are on gnu.org."
  541. (and (or (not (string-prefix? "emacs-" (package-name package)))
  542. (gnu-hosted? package))
  543. (not (gnome-package? package))
  544. (gnu-package? package)))
  545. (define gnu-hosted?
  546. (url-prefix-predicate "mirror://gnu/"))
  547. (define (url-prefix-rewrite old new)
  548. "Return a one-argument procedure that rewrites URL prefix OLD to NEW."
  549. (lambda (url)
  550. (if (string-prefix? old url)
  551. (string-append new (string-drop url (string-length old)))
  552. url)))
  553. (define (adjusted-upstream-source source rewrite-url)
  554. "Rewrite URLs in SOURCE by apply REWRITE-URL to each of them."
  555. (upstream-source
  556. (inherit source)
  557. (urls (map rewrite-url (upstream-source-urls source)))
  558. (signature-urls (and=> (upstream-source-signature-urls source)
  559. (lambda (urls)
  560. (map rewrite-url urls))))))
  561. (define savannah-package?
  562. (url-prefix-predicate "mirror://savannah/"))
  563. (define %savannah-base
  564. ;; One of the Savannah mirrors listed at
  565. ;; <http://download0.savannah.gnu.org/mirmon/savannah/> that serves valid
  566. ;; HTML (unlike <https://download.savannah.nongnu.org/releases>.)
  567. "https://nongnu.freemirror.org/nongnu")
  568. (define (latest-savannah-release package)
  569. "Return the latest release of PACKAGE."
  570. (let* ((uri (string->uri
  571. (match (origin-uri (package-source package))
  572. ((? string? uri) uri)
  573. ((uri mirrors ...) uri))))
  574. (package (package-upstream-name package))
  575. (directory (dirname (uri-path uri)))
  576. (rewrite (url-prefix-rewrite %savannah-base
  577. "mirror://savannah")))
  578. ;; Note: We use the default 'file->signature', which adds ".sig", but not
  579. ;; all projects on Savannah follow that convention: some use ".asc" and
  580. ;; perhaps some lack signatures altogether.
  581. (and=> (latest-html-release package
  582. #:base-url %savannah-base
  583. #:directory directory)
  584. (cut adjusted-upstream-source <> rewrite))))
  585. (define (latest-xorg-release package)
  586. "Return the latest release of PACKAGE."
  587. (let ((uri (string->uri (origin-uri (package-source package)))))
  588. (false-if-ftp-error
  589. (latest-ftp-release
  590. (package-name package)
  591. #:server "ftp.freedesktop.org"
  592. #:directory
  593. (string-append "/pub/xorg/" (dirname (uri-path uri)))))))
  594. (define (latest-kernel.org-release package)
  595. "Return the latest release of PACKAGE, the name of a kernel.org package."
  596. (define %kernel.org-base
  597. ;; This URL and sub-directories thereof are nginx-generated directory
  598. ;; listings suitable for 'latest-html-release'.
  599. "https://mirrors.edge.kernel.org/pub")
  600. (define (file->signature file)
  601. (string-append (file-sans-extension file) ".sign"))
  602. (let* ((uri (string->uri
  603. (match (origin-uri (package-source package))
  604. ((? string? uri) uri)
  605. ((uri mirrors ...) uri))))
  606. (package (package-upstream-name package))
  607. (directory (dirname (uri-path uri)))
  608. (rewrite (url-prefix-rewrite %kernel.org-base
  609. "mirror://kernel.org")))
  610. (and=> (latest-html-release package
  611. #:base-url %kernel.org-base
  612. #:directory directory
  613. #:file->signature file->signature)
  614. (cut adjusted-upstream-source <> rewrite))))
  615. (define %gnu-updater
  616. ;; This is for everything at ftp.gnu.org.
  617. (upstream-updater
  618. (name 'gnu)
  619. (description "Updater for GNU packages")
  620. (pred gnu-hosted?)
  621. (latest latest-gnu-release)))
  622. (define %gnu-ftp-updater
  623. ;; This is for GNU packages taken from alternate locations, such as
  624. ;; alpha.gnu.org, ftp.gnupg.org, etc. It is obsolescent.
  625. (upstream-updater
  626. (name 'gnu-ftp)
  627. (description "Updater for GNU packages only available via FTP")
  628. (pred (lambda (package)
  629. (and (not (gnu-hosted? package))
  630. (pure-gnu-package? package))))
  631. (latest latest-release*)))
  632. (define %savannah-updater
  633. (upstream-updater
  634. (name 'savannah)
  635. (description "Updater for packages hosted on savannah.gnu.org")
  636. (pred (url-prefix-predicate "mirror://savannah/"))
  637. (latest latest-savannah-release)))
  638. (define %xorg-updater
  639. (upstream-updater
  640. (name 'xorg)
  641. (description "Updater for X.org packages")
  642. (pred (url-prefix-predicate "mirror://xorg/"))
  643. (latest latest-xorg-release)))
  644. (define %kernel.org-updater
  645. (upstream-updater
  646. (name 'kernel.org)
  647. (description "Updater for packages hosted on kernel.org")
  648. (pred (url-prefix-predicate "mirror://kernel.org/"))
  649. (latest latest-kernel.org-release)))
  650. ;;; gnu-maintenance.scm ends here