gnu: r-igraph: Move to (gnu packages cran).
[jackhill/guix/guix.git] / guix / build / clojure-build-system.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
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 clojure-build-system)
20 #:use-module ((guix build ant-build-system)
21 #:select ((%standard-phases . %standard-phases@ant)
22 ant-build))
23 #:use-module (guix build clojure-utils)
24 #:use-module (guix build java-utils)
25 #:use-module (guix build utils)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-26)
28 #:export (%standard-phases
29 clojure-build))
30
31 ;; Commentary:
32 ;;
33 ;; Builder-side code of the standard build procedure for Clojure packages.
34 ;;
35 ;; Code:
36
37 (define* (build #:key
38 source-dirs compile-dir
39 jar-names main-class omit-source?
40 aot-include aot-exclude
41 #:allow-other-keys)
42 "Standard 'build' phase for clojure-build-system."
43 (let* ((libs (append-map find-clojure-libs source-dirs))
44 (libs* (include-list\exclude-list aot-include
45 aot-exclude
46 #:all-list libs)))
47 (mkdir-p compile-dir)
48 (eval-with-clojure `(run! compile ',libs*)
49 source-dirs)
50 (let ((source-dir-files-alist (map (lambda (dir)
51 (cons dir (find-files* dir)))
52 source-dirs))
53 ;; workaround transitive compilation in Clojure
54 (classes (filter (lambda (class)
55 (any (cut compiled-from? class <>)
56 libs*))
57 (find-files* compile-dir))))
58 (for-each (cut create-jar <> (cons (cons compile-dir classes)
59 (if omit-source?
60 '()
61 source-dir-files-alist))
62 #:main-class main-class)
63 jar-names)
64 #t)))
65
66 (define* (check #:key
67 test-dirs
68 jar-names
69 tests? test-include test-exclude
70 #:allow-other-keys)
71 "Standard 'check' phase for clojure-build-system. Note that TEST-EXCLUDE has
72 priority over TEST-INCLUDE."
73 (if tests?
74 (let* ((libs (append-map find-clojure-libs test-dirs))
75 (libs* (include-list\exclude-list test-include
76 test-exclude
77 #:all-list libs)))
78 (for-each (lambda (jar)
79 (eval-with-clojure `(do (apply require
80 '(clojure.test ,@libs*))
81 (apply clojure.test/run-tests
82 ',libs*))
83 (cons jar test-dirs)))
84 jar-names)))
85 #t)
86
87 (define-with-docs install
88 "Standard 'install' phase for clojure-build-system."
89 (install-jars "./"))
90
91 (define-with-docs %standard-phases
92 "Standard build phases for clojure-build-system."
93 (modify-phases %standard-phases@ant
94 (replace 'build build)
95 (replace 'check check)
96 (replace 'install install)
97 (add-after 'install-license-files 'install-doc install-doc)))
98
99 (define* (clojure-build #:key
100 inputs
101 (phases %standard-phases)
102 #:allow-other-keys
103 #:rest args)
104 "Build the given Clojure package, applying all of PHASES in order."
105 (apply ant-build
106 #:inputs inputs
107 #:phases phases
108 args))
109
110 ;;; clojure-build-system.scm ends here