Commit | Line | Data |
---|---|---|
7047133f | 1 | ;;; GNU Guix --- Functional package management for GNU |
14959038 | 2 | ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
7047133f LC |
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/>. | |
18 | ||
19 | (define-module (guix import gnu) | |
20 | #:use-module (guix gnu-maintenance) | |
1ff2619b | 21 | #:use-module (guix import utils) |
7047133f LC |
22 | #:use-module (guix utils) |
23 | #:use-module (guix store) | |
ca719424 | 24 | #:use-module (gcrypt hash) |
7047133f | 25 | #:use-module (guix base32) |
3195e19d | 26 | #:use-module (guix upstream) |
7047133f LC |
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) | |
3195e19d | 32 | #:use-module (web uri) |
7047133f LC |
33 | #:use-module (ice-9 match) |
34 | #:use-module (ice-9 regex) | |
35 | #:export (gnu->guix-package)) | |
36 | ||
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: | |
43 | ||
7047133f LC |
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)) | |
49 | ||
50 | (define (preferred-archive-type release) | |
51 | "Return the preferred type of archive for downloading RELEASE." | |
3195e19d | 52 | (find (cute member <> (upstream-source-archive-types release)) |
7047133f LC |
53 | '("xz" "lz" "bz2" "tbz2" "gz" "tgz" "Z"))) |
54 | ||
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 | |
14959038 LC |
58 | <gnu-package>), or #f upon failure. Use KEY-DOWNLOAD as the OpenPGP key |
59 | download policy (see 'download-tarball' for details.)" | |
7047133f LC |
60 | (define name |
61 | (gnu-package-name package)) | |
62 | ||
63 | (define url-base | |
64 | ;; XXX: We assume that RELEASE's directory starts with "/gnu". | |
3195e19d LC |
65 | (string-append "mirror:/" |
66 | (match (upstream-source-urls release) | |
67 | ((url rest ...) | |
68 | (dirname (uri-path (string->uri url))))) | |
7047133f LC |
69 | "/" name "-")) |
70 | ||
71 | (define archive-type | |
72 | (preferred-archive-type release)) | |
73 | ||
3195e19d LC |
74 | (define url |
75 | (find (cut string-suffix? archive-type <>) | |
76 | (upstream-source-urls release))) | |
77 | ||
78 | (define sig-url | |
79 | (find (cute string-suffix? (string-append archive-type ".sig") <>) | |
80 | (upstream-source-signature-urls release))) | |
81 | ||
14959038 LC |
82 | (with-store store |
83 | (match (download-tarball store url sig-url | |
84 | #:key-download key-download) | |
85 | ((? string? tarball) | |
86 | `(package | |
87 | (name ,name) | |
88 | (version ,(upstream-source-version release)) | |
89 | (source (origin | |
90 | (method url-fetch) | |
91 | (uri (string-append ,url-base version | |
92 | ,(string-append ".tar." archive-type))) | |
93 | (sha256 | |
94 | (base32 | |
95 | ,(bytevector->nix-base32-string | |
96 | (file-sha256 tarball)))))) | |
97 | (build-system gnu-build-system) | |
98 | (synopsis ,(gnu-package-doc-summary package)) | |
99 | (description ,(gnu-package-doc-description package)) | |
100 | (home-page ,(match (gnu-package-doc-urls package) | |
101 | ((head . tail) (qualified-url head)))) | |
102 | (license find-by-yourself!))) | |
103 | (#f ;failure to download or authenticate the tarball | |
104 | #f)))) | |
7047133f LC |
105 | |
106 | (define* (gnu->guix-package name | |
107 | #:key (key-download 'interactive)) | |
108 | "Return the package declaration for NAME as an s-expression. Use | |
109 | KEY-DOWNLOAD as the OpenPGP key download policy (see 'download-tarball' for | |
110 | details.)" | |
111 | (match (latest-release name) | |
3195e19d LC |
112 | ((? upstream-source? release) |
113 | (let ((version (upstream-source-version release))) | |
dc794a72 LC |
114 | (match (find-package name) |
115 | (#f | |
7047133f LC |
116 | (raise (condition |
117 | (&message | |
dc794a72 LC |
118 | (message "couldn't find meta-data for GNU package"))))) |
119 | (info | |
120 | (gnu-package->sexp info release #:key-download key-download))))) | |
7047133f LC |
121 | (_ |
122 | (raise (condition | |
123 | (&message | |
124 | (message | |
125 | "failed to determine latest release of GNU package"))))))) | |
126 | ||
127 | ;;; gnu.scm ends here |