import cran: Automatically add gfortran and zlib when needed.
[jackhill/guix/guix.git] / guix / scripts / import / cran.scm
CommitLineData
e1248602
RW
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
3;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
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
20(define-module (guix scripts import cran)
21 #:use-module (guix ui)
22 #:use-module (guix utils)
88981dd3 23 #:use-module (guix scripts)
e1248602
RW
24 #:use-module (guix import cran)
25 #:use-module (guix scripts import)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-11)
28 #:use-module (srfi srfi-37)
64ce53eb 29 #:use-module (srfi srfi-41)
e1248602
RW
30 #:use-module (ice-9 match)
31 #:use-module (ice-9 format)
32 #:export (guix-import-cran))
33
34\f
35;;;
36;;; Command-line options.
37;;;
38
39(define %default-options
40 '())
41
42(define (show-help)
43 (display (_ "Usage: guix import cran PACKAGE-NAME
44Import and convert the CRAN package for PACKAGE-NAME.\n"))
d0bd632f
RW
45 (display (_ "
46 -a, --archive=ARCHIVE specify the archive repository"))
e1248602
RW
47 (display (_ "
48 -h, --help display this help and exit"))
49 (display (_ "
50 -V, --version display version information and exit"))
51 (newline)
52 (show-bug-report-information))
53
54(define %options
55 ;; Specification of the command-line options.
56 (cons* (option '(#\h "help") #f #f
57 (lambda args
58 (show-help)
59 (exit 0)))
60 (option '(#\V "version") #f #f
61 (lambda args
62 (show-version-and-exit "guix import cran")))
d0bd632f
RW
63 (option '(#\a "archive") #t #f
64 (lambda (opt name arg result)
65 (alist-cons 'repo (string->symbol arg)
66 (alist-delete 'repo result))))
64ce53eb
RW
67 (option '(#\r "recursive") #f #f
68 (lambda (opt name arg result)
69 (alist-cons 'recursive #t result)))
e1248602
RW
70 %standard-import-options))
71
72\f
73;;;
74;;; Entry point.
75;;;
76
77(define (guix-import-cran . args)
78 (define (parse-options)
79 ;; Return the alist of option values.
80 (args-fold* args %options
81 (lambda (opt name arg result)
82 (leave (_ "~A: unrecognized option~%") name))
83 (lambda (arg result)
84 (alist-cons 'argument arg result))
85 %default-options))
86
87 (let* ((opts (parse-options))
88 (args (filter-map (match-lambda
89 (('argument . value)
90 value)
91 (_ #f))
92 (reverse opts))))
93 (match args
94 ((package-name)
64ce53eb
RW
95 (if (assoc-ref opts 'recursive)
96 ;; Recursive import
97 (map (match-lambda
98 ((and ('package ('name name) . rest) pkg)
99 `(define-public ,(string->symbol name)
100 ,pkg))
101 (_ #f))
102 (stream->list (recursive-import package-name
103 (or (assoc-ref opts 'repo) 'cran))))
104 ;; Single import
105 (let ((sexp (cran->guix-package package-name
106 (or (assoc-ref opts 'repo) 'cran))))
107 (unless sexp
108 (leave (_ "failed to download description for package '~a'~%")
109 package-name))
110 sexp)))
e1248602
RW
111 (()
112 (leave (_ "too few arguments~%")))
113 ((many ...)
114 (leave (_ "too many arguments~%"))))))