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