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