clojure-build-system.scm 5.4 KB

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