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