hydra: Build only non-grafted variants of the packages.
[jackhill/guix/guix.git] / build-aux / hydra / gnu-system.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
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 ;;;
20 ;;; This file defines build jobs for the Hydra continuation integration
21 ;;; tool.
22 ;;;
23
24 ;; Attempt to use our very own Guix modules.
25 (eval-when (compile load eval)
26
27 ;; Ignore any available .go, and force recompilation. This is because our
28 ;; checkout in the store has mtime set to the epoch, and thus .go files look
29 ;; newer, even though they may not correspond.
30 (set! %fresh-auto-compile #t)
31
32 (and=> (assoc-ref (current-source-location) 'filename)
33 (lambda (file)
34 (let ((dir (string-append (dirname file) "/../..")))
35 (format (current-error-port) "prepending ~s to the load path~%"
36 dir)
37 (set! %load-path (cons dir %load-path))))))
38
39 (use-modules (guix config)
40 (guix store)
41 (guix packages)
42 (guix derivations)
43 (guix monads)
44 ((guix licenses) #:select (gpl3+))
45 ((guix utils) #:select (%current-system))
46 ((guix scripts system) #:select (read-operating-system))
47 (gnu packages)
48 (gnu packages gcc)
49 (gnu packages base)
50 (gnu packages gawk)
51 (gnu packages guile)
52 (gnu packages gettext)
53 (gnu packages compression)
54 (gnu packages multiprecision)
55 (gnu packages make-bootstrap)
56 (gnu packages commencement)
57 (gnu system)
58 (gnu system vm)
59 (gnu system install)
60 (srfi srfi-1)
61 (srfi srfi-26)
62 (ice-9 match))
63
64 ;; XXX: Debugging hack: since `hydra-eval-guile-jobs' redirects the output
65 ;; port to the bit bucket, let us write to the error port instead.
66 (setvbuf (current-error-port) _IOLBF)
67 (set-current-output-port (current-error-port))
68
69 (define* (package->alist store package system
70 #:optional (package-derivation package-derivation))
71 "Convert PACKAGE to an alist suitable for Hydra."
72 `((derivation . ,(derivation-file-name
73 (package-derivation store package system
74 #:graft? #f)))
75 (description . ,(package-synopsis package))
76 (long-description . ,(package-description package))
77 (license . ,(package-license package))
78 (home-page . ,(package-home-page package))
79 (maintainers . ("bug-guix@gnu.org"))
80
81 ;; Work around versions of 'hydra-eval-guile-jobs' before Hydra commit
82 ;; 61448ca (27 Feb. 2014) which used a default timeout of 2h.
83 (timeout . 72000)))
84
85 (define (package-job store job-name package system)
86 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
87 (let ((job-name (symbol-append job-name (string->symbol ".")
88 (string->symbol system))))
89 `(,job-name . ,(cut package->alist store package system))))
90
91 (define (package-cross-job store job-name package target system)
92 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
93 SYSTEM."
94 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
95 (string->symbol ".") (string->symbol system)) .
96 ,(cute package->alist store package system
97 (lambda* (store package system #:key graft?)
98 (package-cross-derivation store package target system
99 #:graft? graft?)))))
100
101 (define %core-packages
102 ;; Note: Don't put the '-final' package variants because (1) that's
103 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
104 ;; chain.)
105 (list gcc-4.8 gcc-4.7 glibc binutils
106 gmp mpfr mpc coreutils findutils diffutils patch sed grep
107 gawk gnu-gettext hello guile-2.0 zlib gzip xz
108 %bootstrap-binaries-tarball
109 %binutils-bootstrap-tarball
110 %glibc-bootstrap-tarball
111 %gcc-bootstrap-tarball
112 %guile-bootstrap-tarball
113 %bootstrap-tarballs))
114
115 (define %packages-to-cross-build
116 %core-packages)
117
118 (define %cross-targets
119 '("mips64el-linux-gnu"
120 "mips64el-linux-gnuabi64"))
121
122 (define (demo-os)
123 "Return the \"demo\" 'operating-system' structure."
124 (let* ((dir (dirname (assoc-ref (current-source-location) 'filename)))
125 (file (string-append dir "/demo-os.scm")))
126 (read-operating-system file)))
127
128 (define (qemu-jobs store system)
129 "Return a list of jobs that build QEMU images for SYSTEM."
130 (define (->alist drv)
131 `((derivation . ,(derivation-file-name drv))
132 (description . "Stand-alone QEMU image of the GNU system")
133 (long-description . "This is a demo stand-alone QEMU image of the GNU
134 system.")
135 (license . ,gpl3+)
136 (home-page . ,%guix-home-page-url)
137 (maintainers . ("bug-guix@gnu.org"))))
138
139 (define (->job name drv)
140 (let ((name (symbol-append name (string->symbol ".")
141 (string->symbol system))))
142 `(,name . ,(cut ->alist drv))))
143
144 (define MiB
145 (expt 2 20))
146
147 (if (member system '("x86_64-linux" "i686-linux"))
148 (list (->job 'qemu-image
149 (run-with-store store
150 (system-qemu-image (demo-os)
151 #:disk-image-size
152 (* 1400 MiB)))) ; 1.4 GiB
153 (->job 'usb-image
154 (run-with-store store
155 (system-disk-image installation-os
156 #:disk-image-size
157 (* 800 MiB)))))
158 '()))
159
160 (define job-name
161 ;; Return the name of a package's job.
162 (compose string->symbol package-full-name))
163
164 (define package->job
165 (let ((base-packages
166 (delete-duplicates
167 (append-map (match-lambda
168 ((_ package _ ...)
169 (match (package-transitive-inputs package)
170 (((_ inputs _ ...) ...)
171 inputs))))
172 %final-inputs))))
173 (lambda (store package system)
174 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
175 valid."
176 (cond ((member package base-packages)
177 #f)
178 ((member system
179 (package-transitive-supported-systems package))
180 (package-job store (job-name package) package system))
181 (else
182 #f)))))
183
184 \f
185 ;;;
186 ;;; Hydra entry point.
187 ;;;
188
189 (define (hydra-jobs store arguments)
190 "Return Hydra jobs."
191 (define subset
192 (match (assoc-ref arguments 'subset)
193 ("core" 'core) ; only build core packages
194 (_ 'all))) ; build everything
195
196 (define (cross-jobs system)
197 (define (from-32-to-64? target)
198 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit.
199 ;; This hacks prevents known-to-fail cross-builds from i686-linux to
200 ;; mips64el-linux-gnuabi64.
201 (and (string-prefix? "i686-" system)
202 (string-suffix? "64" target)))
203
204 (define (same? target)
205 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
206 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
207 ;; 'mips64el-linux'.
208 (string-contains target system))
209
210 (define (either proc1 proc2)
211 (lambda (x)
212 (or (proc1 x) (proc2 x))))
213
214 (append-map (lambda (target)
215 (map (lambda (package)
216 (package-cross-job store (job-name package)
217 package target system))
218 %packages-to-cross-build))
219 (remove (either from-32-to-64? same?) %cross-targets)))
220
221 ;; Return one job for each package, except bootstrap packages.
222 (append-map (lambda (system)
223 (case subset
224 ((all)
225 ;; Build everything.
226 (fold-packages (lambda (package result)
227 (let ((job (package->job store package
228 system)))
229 (if job
230 (cons job result)
231 result)))
232 (append (qemu-jobs store system)
233 (cross-jobs system))))
234 ((core)
235 ;; Build core packages only.
236 (append (map (lambda (package)
237 (package-job store (job-name package)
238 package system))
239 %core-packages)
240 (cross-jobs system)))
241 (else
242 (error "unknown subset" subset))))
243 %supported-systems))