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