summary refs log tree commit diff
diff options
context:
space:
mode:
authorReily Siegel <mail@reilysiegel.com>2022-01-18 13:17:24 -0500
committerLudovic Courtès <ludo@gnu.org>2022-01-24 10:38:14 +0100
commit0f2df54f8397560e6e8473e2982c66af01d9cd0a (patch)
tree217b9c71b962095c96b33222834d0266682b07c8
parent09b4d74bd352d40b45e081eaa094b086a42dad3d (diff)
downloadguix-0f2df54f8397560e6e8473e2982c66af01d9cd0a.tar.gz
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>
-rw-r--r--guix/build-system/clojure.scm6
-rw-r--r--guix/build/clojure-build-system.scm36
-rw-r--r--guix/build/clojure-utils.scm10
3 files changed, 44 insertions, 8 deletions
diff --git a/guix/build-system/clojure.scm b/guix/build-system/clojure.scm
index 634854cf1b..2a0713d297 100644
--- a/guix/build-system/clojure.scm
+++ b/guix/build-system/clojure.scm
@@ -107,8 +107,10 @@
                         #: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 @@
                          #: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?
diff --git a/guix/build/clojure-build-system.scm b/guix/build/clojure-build-system.scm
index dd01f95de8..7d494078ea 100644
--- a/guix/build/clojure-build-system.scm
+++ b/guix/build/clojure-build-system.scm
@@ -34,8 +34,24 @@
 ;;
 ;; 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 @@
                                            #: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 @@ priority over TEST-INCLUDE."
 (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)
diff --git a/guix/build/clojure-utils.scm b/guix/build/clojure-utils.scm
index 8817cab52a..c5322141d3 100644
--- a/guix/build/clojure-utils.scm
+++ b/guix/build/clojure-utils.scm
@@ -32,8 +32,10 @@
             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 @@ DOC-REGEX can be compiled or uncompiled."
   "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 @@ DOC-REGEX can be compiled or uncompiled."
   "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\")."