gnu: python-tblib: Update to 1.6.0.
[jackhill/guix/guix.git] / gnu / ci.scm
CommitLineData
59fb5c1c 1;;; GNU Guix --- Functional package management for GNU
2032d847 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
59fb5c1c 3;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
f71b0a00 4;;; Copyright © 2018, 2019 Clément Lassieur <clement@lassieur.org>
59fb5c1c
LC
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)
7e6d8d36 27 #:use-module (guix channels)
59fb5c1c 28 #:use-module (guix derivations)
7e6d8d36 29 #:use-module (guix build-system)
59fb5c1c 30 #:use-module (guix monads)
dd1ee160 31 #:use-module (guix gexp)
59fb5c1c 32 #:use-module (guix ui)
b5f8c2c8
LC
33 #:use-module ((guix licenses)
34 #:select (gpl3+ license? license-name))
59fb5c1c
LC
35 #:use-module ((guix utils) #:select (%current-system))
36 #:use-module ((guix scripts system) #:select (read-operating-system))
37 #:use-module ((guix scripts pack)
38 #:select (lookup-compressor self-contained-tarball))
39 #:use-module (gnu bootloader)
40 #:use-module (gnu bootloader u-boot)
41 #:use-module (gnu packages)
42 #:use-module (gnu packages gcc)
43 #:use-module (gnu packages base)
44 #:use-module (gnu packages gawk)
45 #:use-module (gnu packages guile)
46 #:use-module (gnu packages gettext)
47 #:use-module (gnu packages compression)
48 #:use-module (gnu packages multiprecision)
49 #:use-module (gnu packages make-bootstrap)
50 #:use-module (gnu packages package-management)
51 #:use-module (gnu system)
52 #:use-module (gnu system vm)
53 #:use-module (gnu system install)
54 #:use-module (gnu tests)
55 #:use-module (srfi srfi-1)
56 #:use-module (srfi srfi-26)
57 #:use-module (ice-9 match)
f292c501
LC
58 #:export (%cross-targets
59 channel-source->package
887fd835 60 hydra-jobs))
59fb5c1c
LC
61
62;;; Commentary:
63;;;
64;;; This file defines build jobs for the Hydra and Cuirass continuation
65;;; integration tools.
66;;;
67;;; Code:
68
69(define* (package->alist store package system
70 #:optional (package-derivation package-derivation))
71 "Convert PACKAGE to an alist suitable for Hydra."
72 (parameterize ((%graft? #f))
73 `((derivation . ,(derivation-file-name
74 (package-derivation store package system
75 #:graft? #f)))
76 (description . ,(package-synopsis package))
77 (long-description . ,(package-description package))
b5f8c2c8
LC
78
79 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
80 ;; list thereof.
81 (license . ,(let loop ((license (package-license package)))
82 (match license
83 ((? license?)
84 (license-name license))
85 ((lst ...)
86 (map loop license)))))
87
59fb5c1c
LC
88 (home-page . ,(package-home-page package))
89 (maintainers . ("bug-guix@gnu.org"))
90 (max-silent-time . ,(or (assoc-ref (package-properties package)
91 'max-silent-time)
92 3600)) ;1 hour by default
93 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
94 72000))))) ;20 hours by default
95
96(define (package-job store job-name package system)
97 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
98 (let ((job-name (symbol-append job-name (string->symbol ".")
99 (string->symbol system))))
100 `(,job-name . ,(cut package->alist store package system))))
101
102(define (package-cross-job store job-name package target system)
103 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
104SYSTEM."
105 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
106 (string->symbol ".") (string->symbol system)) .
107 ,(cute package->alist store package system
108 (lambda* (store package system #:key graft?)
109 (package-cross-derivation store package target system
110 #:graft? graft?)))))
111
112(define %core-packages
113 ;; Note: Don't put the '-final' package variants because (1) that's
114 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
115 ;; chain.)
116 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
117 gmp mpfr mpc coreutils findutils diffutils patch sed grep
118 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
119 %bootstrap-binaries-tarball
120 %binutils-bootstrap-tarball
121 (%glibc-bootstrap-tarball)
122 %gcc-bootstrap-tarball
123 %guile-bootstrap-tarball
124 %bootstrap-tarballs))
125
126(define %packages-to-cross-build
127 %core-packages)
128
129(define %cross-targets
130 '("mips64el-linux-gnu"
131 "mips64el-linux-gnuabi64"
132 "arm-linux-gnueabihf"
133 "aarch64-linux-gnu"
134 "powerpc-linux-gnu"
2032d847 135 "riscv64-linux-gnu"
59fb5c1c 136 "i586-pc-gnu" ;aka. GNU/Hurd
67dac6b8
CD
137 "i686-w64-mingw32"
138 "x86_64-w64-mingw32"))
59fb5c1c 139
3046e73b
LC
140(define (cross-jobs store system)
141 "Return a list of cross-compilation jobs for SYSTEM."
142 (define (from-32-to-64? target)
143 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
144 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
145 ;; mips64el-linux-gnuabi64.
146 (and (or (string-prefix? "i686-" system)
147 (string-prefix? "i586-" system)
148 (string-prefix? "armhf-" system))
149 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
150
151 (define (same? target)
152 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
153 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
154 ;; 'mips64el-linux'.
155 (or (string-contains target system)
156 (and (string-prefix? "armhf" system) ;armhf-linux
157 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
158
159 (define (pointless? target)
160 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
161 (match system
162 ((or "x86_64-linux" "i686-linux")
163 (if (string-contains target "mingw")
164 (not (string=? "x86_64-linux" system))
165 #f))
166 (_
167 ;; Don't try to cross-compile from non-Intel platforms: this isn't
168 ;; very useful and these are often brittle configurations.
169 #t)))
170
171 (define (either proc1 proc2 proc3)
172 (lambda (x)
173 (or (proc1 x) (proc2 x) (proc3 x))))
174
175 (append-map (lambda (target)
176 (map (lambda (package)
177 (package-cross-job store (job-name package)
178 package target system))
179 %packages-to-cross-build))
180 (remove (either from-32-to-64? same? pointless?)
181 %cross-targets)))
182
59fb5c1c
LC
183(define %guixsd-supported-systems
184 '("x86_64-linux" "i686-linux" "armhf-linux"))
185
186(define %u-boot-systems
187 '("armhf-linux"))
188
189(define (qemu-jobs store system)
190 "Return a list of jobs that build QEMU images for SYSTEM."
191 (define (->alist drv)
192 `((derivation . ,(derivation-file-name drv))
193 (description . "Stand-alone QEMU image of the GNU system")
194 (long-description . "This is a demo stand-alone QEMU image of the GNU
195system.")
b5f8c2c8 196 (license . ,(license-name gpl3+))
59fb5c1c
LC
197 (max-silent-time . 600)
198 (timeout . 3600)
199 (home-page . ,%guix-home-page-url)
200 (maintainers . ("bug-guix@gnu.org"))))
201
202 (define (->job name drv)
203 (let ((name (symbol-append name (string->symbol ".")
204 (string->symbol system))))
205 `(,name . ,(lambda ()
206 (parameterize ((%graft? #f))
207 (->alist drv))))))
208
209 (define MiB
210 (expt 2 20))
211
212 (if (member system %guixsd-supported-systems)
213 (if (member system %u-boot-systems)
214 (list (->job 'flash-image
215 (run-with-store store
216 (mbegin %store-monad
217 (set-guile-for-build (default-guile))
218 (system-disk-image
219 (operating-system (inherit installation-os)
220 (bootloader (bootloader-configuration
221 (bootloader u-boot-bootloader)
222 (target #f))))
223 #:disk-image-size
224 (* 1500 MiB))))))
225 (list (->job 'usb-image
226 (run-with-store store
227 (mbegin %store-monad
228 (set-guile-for-build (default-guile))
229 (system-disk-image installation-os
230 #:disk-image-size
231 (* 1500 MiB)))))
232 (->job 'iso9660-image
233 (run-with-store store
234 (mbegin %store-monad
235 (set-guile-for-build (default-guile))
236 (system-disk-image installation-os
237 #:file-system-type
238 "iso9660"))))))
239 '()))
240
7e6d8d36
LC
241(define channel-build-system
242 ;; Build system used to "convert" a channel instance to a package.
243 (let* ((build (lambda* (store name inputs
dd1ee160 244 #:key source commit system
c3ab921e 245 #:allow-other-keys)
7e6d8d36 246 (run-with-store store
bc8b2ffd
LC
247 ;; SOURCE can be a lowerable object such as <local-file>
248 ;; or a file name. Adjust accordingly.
249 (mlet* %store-monad ((source (if (string? source)
250 (return source)
251 (lower-object source)))
dd1ee160
LC
252 (instance
253 -> (checkout->channel-instance
254 source #:commit commit)))
255 (channel-instances->derivation (list instance)))
c3ab921e 256 #:system system)))
dd1ee160
LC
257 (lower (lambda* (name #:key system source commit
258 #:allow-other-keys)
7e6d8d36
LC
259 (bag
260 (name name)
261 (system system)
262 (build build)
dd1ee160
LC
263 (arguments `(#:source ,source
264 #:commit ,commit))))))
7e6d8d36
LC
265 (build-system (name 'channel)
266 (description "Turn a channel instance into a package.")
267 (lower lower))))
268
dd1ee160
LC
269(define* (channel-source->package source #:key commit)
270 "Return a package for the given channel SOURCE, a lowerable object."
7e6d8d36
LC
271 (package
272 (inherit guix)
dd1ee160 273 (version (string-append (package-version guix) "+"))
7e6d8d36 274 (build-system channel-build-system)
dd1ee160
LC
275 (arguments `(#:source ,source
276 #:commit ,commit))
7e6d8d36
LC
277 (inputs '())
278 (native-inputs '())
279 (propagated-inputs '())))
280
281(define* (system-test-jobs store system
282 #:key source commit)
59fb5c1c
LC
283 "Return a list of jobs for the system tests."
284 (define (test->thunk test)
285 (lambda ()
286 (define drv
287 (run-with-store store
288 (mbegin %store-monad
289 (set-current-system system)
290 (set-grafting #f)
291 (set-guile-for-build (default-guile))
292 (system-test-value test))))
293
294 `((derivation . ,(derivation-file-name drv))
59e80445 295 (description . ,(format #f "Guix '~a' system test"
59fb5c1c
LC
296 (system-test-name test)))
297 (long-description . ,(system-test-description test))
b5f8c2c8 298 (license . ,(license-name gpl3+))
59fb5c1c
LC
299 (max-silent-time . 600)
300 (timeout . 3600)
301 (home-page . ,%guix-home-page-url)
302 (maintainers . ("bug-guix@gnu.org")))))
303
304 (define (->job test)
305 (let ((name (string->symbol
306 (string-append "test." (system-test-name test)
307 "." system))))
308 (cons name (test->thunk test))))
309
c680a7da
LC
310 (if (and (member system %guixsd-supported-systems)
311
312 ;; XXX: Our build farm has too few ARMv7 machines and they are very
313 ;; slow, so skip system tests there.
314 (not (string=? system "armhf-linux")))
7e6d8d36
LC
315 ;; Override the value of 'current-guix' used by system tests. Using a
316 ;; channel instance makes tests that rely on 'current-guix' less
317 ;; expensive. It also makes sure we get a valid Guix package when this
318 ;; code is not running from a checkout.
319 (parameterize ((current-guix-package
dd1ee160 320 (channel-source->package source #:commit commit)))
7e6d8d36 321 (map ->job (all-system-tests)))
59fb5c1c
LC
322 '()))
323
324(define (tarball-jobs store system)
325 "Return Hydra jobs to build the self-contained Guix binary tarball."
326 (define (->alist drv)
327 `((derivation . ,(derivation-file-name drv))
328 (description . "Stand-alone binary Guix tarball")
329 (long-description . "This is a tarball containing binaries of Guix and
59e80445 330all its dependencies, and ready to be installed on \"foreign\" distributions.")
b5f8c2c8 331 (license . ,(license-name gpl3+))
59fb5c1c
LC
332 (home-page . ,%guix-home-page-url)
333 (maintainers . ("bug-guix@gnu.org"))))
334
335 (define (->job name drv)
336 (let ((name (symbol-append name (string->symbol ".")
337 (string->symbol system))))
338 `(,name . ,(lambda ()
339 (parameterize ((%graft? #f))
340 (->alist drv))))))
341
342 ;; XXX: Add a job for the stable Guix?
343 (list (->job 'binary-tarball
344 (run-with-store store
345 (mbegin %store-monad
346 (set-guile-for-build (default-guile))
347 (>>= (profile-derivation (packages->manifest (list guix)))
348 (lambda (profile)
349 (self-contained-tarball "guix-binary" profile
350 #:localstatedir? #t
351 #:compressor
352 (lookup-compressor "xz")))))
353 #:system system))))
354
355(define job-name
356 ;; Return the name of a package's job.
357 (compose string->symbol
358 (cut package-full-name <> "-")))
359
360(define package->job
361 (let ((base-packages
362 (delete-duplicates
363 (append-map (match-lambda
364 ((_ package _ ...)
365 (match (package-transitive-inputs package)
366 (((_ inputs _ ...) ...)
367 inputs))))
368 (%final-inputs)))))
369 (lambda (store package system)
370 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
371valid."
372 (cond ((member package base-packages)
373 (package-job store (symbol-append 'base. (job-name package))
374 package system))
375 ((supported-package? package system)
376 (let ((drv (package-derivation store package system
377 #:graft? #f)))
378 (and (substitutable-derivation? drv)
379 (package-job store (job-name package)
380 package system))))
381 (else
382 #f)))))
383
384(define (all-packages)
385 "Return the list of packages to build."
386 (define (adjust package result)
387 (cond ((package-replacement package)
f00ff8db
LC
388 ;; XXX: If PACKAGE and its replacement have the same name/version,
389 ;; then both Cuirass jobs will have the same name, which
390 ;; effectively means that the second one will be ignored. Thus,
391 ;; return the replacement first.
392 (cons* (package-replacement package) ;build both
393 package
59fb5c1c
LC
394 result))
395 ((package-superseded package)
396 result) ;don't build it
397 (else
398 (cons package result))))
399
400 (fold-packages adjust
401 (fold adjust '() ;include base packages
402 (match (%final-inputs)
403 (((labels packages _ ...) ...)
404 packages)))
405 #:select? (const #t))) ;include hidden packages
406
407(define (arguments->manifests arguments)
408 "Return the list of manifests extracted from ARGUMENTS."
409 (map (match-lambda
410 ((input-name . relative-path)
411 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
412 (base (assq-ref checkout 'file-name)))
413 (in-vicinity base relative-path))))
414 (assq-ref arguments 'manifests)))
415
416(define (manifests->packages store manifests)
417 "Return the list of packages found in MANIFESTS."
418 (define (load-manifest manifest)
419 (save-module-excursion
420 (lambda ()
421 (set-current-module (make-user-module '((guix profiles) (gnu))))
422 (primitive-load manifest))))
423
424 (delete-duplicates!
425 (map manifest-entry-item
426 (append-map (compose manifest-entries
427 load-manifest)
428 manifests))))
429
f71b0a00
CL
430(define (find-current-checkout arguments)
431 "Find the first checkout of ARGUMENTS that provided the current file.
432Return #f if no such checkout is found."
433 (let ((current-root
434 (canonicalize-path
435 (string-append (dirname (current-filename)) "/.."))))
436 (find (lambda (argument)
437 (and=> (assq-ref argument 'file-name)
438 (lambda (name)
439 (string=? name current-root)))) arguments)))
440
59fb5c1c
LC
441\f
442;;;
443;;; Hydra entry point.
444;;;
445
446(define (hydra-jobs store arguments)
447 "Return Hydra jobs."
448 (define subset
449 (match (assoc-ref arguments 'subset)
450 ("core" 'core) ; only build core packages
451 ("hello" 'hello) ; only build hello
452 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
453 ("manifests" 'manifests) ; only build packages in the list of manifests
454 (_ 'all))) ; build everything
455
456 (define systems
457 (match (assoc-ref arguments 'systems)
458 (#f %hydra-supported-systems)
459 ((lst ...) lst)
460 ((? string? str) (call-with-input-string str read))))
461
7e6d8d36 462 (define checkout
f71b0a00
CL
463 (or (find-current-checkout arguments)
464 (assq-ref arguments 'superior-guix-checkout)))
7e6d8d36
LC
465
466 (define commit
467 (assq-ref checkout 'revision))
468
469 (define source
470 (assq-ref checkout 'file-name))
471
59fb5c1c
LC
472 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
473 (parameterize ((%graft? #f))
474 ;; Return one job for each package, except bootstrap packages.
475 (append-map (lambda (system)
476 (format (current-error-port)
477 "evaluating for '~a' (heap size: ~a MiB)...~%"
478 system
479 (round
480 (/ (assoc-ref (gc-stats) 'heap-size)
481 (expt 2. 20))))
482 (invalidate-derivation-caches!)
483 (case subset
484 ((all)
485 ;; Build everything, including replacements.
486 (let ((all (all-packages))
487 (job (lambda (package)
488 (package->job store package
489 system))))
490 (append (filter-map job all)
491 (qemu-jobs store system)
7e6d8d36
LC
492 (system-test-jobs store system
493 #:source source
494 #:commit commit)
59fb5c1c 495 (tarball-jobs store system)
3046e73b 496 (cross-jobs store system))))
59fb5c1c
LC
497 ((core)
498 ;; Build core packages only.
499 (append (map (lambda (package)
500 (package-job store (job-name package)
501 package system))
502 %core-packages)
3046e73b 503 (cross-jobs store system)))
59fb5c1c
LC
504 ((hello)
505 ;; Build hello package only.
506 (if (string=? system (%current-system))
507 (let ((hello (specification->package "hello")))
508 (list (package-job store (job-name hello) hello system)))
509 '()))
510 ((list)
511 ;; Build selected list of packages only.
512 (if (string=? system (%current-system))
513 (let* ((names (assoc-ref arguments 'subset))
514 (packages (map specification->package names)))
515 (map (lambda (package)
516 (package-job store (job-name package)
517 package system))
518 packages))
519 '()))
520 ((manifests)
521 ;; Build packages in the list of manifests.
522 (let* ((manifests (arguments->manifests arguments))
523 (packages (manifests->packages store manifests)))
524 (map (lambda (package)
525 (package-job store (job-name package)
526 package system))
527 packages)))
528 (else
529 (error "unknown subset" subset))))
530 systems)))