gnu: scmutils: Generate 'scmutils-autoloads.el' file.
[guix.git] / guix / import / gnu.scm
blob834f0ae5cfc76e4772adcaffc98e8d3806e7803b
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix import gnu)
20   #:use-module (guix gnu-maintenance)
21   #:use-module (guix import utils)
22   #:use-module (guix utils)
23   #:use-module (guix store)
24   #:use-module (guix hash)
25   #:use-module (guix base32)
26   #:use-module (guix upstream)
27   #:use-module (srfi srfi-1)
28   #:use-module (srfi srfi-11)
29   #:use-module (srfi srfi-26)
30   #:use-module (srfi srfi-34)
31   #:use-module (srfi srfi-35)
32   #:use-module (web uri)
33   #:use-module (ice-9 match)
34   #:use-module (ice-9 regex)
35   #:export (gnu->guix-package))
37 ;;; Commentary:
38 ;;;
39 ;;; Generate a package declaration template for the latest version of a GNU
40 ;;; package, using meta-data available upstream for the package.
41 ;;;
42 ;;; Code:
44 (define (qualified-url url)
45   "Return a fully-qualified URL based on URL."
46   (if (string-prefix? "/" url)
47       (string-append "http://www.gnu.org" url)
48       url))
50 (define (preferred-archive-type release)
51   "Return the preferred type of archive for downloading RELEASE."
52   (find (cute member <> (upstream-source-archive-types release))
53         '("xz" "lz" "bz2" "tbz2" "gz" "tgz" "Z")))
55 (define* (gnu-package->sexp package release
56                             #:key (key-download 'interactive))
57   "Return the 'package' sexp for the RELEASE (a <gnu-release>) of PACKAGE (a
58 <gnu-package>).  Use KEY-DOWNLOAD as the OpenPGP key download policy (see
59 'download-tarball' for details.)"
60   (define name
61     (gnu-package-name package))
63   (define url-base
64     ;; XXX: We assume that RELEASE's directory starts with "/gnu".
65     (string-append "mirror:/"
66                    (match (upstream-source-urls release)
67                      ((url rest ...)
68                       (dirname (uri-path (string->uri url)))))
69                    "/" name "-"))
71   (define archive-type
72     (preferred-archive-type release))
74   (define url
75     (find (cut string-suffix? archive-type <>)
76           (upstream-source-urls release)))
78   (define sig-url
79     (find (cute string-suffix? (string-append archive-type ".sig") <>)
80           (upstream-source-signature-urls release)))
82   (let ((tarball (with-store store
83                    (download-tarball store url sig-url
84                                      #:key-download key-download))))
85     `(package
86        (name ,name)
87        (version ,(upstream-source-version release))
88        (source (origin
89                  (method url-fetch)
90                  (uri (string-append ,url-base version
91                                      ,(string-append ".tar." archive-type)))
92                  (sha256
93                   (base32
94                    ,(bytevector->nix-base32-string (file-sha256 tarball))))))
95        (build-system gnu-build-system)
96        (synopsis ,(gnu-package-doc-summary package))
97        (description ,(gnu-package-doc-description package))
98        (home-page ,(match (gnu-package-doc-urls package)
99                      ((head . tail) (qualified-url head))))
100        (license find-by-yourself!))))
102 (define* (gnu->guix-package name
103                             #:key (key-download 'interactive))
104   "Return the package declaration for NAME as an s-expression.  Use
105 KEY-DOWNLOAD as the OpenPGP key download policy (see 'download-tarball' for
106 details.)"
107   (match (latest-release name)
108     ((? upstream-source? release)
109      (let ((version (upstream-source-version release)))
110        (match (find-packages (regexp-quote name))
111          ((info . _)
112           (gnu-package->sexp info release #:key-download key-download))
113          (()
114           (raise (condition
115                   (&message
116                    (message "couldn't find meta-data for GNU package"))))))))
117     (_
118      (raise (condition
119              (&message
120               (message
121                "failed to determine latest release of GNU package")))))))
123 ;;; gnu.scm ends here