gnu: r-pracma: Move to (gnu packages cran).
[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)
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"
133 "i586-pc-gnu" ;aka. GNU/Hurd
67dac6b8
CD
134 "i686-w64-mingw32"
135 "x86_64-w64-mingw32"))
59fb5c1c
LC
136
137(define %guixsd-supported-systems
138 '("x86_64-linux" "i686-linux" "armhf-linux"))
139
140(define %u-boot-systems
141 '("armhf-linux"))
142
143(define (qemu-jobs store system)
144 "Return a list of jobs that build QEMU images for SYSTEM."
145 (define (->alist drv)
146 `((derivation . ,(derivation-file-name drv))
147 (description . "Stand-alone QEMU image of the GNU system")
148 (long-description . "This is a demo stand-alone QEMU image of the GNU
149system.")
b5f8c2c8 150 (license . ,(license-name gpl3+))
59fb5c1c
LC
151 (max-silent-time . 600)
152 (timeout . 3600)
153 (home-page . ,%guix-home-page-url)
154 (maintainers . ("bug-guix@gnu.org"))))
155
156 (define (->job name drv)
157 (let ((name (symbol-append name (string->symbol ".")
158 (string->symbol system))))
159 `(,name . ,(lambda ()
160 (parameterize ((%graft? #f))
161 (->alist drv))))))
162
163 (define MiB
164 (expt 2 20))
165
166 (if (member system %guixsd-supported-systems)
167 (if (member system %u-boot-systems)
168 (list (->job 'flash-image
169 (run-with-store store
170 (mbegin %store-monad
171 (set-guile-for-build (default-guile))
172 (system-disk-image
173 (operating-system (inherit installation-os)
174 (bootloader (bootloader-configuration
175 (bootloader u-boot-bootloader)
176 (target #f))))
177 #:disk-image-size
178 (* 1500 MiB))))))
179 (list (->job 'usb-image
180 (run-with-store store
181 (mbegin %store-monad
182 (set-guile-for-build (default-guile))
183 (system-disk-image installation-os
184 #:disk-image-size
185 (* 1500 MiB)))))
186 (->job 'iso9660-image
187 (run-with-store store
188 (mbegin %store-monad
189 (set-guile-for-build (default-guile))
190 (system-disk-image installation-os
191 #:file-system-type
192 "iso9660"))))))
193 '()))
194
7e6d8d36
LC
195(define channel-build-system
196 ;; Build system used to "convert" a channel instance to a package.
197 (let* ((build (lambda* (store name inputs
c3ab921e
LC
198 #:key instance system
199 #:allow-other-keys)
7e6d8d36 200 (run-with-store store
c3ab921e
LC
201 (channel-instances->derivation (list instance))
202 #:system system)))
7e6d8d36
LC
203 (lower (lambda* (name #:key system instance #:allow-other-keys)
204 (bag
205 (name name)
206 (system system)
207 (build build)
208 (arguments `(#:instance ,instance))))))
209 (build-system (name 'channel)
210 (description "Turn a channel instance into a package.")
211 (lower lower))))
212
213(define (channel-instance->package instance)
214 "Return a package for the given channel INSTANCE."
215 (package
216 (inherit guix)
217 (version (or (string-take (channel-instance-commit instance) 7)
218 (string-append (package-version guix) "+")))
219 (build-system channel-build-system)
220 (arguments `(#:instance ,instance))
221 (inputs '())
222 (native-inputs '())
223 (propagated-inputs '())))
224
225(define* (system-test-jobs store system
226 #:key source commit)
59fb5c1c 227 "Return a list of jobs for the system tests."
7e6d8d36
LC
228 (define instance
229 (checkout->channel-instance source #:commit commit))
230
59fb5c1c
LC
231 (define (test->thunk test)
232 (lambda ()
233 (define drv
234 (run-with-store store
235 (mbegin %store-monad
236 (set-current-system system)
237 (set-grafting #f)
238 (set-guile-for-build (default-guile))
239 (system-test-value test))))
240
241 `((derivation . ,(derivation-file-name drv))
59e80445 242 (description . ,(format #f "Guix '~a' system test"
59fb5c1c
LC
243 (system-test-name test)))
244 (long-description . ,(system-test-description test))
b5f8c2c8 245 (license . ,(license-name gpl3+))
59fb5c1c
LC
246 (max-silent-time . 600)
247 (timeout . 3600)
248 (home-page . ,%guix-home-page-url)
249 (maintainers . ("bug-guix@gnu.org")))))
250
251 (define (->job test)
252 (let ((name (string->symbol
253 (string-append "test." (system-test-name test)
254 "." system))))
255 (cons name (test->thunk test))))
256
c680a7da
LC
257 (if (and (member system %guixsd-supported-systems)
258
259 ;; XXX: Our build farm has too few ARMv7 machines and they are very
260 ;; slow, so skip system tests there.
261 (not (string=? system "armhf-linux")))
7e6d8d36
LC
262 ;; Override the value of 'current-guix' used by system tests. Using a
263 ;; channel instance makes tests that rely on 'current-guix' less
264 ;; expensive. It also makes sure we get a valid Guix package when this
265 ;; code is not running from a checkout.
266 (parameterize ((current-guix-package
267 (channel-instance->package instance)))
268 (map ->job (all-system-tests)))
59fb5c1c
LC
269 '()))
270
271(define (tarball-jobs store system)
272 "Return Hydra jobs to build the self-contained Guix binary tarball."
273 (define (->alist drv)
274 `((derivation . ,(derivation-file-name drv))
275 (description . "Stand-alone binary Guix tarball")
276 (long-description . "This is a tarball containing binaries of Guix and
59e80445 277all its dependencies, and ready to be installed on \"foreign\" distributions.")
b5f8c2c8 278 (license . ,(license-name gpl3+))
59fb5c1c
LC
279 (home-page . ,%guix-home-page-url)
280 (maintainers . ("bug-guix@gnu.org"))))
281
282 (define (->job name drv)
283 (let ((name (symbol-append name (string->symbol ".")
284 (string->symbol system))))
285 `(,name . ,(lambda ()
286 (parameterize ((%graft? #f))
287 (->alist drv))))))
288
289 ;; XXX: Add a job for the stable Guix?
290 (list (->job 'binary-tarball
291 (run-with-store store
292 (mbegin %store-monad
293 (set-guile-for-build (default-guile))
294 (>>= (profile-derivation (packages->manifest (list guix)))
295 (lambda (profile)
296 (self-contained-tarball "guix-binary" profile
297 #:localstatedir? #t
298 #:compressor
299 (lookup-compressor "xz")))))
300 #:system system))))
301
302(define job-name
303 ;; Return the name of a package's job.
304 (compose string->symbol
305 (cut package-full-name <> "-")))
306
307(define package->job
308 (let ((base-packages
309 (delete-duplicates
310 (append-map (match-lambda
311 ((_ package _ ...)
312 (match (package-transitive-inputs package)
313 (((_ inputs _ ...) ...)
314 inputs))))
315 (%final-inputs)))))
316 (lambda (store package system)
317 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
318valid."
319 (cond ((member package base-packages)
320 (package-job store (symbol-append 'base. (job-name package))
321 package system))
322 ((supported-package? package system)
323 (let ((drv (package-derivation store package system
324 #:graft? #f)))
325 (and (substitutable-derivation? drv)
326 (package-job store (job-name package)
327 package system))))
328 (else
329 #f)))))
330
331(define (all-packages)
332 "Return the list of packages to build."
333 (define (adjust package result)
334 (cond ((package-replacement package)
f00ff8db
LC
335 ;; XXX: If PACKAGE and its replacement have the same name/version,
336 ;; then both Cuirass jobs will have the same name, which
337 ;; effectively means that the second one will be ignored. Thus,
338 ;; return the replacement first.
339 (cons* (package-replacement package) ;build both
340 package
59fb5c1c
LC
341 result))
342 ((package-superseded package)
343 result) ;don't build it
344 (else
345 (cons package result))))
346
347 (fold-packages adjust
348 (fold adjust '() ;include base packages
349 (match (%final-inputs)
350 (((labels packages _ ...) ...)
351 packages)))
352 #:select? (const #t))) ;include hidden packages
353
354(define (arguments->manifests arguments)
355 "Return the list of manifests extracted from ARGUMENTS."
356 (map (match-lambda
357 ((input-name . relative-path)
358 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
359 (base (assq-ref checkout 'file-name)))
360 (in-vicinity base relative-path))))
361 (assq-ref arguments 'manifests)))
362
363(define (manifests->packages store manifests)
364 "Return the list of packages found in MANIFESTS."
365 (define (load-manifest manifest)
366 (save-module-excursion
367 (lambda ()
368 (set-current-module (make-user-module '((guix profiles) (gnu))))
369 (primitive-load manifest))))
370
371 (delete-duplicates!
372 (map manifest-entry-item
373 (append-map (compose manifest-entries
374 load-manifest)
375 manifests))))
376
377\f
378;;;
379;;; Hydra entry point.
380;;;
381
382(define (hydra-jobs store arguments)
383 "Return Hydra jobs."
384 (define subset
385 (match (assoc-ref arguments 'subset)
386 ("core" 'core) ; only build core packages
387 ("hello" 'hello) ; only build hello
388 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
389 ("manifests" 'manifests) ; only build packages in the list of manifests
390 (_ 'all))) ; build everything
391
392 (define systems
393 (match (assoc-ref arguments 'systems)
394 (#f %hydra-supported-systems)
395 ((lst ...) lst)
396 ((? string? str) (call-with-input-string str read))))
397
7e6d8d36
LC
398 (define checkout
399 ;; Extract metadata about the 'guix' checkout. Its key in ARGUMENTS may
400 ;; vary, so pick up the first one that's neither 'subset' nor 'systems'.
401 (any (match-lambda
402 ((key . value)
403 (and (not (memq key '(systems subset)))
404 value)))
405 arguments))
406
407 (define commit
408 (assq-ref checkout 'revision))
409
410 (define source
411 (assq-ref checkout 'file-name))
412
59fb5c1c
LC
413 (define (cross-jobs system)
414 (define (from-32-to-64? target)
415 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
416 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
417 ;; mips64el-linux-gnuabi64.
418 (and (or (string-prefix? "i686-" system)
419 (string-prefix? "i586-" system)
420 (string-prefix? "armhf-" system))
421 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
422
423 (define (same? target)
424 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
425 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
426 ;; 'mips64el-linux'.
427 (or (string-contains target system)
428 (and (string-prefix? "armhf" system) ;armhf-linux
429 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
430
431 (define (pointless? target)
432 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
433 (match system
434 ((or "x86_64-linux" "i686-linux")
435 (if (string-contains target "mingw")
436 (not (string=? "x86_64-linux" system))
437 #f))
438 (_
439 ;; Don't try to cross-compile from non-Intel platforms: this isn't
440 ;; very useful and these are often brittle configurations.
441 #t)))
442
443 (define (either proc1 proc2 proc3)
444 (lambda (x)
445 (or (proc1 x) (proc2 x) (proc3 x))))
446
447 (append-map (lambda (target)
448 (map (lambda (package)
449 (package-cross-job store (job-name package)
450 package target system))
451 %packages-to-cross-build))
452 (remove (either from-32-to-64? same? pointless?)
453 %cross-targets)))
454
455 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
456 (parameterize ((%graft? #f))
457 ;; Return one job for each package, except bootstrap packages.
458 (append-map (lambda (system)
459 (format (current-error-port)
460 "evaluating for '~a' (heap size: ~a MiB)...~%"
461 system
462 (round
463 (/ (assoc-ref (gc-stats) 'heap-size)
464 (expt 2. 20))))
465 (invalidate-derivation-caches!)
466 (case subset
467 ((all)
468 ;; Build everything, including replacements.
469 (let ((all (all-packages))
470 (job (lambda (package)
471 (package->job store package
472 system))))
473 (append (filter-map job all)
474 (qemu-jobs store system)
7e6d8d36
LC
475 (system-test-jobs store system
476 #:source source
477 #:commit commit)
59fb5c1c
LC
478 (tarball-jobs store system)
479 (cross-jobs system))))
480 ((core)
481 ;; Build core packages only.
482 (append (map (lambda (package)
483 (package-job store (job-name package)
484 package system))
485 %core-packages)
486 (cross-jobs system)))
487 ((hello)
488 ;; Build hello package only.
489 (if (string=? system (%current-system))
490 (let ((hello (specification->package "hello")))
491 (list (package-job store (job-name hello) hello system)))
492 '()))
493 ((list)
494 ;; Build selected list of packages only.
495 (if (string=? system (%current-system))
496 (let* ((names (assoc-ref arguments 'subset))
497 (packages (map specification->package names)))
498 (map (lambda (package)
499 (package-job store (job-name package)
500 package system))
501 packages))
502 '()))
503 ((manifests)
504 ;; Build packages in the list of manifests.
505 (let* ((manifests (arguments->manifests arguments))
506 (packages (manifests->packages store manifests)))
507 (map (lambda (package)
508 (package-job store (job-name package)
509 package system))
510 packages)))
511 (else
512 (error "unknown subset" subset))))
513 systems)))