rebar.scm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
  3. ;;; Copyright © 2020 Hartmut Goebel <h.goebel@crazy-compilers.com>
  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 rebar)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix gexp)
  23. #:use-module (guix packages)
  24. #:use-module (guix monads)
  25. #:use-module (guix search-paths)
  26. #:use-module (guix build-system)
  27. #:use-module (guix build-system gnu)
  28. #:export (hexpm-uri
  29. hexpm-package-url
  30. %rebar-build-system-modules
  31. rebar-build
  32. rebar-build-system))
  33. ;;;
  34. ;;; Definitions for the hex.pm repository,
  35. ;;;
  36. ;; URL and paths from
  37. ;; https://github.com/hexpm/specifications/blob/master/endpoints.md
  38. (define %hexpm-repo-url
  39. (make-parameter "https://repo.hex.pm"))
  40. (define hexpm-package-url
  41. (string-append (%hexpm-repo-url) "/tarballs/"))
  42. (define (hexpm-uri name version)
  43. "Return a URI string for the package hosted at hex.pm corresponding to NAME
  44. and VERSION."
  45. (string-append hexpm-package-url name "-" version ".tar"))
  46. ;;
  47. ;; Standard build procedure for Erlang packages using Rebar.
  48. ;;
  49. (define %rebar-build-system-modules
  50. ;; Build-side modules imported by default.
  51. `((guix build rebar-build-system)
  52. ,@%gnu-build-system-modules))
  53. (define (default-rebar3)
  54. "Return the default Rebar3 package."
  55. ;; Lazily resolve the binding to avoid a circular dependency.
  56. (let ((erlang-mod (resolve-interface '(gnu packages erlang))))
  57. (module-ref erlang-mod 'rebar3)))
  58. (define (default-erlang)
  59. "Return the default Erlang package."
  60. ;; Lazily resolve the binding to avoid a circular dependency.
  61. (let ((erlang-mod (resolve-interface '(gnu packages erlang))))
  62. (module-ref erlang-mod 'erlang)))
  63. (define* (lower name
  64. #:key source inputs native-inputs outputs system target
  65. (rebar (default-rebar3))
  66. (erlang (default-erlang))
  67. #:allow-other-keys
  68. #:rest arguments)
  69. "Return a bag for NAME from the given arguments."
  70. (define private-keywords
  71. '(#:target #:rebar #:erlang #:inputs #:native-inputs))
  72. (and (not target) ;XXX: no cross-compilation
  73. (bag
  74. (name name)
  75. (system system)
  76. (host-inputs `(,@(if source
  77. `(("source" ,source))
  78. '())
  79. ,@inputs))
  80. (build-inputs `(("rebar" ,rebar)
  81. ("erlang" ,erlang) ;; for escriptize
  82. ,@native-inputs
  83. ;; Keep the standard inputs of 'gnu-build-system'.
  84. ,@(standard-packages)))
  85. (outputs outputs)
  86. (build rebar-build)
  87. (arguments (strip-keyword-arguments private-keywords arguments)))))
  88. (define* (rebar-build name inputs
  89. #:key
  90. guile source
  91. (rebar-flags ''("skip_deps=true" "-vv"))
  92. (tests? #t)
  93. (test-target "eunit")
  94. ;; TODO: install-name ; default: based on guix package name
  95. (install-profile "default")
  96. (phases '(@ (guix build rebar-build-system)
  97. %standard-phases))
  98. (outputs '("out"))
  99. (search-paths '())
  100. (native-search-paths '())
  101. (system (%current-system))
  102. (imported-modules %rebar-build-system-modules)
  103. (modules '((guix build rebar-build-system)
  104. (guix build utils))))
  105. "Build SOURCE with INPUTS."
  106. (define builder
  107. (with-imported-modules imported-modules
  108. #~(begin
  109. (use-modules #$@(sexp->gexp modules))
  110. #$(with-build-variables inputs outputs
  111. #~(rebar-build #:source #+source
  112. #:system #$system
  113. #:name #$name
  114. #:rebar-flags #$rebar-flags
  115. #:tests? #$tests?
  116. #:test-target #$test-target
  117. ;; TODO: #:install-name #$install-name
  118. #:install-profile #$install-profile
  119. #:phases #$(if (pair? phases)
  120. (sexp->gexp phases)
  121. phases)
  122. #:outputs %outputs
  123. #:search-paths '#$(sexp->gexp
  124. (map search-path-specification->sexp
  125. search-paths))
  126. #:inputs %build-inputs)))))
  127. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  128. system #:graft? #f)))
  129. ;; Note: Always pass #:graft? #f. Without it, ALLOWED-REFERENCES &
  130. ;; co. would be interpreted as referring to grafted packages.
  131. (gexp->derivation name builder
  132. #:system system
  133. #:target #f
  134. #:graft? #f
  135. #:guile-for-build guile)))
  136. (define rebar-build-system
  137. (build-system
  138. (name 'rebar)
  139. (description "The standard Rebar build system")
  140. (lower lower)))