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