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