gnu: Add emacs-company-reftex.
[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.)
121 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
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
240 (string-append "GUIX_" system "_" %guix-version)))
b06ba9e0
MO
241 (operating-system installation-os))))
242 ;; Only cross-compile Guix System images from x86_64-linux for now.
243 ,@(if (string=? system "x86_64-linux")
244 (map (lambda (image)
245 (->job (image-name image) (build-image image)))
246 %guix-system-images)
247 '()))
1189f405 248 '()))
59fb5c1c 249
7e6d8d36
LC
250(define channel-build-system
251 ;; Build system used to "convert" a channel instance to a package.
252 (let* ((build (lambda* (store name inputs
dd1ee160 253 #:key source commit system
c3ab921e 254 #:allow-other-keys)
7e6d8d36 255 (run-with-store store
bc8b2ffd
LC
256 ;; SOURCE can be a lowerable object such as <local-file>
257 ;; or a file name. Adjust accordingly.
258 (mlet* %store-monad ((source (if (string? source)
259 (return source)
260 (lower-object source)))
dd1ee160
LC
261 (instance
262 -> (checkout->channel-instance
263 source #:commit commit)))
264 (channel-instances->derivation (list instance)))
c3ab921e 265 #:system system)))
dd1ee160
LC
266 (lower (lambda* (name #:key system source commit
267 #:allow-other-keys)
7e6d8d36
LC
268 (bag
269 (name name)
270 (system system)
271 (build build)
dd1ee160
LC
272 (arguments `(#:source ,source
273 #:commit ,commit))))))
7e6d8d36
LC
274 (build-system (name 'channel)
275 (description "Turn a channel instance into a package.")
276 (lower lower))))
277
dd1ee160
LC
278(define* (channel-source->package source #:key commit)
279 "Return a package for the given channel SOURCE, a lowerable object."
7e6d8d36
LC
280 (package
281 (inherit guix)
dd1ee160 282 (version (string-append (package-version guix) "+"))
7e6d8d36 283 (build-system channel-build-system)
dd1ee160
LC
284 (arguments `(#:source ,source
285 #:commit ,commit))
7e6d8d36
LC
286 (inputs '())
287 (native-inputs '())
288 (propagated-inputs '())))
289
290(define* (system-test-jobs store system
291 #:key source commit)
59fb5c1c
LC
292 "Return a list of jobs for the system tests."
293 (define (test->thunk test)
294 (lambda ()
295 (define drv
296 (run-with-store store
297 (mbegin %store-monad
298 (set-current-system system)
299 (set-grafting #f)
300 (set-guile-for-build (default-guile))
301 (system-test-value test))))
302
303 `((derivation . ,(derivation-file-name drv))
59e80445 304 (description . ,(format #f "Guix '~a' system test"
59fb5c1c
LC
305 (system-test-name test)))
306 (long-description . ,(system-test-description test))
b5f8c2c8 307 (license . ,(license-name gpl3+))
59fb5c1c
LC
308 (max-silent-time . 600)
309 (timeout . 3600)
310 (home-page . ,%guix-home-page-url)
311 (maintainers . ("bug-guix@gnu.org")))))
312
313 (define (->job test)
314 (let ((name (string->symbol
315 (string-append "test." (system-test-name test)
316 "." system))))
317 (cons name (test->thunk test))))
318
b06ba9e0 319 (if (member system %guix-system-supported-systems)
7e6d8d36
LC
320 ;; Override the value of 'current-guix' used by system tests. Using a
321 ;; channel instance makes tests that rely on 'current-guix' less
322 ;; expensive. It also makes sure we get a valid Guix package when this
323 ;; code is not running from a checkout.
324 (parameterize ((current-guix-package
dd1ee160 325 (channel-source->package source #:commit commit)))
7e6d8d36 326 (map ->job (all-system-tests)))
59fb5c1c
LC
327 '()))
328
329(define (tarball-jobs store system)
330 "Return Hydra jobs to build the self-contained Guix binary tarball."
331 (define (->alist drv)
332 `((derivation . ,(derivation-file-name drv))
333 (description . "Stand-alone binary Guix tarball")
334 (long-description . "This is a tarball containing binaries of Guix and
59e80445 335all its dependencies, and ready to be installed on \"foreign\" distributions.")
b5f8c2c8 336 (license . ,(license-name gpl3+))
59fb5c1c
LC
337 (home-page . ,%guix-home-page-url)
338 (maintainers . ("bug-guix@gnu.org"))))
339
340 (define (->job name drv)
341 (let ((name (symbol-append name (string->symbol ".")
342 (string->symbol system))))
343 `(,name . ,(lambda ()
344 (parameterize ((%graft? #f))
345 (->alist drv))))))
346
347 ;; XXX: Add a job for the stable Guix?
348 (list (->job 'binary-tarball
349 (run-with-store store
350 (mbegin %store-monad
351 (set-guile-for-build (default-guile))
352 (>>= (profile-derivation (packages->manifest (list guix)))
353 (lambda (profile)
354 (self-contained-tarball "guix-binary" profile
355 #:localstatedir? #t
356 #:compressor
357 (lookup-compressor "xz")))))
358 #:system system))))
359
360(define job-name
361 ;; Return the name of a package's job.
362 (compose string->symbol
363 (cut package-full-name <> "-")))
364
365(define package->job
366 (let ((base-packages
367 (delete-duplicates
368 (append-map (match-lambda
369 ((_ package _ ...)
370 (match (package-transitive-inputs package)
371 (((_ inputs _ ...) ...)
372 inputs))))
373 (%final-inputs)))))
374 (lambda (store package system)
375 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
376valid."
377 (cond ((member package base-packages)
378 (package-job store (symbol-append 'base. (job-name package))
379 package system))
380 ((supported-package? package system)
381 (let ((drv (package-derivation store package system
382 #:graft? #f)))
383 (and (substitutable-derivation? drv)
384 (package-job store (job-name package)
385 package system))))
386 (else
387 #f)))))
388
389(define (all-packages)
390 "Return the list of packages to build."
391 (define (adjust package result)
392 (cond ((package-replacement package)
f00ff8db
LC
393 ;; XXX: If PACKAGE and its replacement have the same name/version,
394 ;; then both Cuirass jobs will have the same name, which
395 ;; effectively means that the second one will be ignored. Thus,
396 ;; return the replacement first.
397 (cons* (package-replacement package) ;build both
398 package
59fb5c1c
LC
399 result))
400 ((package-superseded package)
401 result) ;don't build it
402 (else
403 (cons package result))))
404
405 (fold-packages adjust
406 (fold adjust '() ;include base packages
407 (match (%final-inputs)
408 (((labels packages _ ...) ...)
409 packages)))
410 #:select? (const #t))) ;include hidden packages
411
412(define (arguments->manifests arguments)
413 "Return the list of manifests extracted from ARGUMENTS."
414 (map (match-lambda
415 ((input-name . relative-path)
416 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
417 (base (assq-ref checkout 'file-name)))
418 (in-vicinity base relative-path))))
419 (assq-ref arguments 'manifests)))
420
421(define (manifests->packages store manifests)
422 "Return the list of packages found in MANIFESTS."
423 (define (load-manifest manifest)
424 (save-module-excursion
425 (lambda ()
426 (set-current-module (make-user-module '((guix profiles) (gnu))))
427 (primitive-load manifest))))
428
429 (delete-duplicates!
430 (map manifest-entry-item
431 (append-map (compose manifest-entries
432 load-manifest)
433 manifests))))
434
f71b0a00
CL
435(define (find-current-checkout arguments)
436 "Find the first checkout of ARGUMENTS that provided the current file.
437Return #f if no such checkout is found."
438 (let ((current-root
439 (canonicalize-path
440 (string-append (dirname (current-filename)) "/.."))))
441 (find (lambda (argument)
442 (and=> (assq-ref argument 'file-name)
443 (lambda (name)
444 (string=? name current-root)))) arguments)))
445
59fb5c1c
LC
446\f
447;;;
448;;; Hydra entry point.
449;;;
450
451(define (hydra-jobs store arguments)
452 "Return Hydra jobs."
453 (define subset
454 (match (assoc-ref arguments 'subset)
455 ("core" 'core) ; only build core packages
456 ("hello" 'hello) ; only build hello
457 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
458 ("manifests" 'manifests) ; only build packages in the list of manifests
459 (_ 'all))) ; build everything
460
461 (define systems
462 (match (assoc-ref arguments 'systems)
463 (#f %hydra-supported-systems)
464 ((lst ...) lst)
465 ((? string? str) (call-with-input-string str read))))
466
7e6d8d36 467 (define checkout
f71b0a00
CL
468 (or (find-current-checkout arguments)
469 (assq-ref arguments 'superior-guix-checkout)))
7e6d8d36
LC
470
471 (define commit
472 (assq-ref checkout 'revision))
473
474 (define source
475 (assq-ref checkout 'file-name))
476
59fb5c1c
LC
477 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
478 (parameterize ((%graft? #f))
479 ;; Return one job for each package, except bootstrap packages.
480 (append-map (lambda (system)
481 (format (current-error-port)
482 "evaluating for '~a' (heap size: ~a MiB)...~%"
483 system
484 (round
485 (/ (assoc-ref (gc-stats) 'heap-size)
486 (expt 2. 20))))
487 (invalidate-derivation-caches!)
488 (case subset
489 ((all)
490 ;; Build everything, including replacements.
491 (let ((all (all-packages))
492 (job (lambda (package)
493 (package->job store package
494 system))))
495 (append (filter-map job all)
b06ba9e0 496 (image-jobs store system)
7e6d8d36
LC
497 (system-test-jobs store system
498 #:source source
499 #:commit commit)
59fb5c1c 500 (tarball-jobs store system)
3046e73b 501 (cross-jobs store system))))
59fb5c1c
LC
502 ((core)
503 ;; Build core packages only.
504 (append (map (lambda (package)
505 (package-job store (job-name package)
506 package system))
507 %core-packages)
3046e73b 508 (cross-jobs store system)))
59fb5c1c
LC
509 ((hello)
510 ;; Build hello package only.
511 (if (string=? system (%current-system))
512 (let ((hello (specification->package "hello")))
513 (list (package-job store (job-name hello) hello system)))
514 '()))
515 ((list)
516 ;; Build selected list of packages only.
517 (if (string=? system (%current-system))
518 (let* ((names (assoc-ref arguments 'subset))
519 (packages (map specification->package names)))
520 (map (lambda (package)
521 (package-job store (job-name package)
522 package system))
523 packages))
524 '()))
525 ((manifests)
526 ;; Build packages in the list of manifests.
527 (let* ((manifests (arguments->manifests arguments))
528 (packages (manifests->packages store manifests)))
529 (map (lambda (package)
530 (package-job store (job-name package)
531 package system))
532 packages)))
533 (else
534 (error "unknown subset" subset))))
535 systems)))