gnu: emacs-irony-mode: Fetch source using git.
[guix.git] / guix / build-system / r.scm
blob664515d0ee9b3f761a09fd2ba4e8eaf54fb44f84
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
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 build-system r)
20   #:use-module (guix store)
21   #:use-module (guix utils)
22   #:use-module (guix packages)
23   #:use-module (guix derivations)
24   #:use-module (guix search-paths)
25   #:use-module (guix build-system)
26   #:use-module (guix build-system gnu)
27   #:use-module (ice-9 match)
28   #:use-module (srfi srfi-26)
29   #:export (%r-build-system-modules
30             r-build
31             r-build-system
32             cran-uri
33             bioconductor-uri))
35 ;; Commentary:
37 ;; Standard build procedure for R packages.
39 ;; Code:
41 (define (cran-uri name version)
42   "Return a list of URI strings for the R package archive on CRAN for the
43 release corresponding to NAME and VERSION.  As only the most recent version is
44 available via the first URI, the second URI points to the archived version."
45   (list (string-append "mirror://cran/src/contrib/"
46                        name "_" version ".tar.gz")
47         (string-append "mirror://cran/src/contrib/Archive/"
48                        name "/" name "_" version ".tar.gz")))
50 (define (bioconductor-uri name version)
51   "Return a URI string for the R package archive on Bioconductor for the
52 release corresponding to NAME and VERSION."
53   (list (string-append "https://bioconductor.org/packages/release/bioc/src/contrib/"
54                        name "_" version ".tar.gz")
55         ;; TODO: use %bioconductor-version from (guix import cran)
56         (string-append "https://bioconductor.org/packages/3.8/bioc/src/contrib/Archive/"
57                        name "_" version ".tar.gz")))
59 (define %r-build-system-modules
60   ;; Build-side modules imported by default.
61   `((guix build r-build-system)
62     ,@%gnu-build-system-modules))
64 (define (default-r)
65   "Return the default R package."
66   ;; Lazily resolve the binding to avoid a circular dependency.
67   (let ((r-mod (resolve-interface '(gnu packages statistics))))
68     (module-ref r-mod 'r-minimal)))
70 (define* (lower name
71                 #:key source inputs native-inputs outputs system target
72                 (r (default-r))
73                 #:allow-other-keys
74                 #:rest arguments)
75   "Return a bag for NAME."
76   (define private-keywords
77     '(#:source #:target #:r #:inputs #:native-inputs))
79   (and (not target)                               ;XXX: no cross-compilation
80        (bag
81          (name name)
82          (system system)
83          (host-inputs `(,@(if source
84                               `(("source" ,source))
85                               '())
86                         ,@inputs
88                         ;; Keep the standard inputs of 'gnu-build-system'.
89                         ,@(standard-packages)))
90          (build-inputs `(("r" ,r)
91                          ,@native-inputs))
92          (outputs outputs)
93          (build r-build)
94          (arguments (strip-keyword-arguments private-keywords arguments)))))
96 (define* (r-build store name inputs
97                   #:key
98                   (tests? #t)
99                   (test-target "tests")
100                   (configure-flags ''())
101                   (phases '(@ (guix build r-build-system)
102                               %standard-phases))
103                   (outputs '("out"))
104                   (search-paths '())
105                   (system (%current-system))
106                   (guile #f)
107                   (substitutable? #t)
108                   (imported-modules %r-build-system-modules)
109                   (modules '((guix build r-build-system)
110                              (guix build utils))))
111   "Build SOURCE with INPUTS."
112   (define builder
113     `(begin
114        (use-modules ,@modules)
115        (r-build #:name ,name
116                 #:source ,(match (assoc-ref inputs "source")
117                             (((? derivation? source))
118                              (derivation->output-path source))
119                             ((source)
120                              source)
121                             (source
122                              source))
123                 #:configure-flags ,configure-flags
124                 #:system ,system
125                 #:tests? ,tests?
126                 #:test-target ,test-target
127                 #:phases ,phases
128                 #:outputs %outputs
129                 #:search-paths ',(map search-path-specification->sexp
130                                       search-paths)
131                 #:inputs %build-inputs)))
133   (define guile-for-build
134     (match guile
135       ((? package?)
136        (package-derivation store guile system #:graft? #f))
137       (#f                                         ; the default
138        (let* ((distro (resolve-interface '(gnu packages commencement)))
139               (guile  (module-ref distro 'guile-final)))
140          (package-derivation store guile system #:graft? #f)))))
142   (build-expression->derivation store name builder
143                                 #:inputs inputs
144                                 #:system system
145                                 #:modules imported-modules
146                                 #:outputs outputs
147                                 #:guile-for-build guile-for-build
148                                 #:substitutable? substitutable?))
150 (define r-build-system
151   (build-system
152     (name 'r)
153     (description "The standard R build system")
154     (lower lower)))
156 ;;; r.scm ends here