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