rakudo-build-system.scm 5.5 KB

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