clojure-build-system.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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* (build #:key
  35. source-dirs compile-dir
  36. jar-names main-class omit-source?
  37. aot-include aot-exclude
  38. #:allow-other-keys)
  39. "Standard 'build' phase for clojure-build-system."
  40. (let* ((libs (append-map find-clojure-libs source-dirs))
  41. (libs* (include-list\exclude-list aot-include
  42. aot-exclude
  43. #:all-list libs)))
  44. (mkdir-p compile-dir)
  45. (eval-with-clojure `(run! compile ',libs*)
  46. source-dirs)
  47. (let ((source-dir-files-alist (map (lambda (dir)
  48. (cons dir (find-files* dir)))
  49. source-dirs))
  50. ;; workaround transitive compilation in Clojure
  51. (classes (filter (lambda (class)
  52. (any (cut compiled-from? class <>)
  53. libs*))
  54. (find-files* compile-dir))))
  55. (for-each (cut create-jar <> (cons (cons compile-dir classes)
  56. (if omit-source?
  57. '()
  58. source-dir-files-alist))
  59. #:main-class main-class)
  60. jar-names)
  61. #t)))
  62. (define* (check #:key
  63. test-dirs
  64. jar-names
  65. tests? test-include test-exclude
  66. #:allow-other-keys)
  67. "Standard 'check' phase for clojure-build-system. Note that TEST-EXCLUDE has
  68. priority over TEST-INCLUDE."
  69. (if tests?
  70. (let* ((libs (append-map find-clojure-libs test-dirs))
  71. (libs* (include-list\exclude-list test-include
  72. test-exclude
  73. #:all-list libs)))
  74. (for-each (lambda (jar)
  75. (eval-with-clojure `(do (apply require
  76. '(clojure.test ,@libs*))
  77. (apply clojure.test/run-tests
  78. ',libs*))
  79. (cons jar test-dirs)))
  80. jar-names)))
  81. #t)
  82. (define-with-docs install
  83. "Standard 'install' phase for clojure-build-system."
  84. (install-jars "./"))
  85. (define-with-docs %standard-phases
  86. "Standard build phases for clojure-build-system."
  87. (modify-phases %standard-phases@ant
  88. (replace 'build build)
  89. (replace 'check check)
  90. (replace 'install install)
  91. (add-after 'install-license-files 'install-doc install-doc)))
  92. (define* (clojure-build #:key
  93. inputs
  94. (phases %standard-phases)
  95. #:allow-other-keys
  96. #:rest args)
  97. "Build the given Clojure package, applying all of PHASES in order."
  98. (apply ant-build
  99. #:inputs inputs
  100. #:phases phases
  101. args))
  102. ;;; clojure-build-system.scm ends here