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