build-system/ruby: Add #:gem-flags parameter.
[guix.git] / guix / build-system / ruby.scm
blob135eda665b7414d67d403aaaeab2d9cf5381a070
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
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/>.
20 (define-module (guix build-system ruby)
21   #:use-module (guix store)
22   #:use-module (guix utils)
23   #:use-module (guix packages)
24   #:use-module (guix derivations)
25   #:use-module (guix search-paths)
26   #:use-module (guix build-system)
27   #:use-module (guix build-system gnu)
28   #:use-module (ice-9 match)
29   #:export (%ruby-build-system-modules
30             ruby-build
31             ruby-build-system))
33 (define %ruby-build-system-modules
34   ;; Build-side modules imported by default.
35   `((guix build ruby-build-system)
36     ,@%gnu-build-system-modules))
38 (define (default-ruby)
39   "Return the default Ruby package."
40   ;; Lazily resolve the binding to avoid a circular dependency.
41   (let ((ruby (resolve-interface '(gnu packages ruby))))
42     (module-ref ruby 'ruby)))
44 (define* (lower name
45                 #:key source inputs native-inputs outputs system target
46                 (ruby (default-ruby))
47                 #:allow-other-keys
48                 #:rest arguments)
49   "Return a bag for NAME."
50   (define private-keywords
51     '(#:source #:target #:ruby #:inputs #:native-inputs))
53   (let ((version-control (resolve-interface '(gnu packages version-control))))
54     (and (not target)                    ;XXX: no cross-compilation
55          (bag
56            (name name)
57            (system system)
58            (host-inputs `(,@(if source
59                                 `(("source" ,source))
60                                 '())
61                           ,@inputs
63                           ;; Keep the standard inputs of 'gnu-build-system'.
64                           ,@(standard-packages)))
65            (build-inputs `(("ruby" ,ruby)
66                            ("git" ,(module-ref version-control 'git))
67                            ,@native-inputs))
68            (outputs outputs)
69            (build ruby-build)
70            (arguments (strip-keyword-arguments private-keywords arguments))))))
72 (define* (ruby-build store name inputs
73                      #:key
74                      (gem-flags ''())
75                      (test-target "test")
76                      (tests? #t)
77                      (phases '(@ (guix build ruby-build-system)
78                                  %standard-phases))
79                      (outputs '("out"))
80                      (search-paths '())
81                      (system (%current-system))
82                      (guile #f)
83                      (imported-modules %ruby-build-system-modules)
84                      (modules '((guix build ruby-build-system)
85                                 (guix build utils))))
86   "Build SOURCE using RUBY and INPUTS."
87   (define builder
88     `(begin
89        (use-modules ,@modules)
90        (ruby-build #:name ,name
91                    #:source ,(match (assoc-ref inputs "source")
92                                (((? derivation? source))
93                                 (derivation->output-path source))
94                                ((source)
95                                 source)
96                                (source
97                                 source))
98                    #:system ,system
99                    #:gem-flags ,gem-flags
100                    #:test-target ,test-target
101                    #:tests? ,tests?
102                    #:phases ,phases
103                    #:outputs %outputs
104                    #:search-paths ',(map search-path-specification->sexp
105                                          search-paths)
106                    #:inputs %build-inputs)))
108   (define guile-for-build
109     (match guile
110       ((? package?)
111        (package-derivation store guile system #:graft? #f))
112       (#f
113        (let* ((distro (resolve-interface '(gnu packages commencement)))
114               (guile  (module-ref distro 'guile-final)))
115          (package-derivation store guile system #:graft? #f)))))
117   (build-expression->derivation store name builder
118                                 #:inputs inputs
119                                 #:system system
120                                 #:modules imported-modules
121                                 #:outputs outputs
122                                 #:guile-for-build guile-for-build))
124 (define ruby-build-system
125   (build-system
126     (name 'ruby)
127     (description "The standard Ruby build system")
128     (lower lower)))