ant.scm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
  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-system ant)
  19. #:use-module (guix store)
  20. #:use-module (guix utils)
  21. #:use-module (guix packages)
  22. #:use-module (guix derivations)
  23. #:use-module (guix search-paths)
  24. #:use-module (guix build-system)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (ice-9 match)
  27. #:use-module (srfi srfi-26)
  28. #:export (%ant-build-system-modules
  29. ant-build
  30. ant-build-system))
  31. ;; Commentary:
  32. ;;
  33. ;; Standard build procedure for Java packages using Ant.
  34. ;;
  35. ;; Code:
  36. (define %ant-build-system-modules
  37. ;; Build-side modules imported by default.
  38. `((guix build ant-build-system)
  39. (guix build maven java)
  40. (guix build maven plugin)
  41. (guix build maven pom)
  42. (guix build java-utils)
  43. (guix build syscalls)
  44. ,@%gnu-build-system-modules))
  45. (define (default-jdk)
  46. "Return the default JDK package."
  47. ;; Lazily resolve the binding to avoid a circular dependency.
  48. (let ((jdk-mod (resolve-interface '(gnu packages java))))
  49. (module-ref jdk-mod 'icedtea)))
  50. (define (default-ant)
  51. "Return the default Ant package."
  52. ;; Lazily resolve the binding to avoid a circular dependency.
  53. (let ((jdk-mod (resolve-interface '(gnu packages java))))
  54. (module-ref jdk-mod 'ant)))
  55. (define (default-zip)
  56. "Return the default ZIP package."
  57. ;; Lazily resolve the binding to avoid a circular dependency.
  58. (let ((zip-mod (resolve-interface '(gnu packages compression))))
  59. (module-ref zip-mod 'zip)))
  60. (define* (lower name
  61. #:key source inputs native-inputs outputs system target
  62. (jdk (default-jdk))
  63. (ant (default-ant))
  64. (zip (default-zip))
  65. #:allow-other-keys
  66. #:rest arguments)
  67. "Return a bag for NAME."
  68. (define private-keywords
  69. '(#:source #:target #:jdk #:ant #:zip #:inputs #:native-inputs))
  70. (and (not target) ;XXX: no cross-compilation
  71. (bag
  72. (name name)
  73. (system system)
  74. (host-inputs `(,@(if source
  75. `(("source" ,source))
  76. '())
  77. ,@inputs
  78. ;; Keep the standard inputs of 'gnu-build-system'.
  79. ,@(standard-packages)))
  80. (build-inputs `(("jdk" ,jdk "jdk")
  81. ("ant" ,ant)
  82. ("zip" ,zip)
  83. ,@native-inputs))
  84. (outputs outputs)
  85. (build ant-build)
  86. (arguments (strip-keyword-arguments private-keywords arguments)))))
  87. (define* (ant-build store name inputs
  88. #:key
  89. (tests? #t)
  90. (test-target "check")
  91. (configure-flags ''())
  92. (make-flags ''())
  93. (build-target "jar")
  94. (jar-name #f)
  95. (main-class #f)
  96. (test-include (list "**/*Test.java"))
  97. (test-exclude (list "**/Abstract*.java"))
  98. (source-dir "src")
  99. (test-dir "src/test")
  100. (phases '(@ (guix build ant-build-system)
  101. %standard-phases))
  102. (outputs '("out"))
  103. (search-paths '())
  104. (system (%current-system))
  105. (guile #f)
  106. (imported-modules %ant-build-system-modules)
  107. (modules '((guix build ant-build-system)
  108. (guix build java-utils)
  109. (guix build utils))))
  110. "Build SOURCE with INPUTS."
  111. (define builder
  112. `(begin
  113. (use-modules ,@modules)
  114. (ant-build #:name ,name
  115. #:source ,(match (assoc-ref inputs "source")
  116. (((? derivation? source))
  117. (derivation->output-path source))
  118. ((source)
  119. source)
  120. (source
  121. source))
  122. #:make-flags ,make-flags
  123. #:configure-flags ,configure-flags
  124. #:system ,system
  125. #:tests? ,tests?
  126. #:test-target ,test-target
  127. #:build-target ,build-target
  128. #:jar-name ,jar-name
  129. #:main-class ,main-class
  130. #:test-include (list ,@test-include)
  131. #:test-exclude (list ,@test-exclude)
  132. #:source-dir ,source-dir
  133. #:test-dir ,test-dir
  134. #:phases ,phases
  135. #:outputs %outputs
  136. #:search-paths ',(map search-path-specification->sexp
  137. search-paths)
  138. #:inputs %build-inputs)))
  139. (define guile-for-build
  140. (match guile
  141. ((? package?)
  142. (package-derivation store guile system #:graft? #f))
  143. (#f ; the default
  144. (let* ((distro (resolve-interface '(gnu packages commencement)))
  145. (guile (module-ref distro 'guile-final)))
  146. (package-derivation store guile system #:graft? #f)))))
  147. (build-expression->derivation store name builder
  148. #:inputs inputs
  149. #:system system
  150. #:modules imported-modules
  151. #:outputs outputs
  152. #:guile-for-build guile-for-build))
  153. (define ant-build-system
  154. (build-system
  155. (name 'ant)
  156. (description "The standard Ant build system")
  157. (lower lower)))
  158. ;;; ant.scm ends here