gnu: arachne-pnr: Update to 840bdfdeb.
[jackhill/guix/guix.git] / gnu / ci.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu ci)
22 #:use-module (guix config)
23 #:use-module (guix store)
24 #:use-module (guix grafts)
25 #:use-module (guix profiles)
26 #:use-module (guix packages)
27 #:use-module (guix derivations)
28 #:use-module (guix monads)
29 #:use-module (guix ui)
30 #:use-module ((guix licenses)
31 #:select (gpl3+ license? license-name))
32 #:use-module ((guix utils) #:select (%current-system))
33 #:use-module ((guix scripts system) #:select (read-operating-system))
34 #:use-module ((guix scripts pack)
35 #:select (lookup-compressor self-contained-tarball))
36 #:use-module (gnu bootloader)
37 #:use-module (gnu bootloader u-boot)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages gcc)
40 #:use-module (gnu packages base)
41 #:use-module (gnu packages gawk)
42 #:use-module (gnu packages guile)
43 #:use-module (gnu packages gettext)
44 #:use-module (gnu packages compression)
45 #:use-module (gnu packages multiprecision)
46 #:use-module (gnu packages make-bootstrap)
47 #:use-module (gnu packages package-management)
48 #:use-module (gnu system)
49 #:use-module (gnu system vm)
50 #:use-module (gnu system install)
51 #:use-module (gnu tests)
52 #:use-module (srfi srfi-1)
53 #:use-module (srfi srfi-26)
54 #:use-module (ice-9 match)
55 #:export (hydra-jobs))
56
57 ;;; Commentary:
58 ;;;
59 ;;; This file defines build jobs for the Hydra and Cuirass continuation
60 ;;; integration tools.
61 ;;;
62 ;;; Code:
63
64 (define* (package->alist store package system
65 #:optional (package-derivation package-derivation))
66 "Convert PACKAGE to an alist suitable for Hydra."
67 (parameterize ((%graft? #f))
68 `((derivation . ,(derivation-file-name
69 (package-derivation store package system
70 #:graft? #f)))
71 (description . ,(package-synopsis package))
72 (long-description . ,(package-description package))
73
74 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
75 ;; list thereof.
76 (license . ,(let loop ((license (package-license package)))
77 (match license
78 ((? license?)
79 (license-name license))
80 ((lst ...)
81 (map loop license)))))
82
83 (home-page . ,(package-home-page package))
84 (maintainers . ("bug-guix@gnu.org"))
85 (max-silent-time . ,(or (assoc-ref (package-properties package)
86 'max-silent-time)
87 3600)) ;1 hour by default
88 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
89 72000))))) ;20 hours by default
90
91 (define (package-job store job-name package system)
92 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
93 (let ((job-name (symbol-append job-name (string->symbol ".")
94 (string->symbol system))))
95 `(,job-name . ,(cut package->alist store package system))))
96
97 (define (package-cross-job store job-name package target system)
98 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
99 SYSTEM."
100 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
101 (string->symbol ".") (string->symbol system)) .
102 ,(cute package->alist store package system
103 (lambda* (store package system #:key graft?)
104 (package-cross-derivation store package target system
105 #:graft? graft?)))))
106
107 (define %core-packages
108 ;; Note: Don't put the '-final' package variants because (1) that's
109 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
110 ;; chain.)
111 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
112 gmp mpfr mpc coreutils findutils diffutils patch sed grep
113 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
114 %bootstrap-binaries-tarball
115 %binutils-bootstrap-tarball
116 (%glibc-bootstrap-tarball)
117 %gcc-bootstrap-tarball
118 %guile-bootstrap-tarball
119 %bootstrap-tarballs))
120
121 (define %packages-to-cross-build
122 %core-packages)
123
124 (define %cross-targets
125 '("mips64el-linux-gnu"
126 "mips64el-linux-gnuabi64"
127 "arm-linux-gnueabihf"
128 "aarch64-linux-gnu"
129 "powerpc-linux-gnu"
130 "i586-pc-gnu" ;aka. GNU/Hurd
131 "i686-w64-mingw32"))
132
133 (define %guixsd-supported-systems
134 '("x86_64-linux" "i686-linux" "armhf-linux"))
135
136 (define %u-boot-systems
137 '("armhf-linux"))
138
139 (define (qemu-jobs store system)
140 "Return a list of jobs that build QEMU images for SYSTEM."
141 (define (->alist drv)
142 `((derivation . ,(derivation-file-name drv))
143 (description . "Stand-alone QEMU image of the GNU system")
144 (long-description . "This is a demo stand-alone QEMU image of the GNU
145 system.")
146 (license . ,(license-name gpl3+))
147 (max-silent-time . 600)
148 (timeout . 3600)
149 (home-page . ,%guix-home-page-url)
150 (maintainers . ("bug-guix@gnu.org"))))
151
152 (define (->job name drv)
153 (let ((name (symbol-append name (string->symbol ".")
154 (string->symbol system))))
155 `(,name . ,(lambda ()
156 (parameterize ((%graft? #f))
157 (->alist drv))))))
158
159 (define MiB
160 (expt 2 20))
161
162 (if (member system %guixsd-supported-systems)
163 (if (member system %u-boot-systems)
164 (list (->job 'flash-image
165 (run-with-store store
166 (mbegin %store-monad
167 (set-guile-for-build (default-guile))
168 (system-disk-image
169 (operating-system (inherit installation-os)
170 (bootloader (bootloader-configuration
171 (bootloader u-boot-bootloader)
172 (target #f))))
173 #:disk-image-size
174 (* 1500 MiB))))))
175 (list (->job 'usb-image
176 (run-with-store store
177 (mbegin %store-monad
178 (set-guile-for-build (default-guile))
179 (system-disk-image installation-os
180 #:disk-image-size
181 (* 1500 MiB)))))
182 (->job 'iso9660-image
183 (run-with-store store
184 (mbegin %store-monad
185 (set-guile-for-build (default-guile))
186 (system-disk-image installation-os
187 #:file-system-type
188 "iso9660"))))))
189 '()))
190
191 (define (system-test-jobs store system)
192 "Return a list of jobs for the system tests."
193 (define (test->thunk test)
194 (lambda ()
195 (define drv
196 (run-with-store store
197 (mbegin %store-monad
198 (set-current-system system)
199 (set-grafting #f)
200 (set-guile-for-build (default-guile))
201 (system-test-value test))))
202
203 `((derivation . ,(derivation-file-name drv))
204 (description . ,(format #f "GuixSD '~a' system test"
205 (system-test-name test)))
206 (long-description . ,(system-test-description test))
207 (license . ,(license-name gpl3+))
208 (max-silent-time . 600)
209 (timeout . 3600)
210 (home-page . ,%guix-home-page-url)
211 (maintainers . ("bug-guix@gnu.org")))))
212
213 (define (->job test)
214 (let ((name (string->symbol
215 (string-append "test." (system-test-name test)
216 "." system))))
217 (cons name (test->thunk test))))
218
219 (if (member system %guixsd-supported-systems)
220 (map ->job (all-system-tests))
221 '()))
222
223 (define (tarball-jobs store system)
224 "Return Hydra jobs to build the self-contained Guix binary tarball."
225 (define (->alist drv)
226 `((derivation . ,(derivation-file-name drv))
227 (description . "Stand-alone binary Guix tarball")
228 (long-description . "This is a tarball containing binaries of Guix and
229 all its dependencies, and ready to be installed on non-GuixSD distributions.")
230 (license . ,(license-name gpl3+))
231 (home-page . ,%guix-home-page-url)
232 (maintainers . ("bug-guix@gnu.org"))))
233
234 (define (->job name drv)
235 (let ((name (symbol-append name (string->symbol ".")
236 (string->symbol system))))
237 `(,name . ,(lambda ()
238 (parameterize ((%graft? #f))
239 (->alist drv))))))
240
241 ;; XXX: Add a job for the stable Guix?
242 (list (->job 'binary-tarball
243 (run-with-store store
244 (mbegin %store-monad
245 (set-guile-for-build (default-guile))
246 (>>= (profile-derivation (packages->manifest (list guix)))
247 (lambda (profile)
248 (self-contained-tarball "guix-binary" profile
249 #:localstatedir? #t
250 #:compressor
251 (lookup-compressor "xz")))))
252 #:system system))))
253
254 (define job-name
255 ;; Return the name of a package's job.
256 (compose string->symbol
257 (cut package-full-name <> "-")))
258
259 (define package->job
260 (let ((base-packages
261 (delete-duplicates
262 (append-map (match-lambda
263 ((_ package _ ...)
264 (match (package-transitive-inputs package)
265 (((_ inputs _ ...) ...)
266 inputs))))
267 (%final-inputs)))))
268 (lambda (store package system)
269 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
270 valid."
271 (cond ((member package base-packages)
272 (package-job store (symbol-append 'base. (job-name package))
273 package system))
274 ((supported-package? package system)
275 (let ((drv (package-derivation store package system
276 #:graft? #f)))
277 (and (substitutable-derivation? drv)
278 (package-job store (job-name package)
279 package system))))
280 (else
281 #f)))))
282
283 (define (all-packages)
284 "Return the list of packages to build."
285 (define (adjust package result)
286 (cond ((package-replacement package)
287 (cons* package ;build both
288 (package-replacement package)
289 result))
290 ((package-superseded package)
291 result) ;don't build it
292 (else
293 (cons package result))))
294
295 (fold-packages adjust
296 (fold adjust '() ;include base packages
297 (match (%final-inputs)
298 (((labels packages _ ...) ...)
299 packages)))
300 #:select? (const #t))) ;include hidden packages
301
302 (define (arguments->manifests arguments)
303 "Return the list of manifests extracted from ARGUMENTS."
304 (map (match-lambda
305 ((input-name . relative-path)
306 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
307 (base (assq-ref checkout 'file-name)))
308 (in-vicinity base relative-path))))
309 (assq-ref arguments 'manifests)))
310
311 (define (manifests->packages store manifests)
312 "Return the list of packages found in MANIFESTS."
313 (define (load-manifest manifest)
314 (save-module-excursion
315 (lambda ()
316 (set-current-module (make-user-module '((guix profiles) (gnu))))
317 (primitive-load manifest))))
318
319 (delete-duplicates!
320 (map manifest-entry-item
321 (append-map (compose manifest-entries
322 load-manifest)
323 manifests))))
324
325 \f
326 ;;;
327 ;;; Hydra entry point.
328 ;;;
329
330 (define (hydra-jobs store arguments)
331 "Return Hydra jobs."
332 (define subset
333 (match (assoc-ref arguments 'subset)
334 ("core" 'core) ; only build core packages
335 ("hello" 'hello) ; only build hello
336 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
337 ("manifests" 'manifests) ; only build packages in the list of manifests
338 (_ 'all))) ; build everything
339
340 (define systems
341 (match (assoc-ref arguments 'systems)
342 (#f %hydra-supported-systems)
343 ((lst ...) lst)
344 ((? string? str) (call-with-input-string str read))))
345
346 (define (cross-jobs system)
347 (define (from-32-to-64? target)
348 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
349 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
350 ;; mips64el-linux-gnuabi64.
351 (and (or (string-prefix? "i686-" system)
352 (string-prefix? "i586-" system)
353 (string-prefix? "armhf-" system))
354 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
355
356 (define (same? target)
357 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
358 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
359 ;; 'mips64el-linux'.
360 (or (string-contains target system)
361 (and (string-prefix? "armhf" system) ;armhf-linux
362 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
363
364 (define (pointless? target)
365 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
366 (match system
367 ((or "x86_64-linux" "i686-linux")
368 (if (string-contains target "mingw")
369 (not (string=? "x86_64-linux" system))
370 #f))
371 (_
372 ;; Don't try to cross-compile from non-Intel platforms: this isn't
373 ;; very useful and these are often brittle configurations.
374 #t)))
375
376 (define (either proc1 proc2 proc3)
377 (lambda (x)
378 (or (proc1 x) (proc2 x) (proc3 x))))
379
380 (append-map (lambda (target)
381 (map (lambda (package)
382 (package-cross-job store (job-name package)
383 package target system))
384 %packages-to-cross-build))
385 (remove (either from-32-to-64? same? pointless?)
386 %cross-targets)))
387
388 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
389 (parameterize ((%graft? #f))
390 ;; Return one job for each package, except bootstrap packages.
391 (append-map (lambda (system)
392 (format (current-error-port)
393 "evaluating for '~a' (heap size: ~a MiB)...~%"
394 system
395 (round
396 (/ (assoc-ref (gc-stats) 'heap-size)
397 (expt 2. 20))))
398 (invalidate-derivation-caches!)
399 (case subset
400 ((all)
401 ;; Build everything, including replacements.
402 (let ((all (all-packages))
403 (job (lambda (package)
404 (package->job store package
405 system))))
406 (append (filter-map job all)
407 (qemu-jobs store system)
408 (system-test-jobs store system)
409 (tarball-jobs store system)
410 (cross-jobs system))))
411 ((core)
412 ;; Build core packages only.
413 (append (map (lambda (package)
414 (package-job store (job-name package)
415 package system))
416 %core-packages)
417 (cross-jobs system)))
418 ((hello)
419 ;; Build hello package only.
420 (if (string=? system (%current-system))
421 (let ((hello (specification->package "hello")))
422 (list (package-job store (job-name hello) hello system)))
423 '()))
424 ((list)
425 ;; Build selected list of packages only.
426 (if (string=? system (%current-system))
427 (let* ((names (assoc-ref arguments 'subset))
428 (packages (map specification->package names)))
429 (map (lambda (package)
430 (package-job store (job-name package)
431 package system))
432 packages))
433 '()))
434 ((manifests)
435 ;; Build packages in the list of manifests.
436 (let* ((manifests (arguments->manifests arguments))
437 (packages (manifests->packages store manifests)))
438 (map (lambda (package)
439 (package-job store (job-name package)
440 package system))
441 packages)))
442 (else
443 (error "unknown subset" subset))))
444 systems)))