clojure.scm 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
  3. ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build-system clojure)
  20. #:use-module (guix build clojure-utils)
  21. #:use-module (guix build-system)
  22. #:use-module (guix build-system ant)
  23. #:use-module ((guix build-system gnu)
  24. #:select (standard-packages)
  25. #:prefix gnu:)
  26. #:use-module (guix derivations)
  27. #:use-module (guix packages)
  28. #:use-module ((guix search-paths)
  29. #:select
  30. ((search-path-specification->sexp . search-path-spec->sexp)))
  31. #:use-module (guix utils)
  32. #:use-module (ice-9 match)
  33. #:export (%clojure-build-system-modules
  34. clojure-build
  35. clojure-build-system))
  36. ;; Commentary:
  37. ;;
  38. ;; Standard build procedure for Clojure packages.
  39. ;;
  40. ;; Code:
  41. (define-with-docs %clojure-build-system-modules
  42. "Build-side modules imported by default."
  43. `((guix build clojure-build-system)
  44. (guix build clojure-utils)
  45. (guix build guile-build-system)
  46. ,@%ant-build-system-modules))
  47. (define %default-modules
  48. ;; Modules in scope in the build-side environment.
  49. '((guix build clojure-build-system)
  50. (guix build clojure-utils)
  51. (guix build utils)))
  52. (define-with-docs %default-clojure
  53. "The default Clojure package."
  54. (delay (@* (gnu packages clojure) clojure)))
  55. (define-with-docs %default-jdk
  56. "The default JDK package."
  57. (delay (@* (gnu packages java) icedtea)))
  58. (define-with-docs %default-zip
  59. "The default ZIP package."
  60. (delay (@* (gnu packages compression) zip)))
  61. (define* (lower name
  62. #:key
  63. source target
  64. inputs native-inputs
  65. (clojure (force %default-clojure))
  66. (jdk (force %default-jdk))
  67. (zip (force %default-zip))
  68. outputs system
  69. #:allow-other-keys
  70. #:rest arguments)
  71. "Return a bag for NAME."
  72. (let ((private-keywords '(#:source #:target
  73. #:inputs #:native-inputs
  74. #:clojure #:jdk #:zip)))
  75. (if target
  76. (error "No cross-compilation for clojure-build-system yet: LOWER"
  77. target) ; FIXME
  78. (bag (name name)
  79. (system system)
  80. (host-inputs `(,@(if source
  81. `(("source" ,source))
  82. '())
  83. ,@inputs
  84. ,@(gnu:standard-packages)))
  85. (build-inputs `(("clojure" ,clojure)
  86. ("jdk" ,jdk "jdk")
  87. ("zip" ,zip)
  88. ,@native-inputs))
  89. (outputs outputs)
  90. (build clojure-build)
  91. (arguments (strip-keyword-arguments private-keywords
  92. arguments))))))
  93. (define-with-docs source->output-path
  94. "Convert source input to output path."
  95. (match-lambda
  96. (((? derivation? source))
  97. (derivation->output-path source))
  98. ((source)
  99. source)
  100. (source
  101. source)))
  102. (define-with-docs maybe-guile->guile
  103. "Find the right guile."
  104. (match-lambda
  105. ((and maybe-guile (? package?))
  106. maybe-guile)
  107. (#f ; default
  108. (@* (gnu packages commencement) guile-final))))
  109. (define* (clojure-build store name inputs
  110. #:key
  111. (source-dirs `',%source-dirs)
  112. (test-dirs `',%test-dirs)
  113. (compile-dir %compile-dir)
  114. (jar-names `',(package-name->jar-names name))
  115. (main-class %main-class)
  116. (omit-source? %omit-source?)
  117. (aot-include `',%aot-include)
  118. (aot-exclude `',%aot-exclude)
  119. doc-dirs ; no sensible default
  120. (doc-regex %doc-regex)
  121. (tests? %tests?)
  122. (test-include `',%test-include)
  123. (test-exclude `',%test-exclude)
  124. (phases '%standard-phases)
  125. (outputs '("out"))
  126. (search-paths '())
  127. (system (%current-system))
  128. (guile #f)
  129. (imported-modules %clojure-build-system-modules)
  130. (modules %default-modules))
  131. "Build SOURCE with INPUTS."
  132. (let ((builder `(begin
  133. (use-modules ,@modules)
  134. (clojure-build #:name ,name
  135. #:source ,(source->output-path
  136. (assoc-ref inputs "source"))
  137. #:source-dirs ,source-dirs
  138. #:test-dirs ,test-dirs
  139. #:compile-dir ,compile-dir
  140. #:jar-names ,jar-names
  141. #:main-class ,main-class
  142. #:omit-source? ,omit-source?
  143. #:aot-include ,aot-include
  144. #:aot-exclude ,aot-exclude
  145. #:doc-dirs ,doc-dirs
  146. #:doc-regex ,doc-regex
  147. #:tests? ,tests?
  148. #:test-include ,test-include
  149. #:test-exclude ,test-exclude
  150. #:phases ,phases
  151. #:outputs %outputs
  152. #:search-paths ',(map search-path-spec->sexp
  153. search-paths)
  154. #:system ,system
  155. #:inputs %build-inputs)))
  156. (guile-for-build (package-derivation store
  157. (maybe-guile->guile guile)
  158. system
  159. #:graft? #f)))
  160. (build-expression->derivation store name builder
  161. #:inputs inputs
  162. #:system system
  163. #:modules imported-modules
  164. #:outputs outputs
  165. #:guile-for-build guile-for-build)))
  166. (define clojure-build-system
  167. (build-system
  168. (name 'clojure)
  169. (description "Simple Clojure build system using plain old 'compile'")
  170. (lower lower)))
  171. ;;; clojure.scm ends here