rakudo-build-system.scm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
  3. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  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 rakudo-build-system)
  20. #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  21. #:use-module (guix build utils)
  22. #:use-module (ice-9 ftw)
  23. #:use-module (ice-9 match)
  24. #:use-module (srfi srfi-1)
  25. #:use-module (srfi srfi-26)
  26. #:export (%standard-phases
  27. rakudo-build))
  28. ;; Commentary:
  29. ;;
  30. ;; Builder-side code of the standard Rakudo package build procedure.
  31. ;;
  32. ;; Code:
  33. (define* (check #:key tests? inputs with-prove6? #:allow-other-keys)
  34. (if (and tests? (assoc-ref inputs "perl6-tap-harness"))
  35. ;(if (and tests? with-prove6?)
  36. (invoke "prove6" "-I=lib" "t/")
  37. (format #t "test suite not run~%"))
  38. #t)
  39. (define* (install #:key inputs outputs with-zef? #:allow-other-keys)
  40. "Install a given Perl6 package."
  41. (let* ((out (assoc-ref outputs "out"))
  42. (perl6 (string-append out "/share/perl6")))
  43. (if (assoc-ref inputs "perl6-zef")
  44. ;(if with-zef?
  45. (begin
  46. (let ((zef (string-append (assoc-ref inputs "perl6-zef")
  47. "/bin/zef")))
  48. (setenv "HOME" (getcwd))
  49. (mkdir-p perl6)
  50. (invoke zef "install" "--verbose" "."
  51. ;; Don't install any of the following:
  52. "--/depends" "--/build-depends" "--/test-depends"
  53. (string-append "--install-to=" perl6))
  54. (delete-file (string-append perl6 "/repo.lock")))
  55. #t)
  56. (begin
  57. (let ((inst (string-append (assoc-ref inputs "rakudo")
  58. "/share/perl6/tools/install-dist.p6")))
  59. (setenv "RAKUDO_RERESOLVE_DEPENDENCIES" "0")
  60. (setenv "RAKUDO_MODULE_DEBUG" "1") ; be verbose while building
  61. (invoke inst (string-append "--to=" perl6) "--for=site"))))))
  62. (define* (install-libs #:key outputs #:allow-other-keys)
  63. (let ((out (assoc-ref outputs "out"))
  64. (lock "lib/.precomp/.lock"))
  65. (when (file-exists? lock)
  66. (delete-file "lib/.precomp/.lock"))
  67. (copy-recursively "lib" (string-append out "/share/perl6/lib"))
  68. #t))
  69. (define* (install-bins #:key outputs #:allow-other-keys)
  70. (let ((out (assoc-ref outputs "out")))
  71. (when (file-exists? "bin")
  72. (for-each (lambda (file)
  73. (install-file file (string-append out "/bin"))
  74. (chmod (string-append out "/" file) #o555))
  75. (find-files "bin" ".*")))
  76. (when (file-exists? "sbin")
  77. (for-each (lambda (file)
  78. (install-file file (string-append out "/sbin"))
  79. (chmod (string-append out "/" file) #o555))
  80. (find-files "sbin" ".*")))
  81. #t))
  82. (define* (install-resources #:key outputs #:allow-other-keys)
  83. (let ((out (assoc-ref outputs "out")))
  84. (when (file-exists? "resources")
  85. (copy-recursively "resources"
  86. (string-append out "/share/perl6/resources")))
  87. #t))
  88. (define* (wrap #:key inputs outputs #:allow-other-keys)
  89. (define (list-of-files dir)
  90. (map (cut string-append dir "/" <>)
  91. (or (scandir dir (lambda (f)
  92. (let ((s (stat (string-append dir "/" f))))
  93. (and (eq? 'regular (stat:type s))
  94. (not (wrapped-program? f))))))
  95. '())))
  96. (define bindirs
  97. (append-map (match-lambda
  98. ((_ . dir)
  99. (list (string-append dir "/bin")
  100. (string-append dir "/sbin"))))
  101. outputs))
  102. ;; Do not require bash to be present in the package inputs
  103. ;; even when there is nothing to wrap.
  104. ;; Also, calculate (sh) only once to prevent some I/O.
  105. (define %sh (delay (search-input-file inputs "bin/bash")))
  106. (define (sh) (force %sh))
  107. (let* ((out (assoc-ref outputs "out"))
  108. (var `("PERL6LIB" "," prefix
  109. ,(cons (string-append out "/share/perl6/lib,"
  110. out "/share/perl6/site/lib,"
  111. out "/share/perl6/vendor/lib")
  112. (search-path-as-string->list
  113. (or (getenv "PERL6LIB") "") #\,)))))
  114. (for-each (lambda (dir)
  115. (let ((files (list-of-files dir)))
  116. (for-each (cut wrap-program <> #:sh (sh) var)
  117. files)))
  118. bindirs)
  119. #t))
  120. (define %standard-phases
  121. ;; No need for 'bootstrap, 'configure or 'build.
  122. (modify-phases gnu:%standard-phases
  123. (delete 'bootstrap)
  124. (delete 'configure)
  125. (delete 'build)
  126. (replace 'check check)
  127. (replace 'install install)
  128. (add-before 'install 'install-lib-dir install-libs)
  129. (add-after 'install-lib-dir 'install-resources install-resources)
  130. (add-after 'install-resources 'install-binaries install-bins)
  131. ;; needs to be after 'install-binaries and all 'install phases
  132. (add-after 'install 'wrap wrap)))
  133. (define* (rakudo-build #:key inputs (phases %standard-phases)
  134. #:allow-other-keys #:rest args)
  135. "Build the given Perl6 package, applying all of PHASES in order."
  136. (apply gnu:gnu-build
  137. #:inputs inputs #:phases phases
  138. args))
  139. ;;; rakudo-build-system.scm ends here