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