ruby.scm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2014, 2015, 2021 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 ruby)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix gexp)
  23. #:use-module (guix monads)
  24. #:use-module (guix packages)
  25. #:use-module (guix derivations)
  26. #:use-module (guix search-paths)
  27. #:use-module (guix build-system)
  28. #:use-module (guix build-system gnu)
  29. #:use-module (ice-9 match)
  30. #:export (rubygems-uri
  31. %ruby-build-system-modules
  32. ruby-build
  33. ruby-build-system))
  34. (define (rubygems-uri name version)
  35. "Return a URI string for the gem archive for the release corresponding to
  36. NAME and VERSION."
  37. (string-append "https://rubygems.org/downloads/" name "-" version ".gem"))
  38. (define %ruby-build-system-modules
  39. ;; Build-side modules imported by default.
  40. `((guix build ruby-build-system)
  41. ,@%gnu-build-system-modules))
  42. (define (default-ruby)
  43. "Return the default Ruby package."
  44. ;; Lazily resolve the binding to avoid a circular dependency.
  45. (let ((ruby (resolve-interface '(gnu packages ruby))))
  46. (module-ref ruby 'ruby)))
  47. (define* (lower name
  48. #:key source inputs native-inputs outputs system target
  49. (ruby (default-ruby))
  50. #:allow-other-keys
  51. #:rest arguments)
  52. "Return a bag for NAME."
  53. (define private-keywords
  54. '(#:target #:ruby #:inputs #:native-inputs))
  55. (and (not target) ;XXX: no cross-compilation
  56. (bag
  57. (name name)
  58. (system system)
  59. (host-inputs `(,@(if source
  60. `(("source" ,source))
  61. '())
  62. ,@inputs
  63. ;; Keep the standard inputs of 'gnu-build-system'.
  64. ,@(standard-packages)))
  65. (build-inputs `(("ruby" ,ruby)
  66. ,@native-inputs))
  67. (outputs outputs)
  68. (build ruby-build)
  69. (arguments (strip-keyword-arguments private-keywords arguments)))))
  70. (define* (ruby-build name inputs
  71. #:key source
  72. (gem-flags ''())
  73. (test-target "test")
  74. (tests? #t)
  75. (phases '%standard-phases)
  76. (outputs '("out"))
  77. (search-paths '())
  78. (system (%current-system))
  79. (guile #f)
  80. (imported-modules %ruby-build-system-modules)
  81. (modules '((guix build ruby-build-system)
  82. (guix build utils))))
  83. "Build SOURCE using RUBY and INPUTS."
  84. (define build
  85. #~(begin
  86. (use-modules #$@(sexp->gexp modules))
  87. #$(with-build-variables inputs outputs
  88. #~(ruby-build #:name #$name
  89. #:source #+source
  90. #:system #$system
  91. #:gem-flags #$gem-flags
  92. #:test-target #$test-target
  93. #:tests? #$tests?
  94. #:phases #$(if (pair? phases)
  95. (sexp->gexp phases)
  96. phases)
  97. #:outputs %outputs
  98. #:search-paths '#$(sexp->gexp
  99. (map search-path-specification->sexp
  100. search-paths))
  101. #:inputs %build-inputs))))
  102. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  103. system #:graft? #f)))
  104. (gexp->derivation name build
  105. #:system system
  106. #:target #f
  107. #:modules imported-modules
  108. #:guile-for-build guile)))
  109. (define ruby-build-system
  110. (build-system
  111. (name 'ruby)
  112. (description "The standard Ruby build system")
  113. (lower lower)))