gnome.scm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  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 import gnome)
  20. #:use-module (guix upstream)
  21. #:use-module (guix utils)
  22. #:use-module (guix packages)
  23. #:use-module (guix http-client)
  24. #:use-module (json)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-11)
  27. #:use-module (srfi srfi-26)
  28. #:use-module (srfi srfi-34)
  29. #:use-module (web uri)
  30. #:use-module (ice-9 match)
  31. #:use-module (ice-9 regex)
  32. #:export (%gnome-updater))
  33. ;;; Commentary:
  34. ;;;
  35. ;;; This package provides not an actual importer but simply an updater for
  36. ;;; GNOME packages. It grabs package meta-data from 'cache.json' files
  37. ;;; available on ftp.gnome.org.
  38. ;;;
  39. ;;; Code:
  40. (define (jsonish->upstream-source name jsonish)
  41. "Return an <upstream-source> object for package NAME, using JSONISH as the
  42. source for metadata."
  43. (match jsonish
  44. ((version . dictionary)
  45. (upstream-source
  46. (package name)
  47. (version version)
  48. (urls (filter-map (lambda (extension)
  49. (match (assoc-ref dictionary extension)
  50. (#f
  51. #f)
  52. ((? string? relative-url)
  53. (string-append "mirror://gnome/sources/"
  54. name "/" relative-url))))
  55. '("tar.lz" "tar.xz" "tar.bz2" "tar.gz")))))))
  56. (define (latest-gnome-release package)
  57. "Return the latest release of PACKAGE, a GNOME package, or #f if it could
  58. not be determined."
  59. (define %not-dot
  60. (char-set-complement (char-set #\.)))
  61. (define (pre-release-text? text)
  62. (string-match "^(alpha|beta|rc)" text))
  63. (define (release-version? version)
  64. "Predicate to check if VERSION matches the format of a GNOME release
  65. version. A release version can have more than one form, depending on the
  66. GNOME component, but typically it takes the form of a major-minor tuple, where
  67. minor can also be prefixed wih \"alpha\", \"beta\" or \"rc\". For more
  68. information about the GNOME versioning scheme, see:
  69. https://discourse.gnome.org/t/new-gnome-versioning-scheme/4235"
  70. (define components (string-tokenize version %not-dot))
  71. (if (any pre-release-text? components)
  72. #f ;ignore pre-releases
  73. (match components
  74. (((= string->number major) (= string->number minor) . _)
  75. ;; Any other 3+ components versions such as "2.72.2".
  76. (and major minor))
  77. (((= string->number major) . _)
  78. ;; A GNOME version strings like "42.1".
  79. major))))
  80. (define upstream-name
  81. ;; Some packages like "NetworkManager" have camel-case names.
  82. (package-upstream-name package))
  83. (guard (c ((http-get-error? c)
  84. (if (= 404 (http-get-error-code c))
  85. #f
  86. (raise c))))
  87. (let* ((port (http-fetch/cached
  88. (string->uri (string-append
  89. "https://ftp.gnome.org/pub/gnome/sources/"
  90. upstream-name "/cache.json"))
  91. ;; ftp.gnome.org supports 'if-Modified-Since', so the local
  92. ;; cache can expire early.
  93. #:ttl (* 60 10)
  94. ;; Hide messages about URL redirects.
  95. #:log-port (%make-void-port "w")))
  96. (json (json->scm port)))
  97. (close-port port)
  98. (match json
  99. (#(4 releases _ ...)
  100. (let* ((releases (assoc-ref releases upstream-name))
  101. (latest (fold (match-lambda*
  102. (((key . value) result)
  103. (cond ((release-version? key)
  104. (match result
  105. (#f
  106. (cons key value))
  107. ((newest . _)
  108. (if (version>? key newest)
  109. (cons key value)
  110. result))))
  111. (else
  112. result))))
  113. #f
  114. releases)))
  115. (and latest
  116. (jsonish->upstream-source upstream-name latest))))))))
  117. (define %gnome-updater
  118. (upstream-updater
  119. (name 'gnome)
  120. (description "Updater for GNOME packages")
  121. (pred (url-prefix-predicate "mirror://gnome/"))
  122. (latest latest-gnome-release)))