ruby.scm 5.0 KB

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