ant.scm 6.2 KB

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