Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / build-aux / hydra / gnu-system.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 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 grafts)
42 (guix packages)
43 (guix derivations)
44 (guix monads)
45 ((guix licenses) #:select (gpl3+))
46 ((guix utils) #:select (%current-system))
47 ((guix scripts system) #:select (read-operating-system))
48 (gnu packages)
49 (gnu packages gcc)
50 (gnu packages base)
51 (gnu packages gawk)
52 (gnu packages guile)
53 (gnu packages gettext)
54 (gnu packages compression)
55 (gnu packages multiprecision)
56 (gnu packages make-bootstrap)
57 (gnu packages package-management)
58 (gnu system)
59 (gnu system vm)
60 (gnu system install)
61 (gnu tests)
62 (srfi srfi-1)
63 (srfi srfi-26)
64 (ice-9 match))
65
66 ;; XXX: Debugging hack: since `hydra-eval-guile-jobs' redirects the output
67 ;; port to the bit bucket, let us write to the error port instead.
68 (setvbuf (current-error-port) _IOLBF)
69 (set-current-output-port (current-error-port))
70
71 (define* (package->alist store package system
72 #:optional (package-derivation package-derivation))
73 "Convert PACKAGE to an alist suitable for Hydra."
74 (parameterize ((%graft? #f))
75 `((derivation . ,(derivation-file-name
76 (package-derivation store package system
77 #:graft? #f)))
78 (description . ,(package-synopsis package))
79 (long-description . ,(package-description package))
80 (license . ,(package-license package))
81 (home-page . ,(package-home-page package))
82 (maintainers . ("bug-guix@gnu.org"))
83 (max-silent-time . ,(or (assoc-ref (package-properties package)
84 'max-silent-time)
85 3600)) ;1 hour by default
86 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
87 72000))))) ;20 hours by default
88
89 (define (package-job store job-name package system)
90 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
91 (let ((job-name (symbol-append job-name (string->symbol ".")
92 (string->symbol system))))
93 `(,job-name . ,(cut package->alist store package system))))
94
95 (define (package-cross-job store job-name package target system)
96 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
97 SYSTEM."
98 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
99 (string->symbol ".") (string->symbol system)) .
100 ,(cute package->alist store package system
101 (lambda* (store package system #:key graft?)
102 (package-cross-derivation store package target system
103 #:graft? graft?)))))
104
105 (define %core-packages
106 ;; Note: Don't put the '-final' package variants because (1) that's
107 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
108 ;; chain.)
109 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
110 gmp mpfr mpc coreutils findutils diffutils patch sed grep
111 gawk gnu-gettext hello guile-2.0 zlib gzip xz
112 %bootstrap-binaries-tarball
113 %binutils-bootstrap-tarball
114 (%glibc-bootstrap-tarball)
115 %gcc-bootstrap-tarball
116 %guile-bootstrap-tarball
117 %bootstrap-tarballs))
118
119 (define %packages-to-cross-build
120 %core-packages)
121
122 (define %cross-targets
123 '("mips64el-linux-gnu"
124 "mips64el-linux-gnuabi64"
125 "arm-linux-gnueabihf"
126 "powerpc-linux-gnu"
127 "i586-pc-gnu" ;aka. GNU/Hurd
128 "i686-w64-mingw32"))
129
130 (define %guixsd-supported-systems
131 '("x86_64-linux" "i686-linux"))
132
133 (define (qemu-jobs store system)
134 "Return a list of jobs that build QEMU images for SYSTEM."
135 (define (->alist drv)
136 `((derivation . ,(derivation-file-name drv))
137 (description . "Stand-alone QEMU image of the GNU system")
138 (long-description . "This is a demo stand-alone QEMU image of the GNU
139 system.")
140 (license . ,gpl3+)
141 (home-page . ,%guix-home-page-url)
142 (maintainers . ("bug-guix@gnu.org"))))
143
144 (define (->job name drv)
145 (let ((name (symbol-append name (string->symbol ".")
146 (string->symbol system))))
147 `(,name . ,(lambda ()
148 (parameterize ((%graft? #f))
149 (->alist drv))))))
150
151 (define MiB
152 (expt 2 20))
153
154 (if (member system %guixsd-supported-systems)
155 (list (->job 'usb-image
156 (run-with-store store
157 (mbegin %store-monad
158 (set-guile-for-build (default-guile))
159 (system-disk-image installation-os
160 #:disk-image-size
161 (* 1024 MiB))))))
162 '()))
163
164 (define (system-test-jobs store system)
165 "Return a list of jobs for the system tests."
166 (define (test->thunk test)
167 (lambda ()
168 (define drv
169 (run-with-store store
170 (mbegin %store-monad
171 (set-current-system system)
172 (set-grafting #f)
173 (set-guile-for-build (default-guile))
174 (system-test-value test))))
175
176 `((derivation . ,(derivation-file-name drv))
177 (description . ,(format #f "GuixSD '~a' system test"
178 (system-test-name test)))
179 (long-description . ,(system-test-description test))
180 (license . ,gpl3+)
181 (home-page . ,%guix-home-page-url)
182 (maintainers . ("bug-guix@gnu.org")))))
183
184 (define (->job test)
185 (let ((name (string->symbol
186 (string-append "test." (system-test-name test)
187 "." system))))
188 (cons name (test->thunk test))))
189
190 (if (member system %guixsd-supported-systems)
191 (map ->job (all-system-tests))
192 '()))
193
194 (define (tarball-jobs store system)
195 "Return Hydra jobs to build the self-contained Guix binary tarball."
196 (define (->alist drv)
197 `((derivation . ,(derivation-file-name drv))
198 (description . "Stand-alone binary Guix tarball")
199 (long-description . "This is a tarball containing binaries of Guix and
200 all its dependencies, and ready to be installed on non-GuixSD distributions.")
201 (license . ,gpl3+)
202 (home-page . ,%guix-home-page-url)
203 (maintainers . ("bug-guix@gnu.org"))))
204
205 (define (->job name drv)
206 (let ((name (symbol-append name (string->symbol ".")
207 (string->symbol system))))
208 `(,name . ,(lambda ()
209 (parameterize ((%graft? #f))
210 (->alist drv))))))
211
212 ;; XXX: Add a job for the stable Guix?
213 (list (->job 'binary-tarball
214 (run-with-store store
215 (mbegin %store-monad
216 (set-guile-for-build (default-guile))
217 (self-contained-tarball))
218 #:system system))))
219
220 (define job-name
221 ;; Return the name of a package's job.
222 (compose string->symbol package-full-name))
223
224 (define package->job
225 (let ((base-packages
226 (delete-duplicates
227 (append-map (match-lambda
228 ((_ package _ ...)
229 (match (package-transitive-inputs package)
230 (((_ inputs _ ...) ...)
231 inputs))))
232 (%final-inputs)))))
233 (lambda (store package system)
234 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
235 valid."
236 (cond ((member package base-packages)
237 #f)
238 ((supported-package? package system)
239 (package-job store (job-name package) package system))
240 (else
241 #f)))))
242
243 \f
244 ;;;
245 ;;; Hydra entry point.
246 ;;;
247
248 (define (hydra-jobs store arguments)
249 "Return Hydra jobs."
250 (define subset
251 (match (assoc-ref arguments 'subset)
252 ("core" 'core) ; only build core packages
253 (_ 'all))) ; build everything
254
255 (define (cross-jobs system)
256 (define (from-32-to-64? target)
257 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
258 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
259 ;; mips64el-linux-gnuabi64.
260 (and (or (string-prefix? "i686-" system)
261 (string-prefix? "armhf-" system))
262 (string-suffix? "64" target)))
263
264 (define (same? target)
265 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
266 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
267 ;; 'mips64el-linux'.
268 (string-contains target system))
269
270 (define (pointless? target)
271 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
272 (and (string-contains target "mingw")
273 (not (string=? "x86_64-linux" system))))
274
275 (define (either proc1 proc2 proc3)
276 (lambda (x)
277 (or (proc1 x) (proc2 x) (proc3 x))))
278
279 (append-map (lambda (target)
280 (map (lambda (package)
281 (package-cross-job store (job-name package)
282 package target system))
283 %packages-to-cross-build))
284 (remove (either from-32-to-64? same? pointless?)
285 %cross-targets)))
286
287 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
288 (parameterize ((%graft? #f))
289 ;; Return one job for each package, except bootstrap packages.
290 (append-map (lambda (system)
291 (case subset
292 ((all)
293 ;; Build everything, including replacements.
294 (let ((all (fold-packages
295 (lambda (package result)
296 (if (package-replacement package)
297 (cons* package
298 (package-replacement package)
299 result)
300 (cons package result)))
301 '()))
302 (job (lambda (package)
303 (package->job store package
304 system))))
305 (append (filter-map job all)
306 (qemu-jobs store system)
307 (system-test-jobs store system)
308 (tarball-jobs store system)
309 (cross-jobs system))))
310 ((core)
311 ;; Build core packages only.
312 (append (map (lambda (package)
313 (package-job store (job-name package)
314 package system))
315 %core-packages)
316 (cross-jobs system)))
317 (else
318 (error "unknown subset" subset))))
319 %hydra-supported-systems)))