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