build-system/clojure: Support compiling Java.
* guix/build/clojure-build-system.scm (compile-java): New variable. (build): Copy classes compiled from Java and optionally Java sources to the final jar. (%standard-phases): Add compile-java phase before build. * guix/build/clojure-utils.scm (%java-source-dirs): New variable. (%java-compile-dir): New variable. * guix/build-system/clojure.scm (clojure-build): Include %java-source-dirs and %java-compile-dir. (builder): Include %java-source-dirs and %java-compile-dir. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
09b4d74bd3
commit
0f2df54f83
3 changed files with 44 additions and 8 deletions
|
@ -107,8 +107,10 @@ (define* (clojure-build name inputs
|
|||
#:key
|
||||
source
|
||||
(source-dirs `',%source-dirs)
|
||||
(java-source-dirs `',%java-source-dirs)
|
||||
(test-dirs `',%test-dirs)
|
||||
(compile-dir %compile-dir)
|
||||
(java-compile-dir %java-compile-dir)
|
||||
|
||||
(jar-names `',(package-name->jar-names name))
|
||||
(main-class %main-class)
|
||||
|
@ -142,9 +144,11 @@ (define builder
|
|||
#:source #+source
|
||||
|
||||
#:source-dirs #$source-dirs
|
||||
#:java-source-dirs #$java-source-dirs
|
||||
#:test-dirs #$test-dirs
|
||||
#:compile-dir #$compile-dir
|
||||
|
||||
#:java-compile-dir #$java-compile-dir
|
||||
|
||||
#:jar-names #$jar-names
|
||||
#:main-class #$main-class
|
||||
#:omit-source? #$omit-source?
|
||||
|
|
|
@ -34,8 +34,24 @@ (define-module (guix build clojure-build-system)
|
|||
;;
|
||||
;; Code:
|
||||
|
||||
(define* (compile-java #:key
|
||||
java-source-dirs java-compile-dir
|
||||
#:allow-other-keys)
|
||||
"Compile java sources for use in clojure-build-system."
|
||||
(let ((java-files (append-map (lambda (dir)
|
||||
(find-files dir "\\.java$"))
|
||||
java-source-dirs)))
|
||||
(mkdir-p java-compile-dir)
|
||||
(when (not (null? java-files))
|
||||
(apply invoke
|
||||
"javac"
|
||||
"-verbose"
|
||||
"-d" java-compile-dir
|
||||
java-files))))
|
||||
|
||||
(define* (build #:key
|
||||
source-dirs compile-dir
|
||||
source-dirs java-source-dirs
|
||||
compile-dir java-compile-dir
|
||||
jar-names main-class omit-source?
|
||||
aot-include aot-exclude
|
||||
#:allow-other-keys)
|
||||
|
@ -46,19 +62,24 @@ (define* (build #:key
|
|||
#:all-list libs)))
|
||||
(mkdir-p compile-dir)
|
||||
(eval-with-clojure `(run! compile ',libs*)
|
||||
source-dirs)
|
||||
(cons* compile-dir
|
||||
java-compile-dir
|
||||
source-dirs))
|
||||
(let ((source-dir-files-alist (map (lambda (dir)
|
||||
(cons dir (find-files* dir)))
|
||||
source-dirs))
|
||||
(append source-dirs
|
||||
java-source-dirs)))
|
||||
;; workaround transitive compilation in Clojure
|
||||
(classes (filter (lambda (class)
|
||||
(any (cut compiled-from? class <>)
|
||||
libs*))
|
||||
(find-files* compile-dir))))
|
||||
(for-each (cut create-jar <> (cons (cons compile-dir classes)
|
||||
(if omit-source?
|
||||
'()
|
||||
source-dir-files-alist))
|
||||
(for-each (cut create-jar <> (cons* (cons compile-dir classes)
|
||||
(cons java-compile-dir
|
||||
(find-files* java-compile-dir))
|
||||
(if omit-source?
|
||||
'()
|
||||
source-dir-files-alist))
|
||||
#:main-class main-class)
|
||||
jar-names)
|
||||
#t)))
|
||||
|
@ -94,6 +115,7 @@ (define-with-docs install
|
|||
(define-with-docs %standard-phases
|
||||
"Standard build phases for clojure-build-system."
|
||||
(modify-phases %standard-phases@ant
|
||||
(add-before 'build 'compile-java compile-java)
|
||||
(replace 'build build)
|
||||
(replace 'check check)
|
||||
(replace 'install install)
|
||||
|
|
|
@ -32,8 +32,10 @@ (define-module (guix build clojure-utils)
|
|||
install-doc
|
||||
|
||||
%source-dirs
|
||||
%java-source-dirs
|
||||
%test-dirs
|
||||
%compile-dir
|
||||
%java-compile-dir
|
||||
package-name->jar-names
|
||||
%main-class
|
||||
%omit-source?
|
||||
|
@ -101,6 +103,10 @@ (define-with-docs %source-dirs
|
|||
"A default list of source directories."
|
||||
'("src/"))
|
||||
|
||||
(define-with-docs %java-source-dirs
|
||||
"A default list of java source directories."
|
||||
'())
|
||||
|
||||
(define-with-docs %test-dirs
|
||||
"A default list of test directories."
|
||||
'("test/"))
|
||||
|
@ -109,6 +115,10 @@ (define-with-docs %compile-dir
|
|||
"Default directory for holding class files."
|
||||
"classes/")
|
||||
|
||||
(define-with-docs %java-compile-dir
|
||||
"Default directory for holding java class files."
|
||||
"java-classes/")
|
||||
|
||||
(define (package-name->jar-names name)
|
||||
"Given NAME, a package name like \"foo-0.9.1b\",
|
||||
return the list of default jar names: (\"foo-0.9.1b.jar\" \"foo.jar\")."
|
||||
|
|
Loading…
Reference in a new issue