gnu: emacs-org: Update to 9.4.
[jackhill/guix/guix.git] / guix / build-system / clojure.scm
CommitLineData
df730f67
AV
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
984efa2b 3;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
df730f67
AV
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 clojure)
21 #:use-module (guix build clojure-utils)
22 #:use-module (guix build-system)
23 #:use-module (guix build-system ant)
24 #:use-module ((guix build-system gnu)
25 #:select (standard-packages)
26 #:prefix gnu:)
27
28 #:use-module (guix derivations)
29 #:use-module (guix packages)
30 #:use-module ((guix search-paths)
31 #:select
32 ((search-path-specification->sexp . search-path-spec->sexp)))
33 #:use-module (guix utils)
34
35 #:use-module (ice-9 match)
36 #:export (%clojure-build-system-modules
37 clojure-build
38 clojure-build-system))
39
40;; Commentary:
41;;
42;; Standard build procedure for Clojure packages.
43;;
44;; Code:
45
46(define-with-docs %clojure-build-system-modules
984efa2b 47 "Build-side modules imported by default."
df730f67
AV
48 `((guix build clojure-build-system)
49 (guix build clojure-utils)
50 (guix build guile-build-system)
51 ,@%ant-build-system-modules))
52
984efa2b
LC
53(define %default-modules
54 ;; Modules in scope in the build-side environment.
55 '((guix build clojure-build-system)
56 (guix build clojure-utils)
57 (guix build utils)))
58
df730f67
AV
59(define-with-docs %default-clojure
60 "The default Clojure package."
3fe6fcc4 61 (delay (@* (gnu packages clojure) clojure)))
df730f67
AV
62
63(define-with-docs %default-jdk
64 "The default JDK package."
65 (delay (@* (gnu packages java) icedtea)))
66
67(define-with-docs %default-zip
68 "The default ZIP package."
69 (delay (@* (gnu packages compression) zip)))
70
71(define* (lower name
72 #:key
73 source target
74 inputs native-inputs
75 (clojure (force %default-clojure))
76 (jdk (force %default-jdk))
77 (zip (force %default-zip))
78 outputs system
79 #:allow-other-keys
80 #:rest arguments)
81 "Return a bag for NAME."
82 (let ((private-keywords '(#:source #:target
83 #:inputs #:native-inputs
84 #:clojure #:jdk #:zip)))
85
86 (if target
87 (error "No cross-compilation for clojure-build-system yet: LOWER"
88 target) ; FIXME
89 (bag (name name)
90 (system system)
91 (host-inputs `(,@(if source
92 `(("source" ,source))
93 '())
94 ,@inputs
95 ,@(gnu:standard-packages)))
96 (build-inputs `(("clojure" ,clojure)
97 ("jdk" ,jdk "jdk")
98 ("zip" ,zip)
99 ,@native-inputs))
100 (outputs outputs)
101 (build clojure-build)
102 (arguments (strip-keyword-arguments private-keywords
103 arguments))))))
104
105(define-with-docs source->output-path
106 "Convert source input to output path."
107 (match-lambda
108 (((? derivation? source))
109 (derivation->output-path source))
110 ((source)
111 source)
112 (source
113 source)))
114
115(define-with-docs maybe-guile->guile
116 "Find the right guile."
117 (match-lambda
118 ((and maybe-guile (? package?))
119 maybe-guile)
120 (#f ; default
121 (@* (gnu packages commencement) guile-final))))
122
123(define* (clojure-build store name inputs
124 #:key
125 (source-dirs `',%source-dirs)
126 (test-dirs `',%test-dirs)
127 (compile-dir %compile-dir)
128
129 (jar-names `',(package-name->jar-names name))
130 (main-class %main-class)
131 (omit-source? %omit-source?)
132
133 (aot-include `',%aot-include)
134 (aot-exclude `',%aot-exclude)
135
136 doc-dirs ; no sensible default
137 (doc-regex %doc-regex)
138
139 (tests? %tests?)
140 (test-include `',%test-include)
141 (test-exclude `',%test-exclude)
142
984efa2b 143 (phases '%standard-phases)
df730f67
AV
144 (outputs '("out"))
145 (search-paths '())
146 (system (%current-system))
147 (guile #f)
148
149 (imported-modules %clojure-build-system-modules)
984efa2b 150 (modules %default-modules))
df730f67
AV
151 "Build SOURCE with INPUTS."
152 (let ((builder `(begin
153 (use-modules ,@modules)
154 (clojure-build #:name ,name
155 #:source ,(source->output-path
156 (assoc-ref inputs "source"))
157
158 #:source-dirs ,source-dirs
159 #:test-dirs ,test-dirs
160 #:compile-dir ,compile-dir
161
162 #:jar-names ,jar-names
163 #:main-class ,main-class
164 #:omit-source? ,omit-source?
165
166 #:aot-include ,aot-include
167 #:aot-exclude ,aot-exclude
168
169 #:doc-dirs ,doc-dirs
170 #:doc-regex ,doc-regex
171
172 #:tests? ,tests?
173 #:test-include ,test-include
174 #:test-exclude ,test-exclude
175
176 #:phases ,phases
177 #:outputs %outputs
178 #:search-paths ',(map search-path-spec->sexp
179 search-paths)
180 #:system ,system
181 #:inputs %build-inputs)))
182
183 (guile-for-build (package-derivation store
184 (maybe-guile->guile guile)
185 system
186 #:graft? #f)))
187
188 (build-expression->derivation store name builder
189 #:inputs inputs
190 #:system system
191 #:modules imported-modules
192 #:outputs outputs
193 #:guile-for-build guile-for-build)))
194
195(define clojure-build-system
196 (build-system
197 (name 'clojure)
198 (description "Simple Clojure build system using plain old 'compile'")
199 (lower lower)))
200
201;;; clojure.scm ends here