1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
6 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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)
27 #:use-module (guix channels)
28 #:use-module (guix derivations)
29 #:use-module (guix build-system)
30 #:use-module (guix monads)
31 #:use-module (guix ui)
32 #:use-module ((guix licenses)
33 #:select (gpl3+ license? license-name))
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))
61 ;;; This file defines build jobs for the Hydra and Cuirass continuation
62 ;;; integration tools.
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
73 (description . ,(package-synopsis package))
74 (long-description . ,(package-description package))
76 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
78 (license . ,(let loop ((license (package-license package)))
81 (license-name license))
83 (map loop license)))))
85 (home-page . ,(package-home-page package))
86 (maintainers . ("bug-guix@gnu.org"))
87 (max-silent-time . ,(or (assoc-ref (package-properties package)
89 3600)) ;1 hour by default
90 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
91 72000))))) ;20 hours by default
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))))
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
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
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
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))
123 (define %packages-to-cross-build
126 (define %cross-targets
127 '("mips64el-linux-gnu"
128 "mips64el-linux-gnuabi64"
129 "arm-linux-gnueabihf"
132 "i586-pc-gnu" ;aka. GNU/Hurd
135 (define %guixsd-supported-systems
136 '("x86_64-linux" "i686-linux" "armhf-linux"))
138 (define %u-boot-systems
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
148 (license . ,(license-name gpl3+))
149 (max-silent-time . 600)
151 (home-page . ,%guix-home-page-url)
152 (maintainers . ("bug-guix@gnu.org"))))
154 (define (->job name drv)
155 (let ((name (symbol-append name (string->symbol ".")
156 (string->symbol system))))
157 `(,name . ,(lambda ()
158 (parameterize ((%graft? #f))
164 (if (member system %guixsd-supported-systems)
165 (if (member system %u-boot-systems)
166 (list (->job 'flash-image
167 (run-with-store store
169 (set-guile-for-build (default-guile))
171 (operating-system (inherit installation-os)
172 (bootloader (bootloader-configuration
173 (bootloader u-boot-bootloader)
177 (list (->job 'usb-image
178 (run-with-store store
180 (set-guile-for-build (default-guile))
181 (system-disk-image installation-os
184 (->job 'iso9660-image
185 (run-with-store store
187 (set-guile-for-build (default-guile))
188 (system-disk-image installation-os
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 system
198 (run-with-store store
199 (channel-instances->derivation (list instance))
201 (lower (lambda* (name #:key system instance #:allow-other-keys)
206 (arguments `(#:instance ,instance))))))
207 (build-system (name 'channel)
208 (description "Turn a channel instance into a package.")
211 (define (channel-instance->package instance)
212 "Return a package for the given channel INSTANCE."
215 (version (or (string-take (channel-instance-commit instance) 7)
216 (string-append (package-version guix) "+")))
217 (build-system channel-build-system)
218 (arguments `(#:instance ,instance))
221 (propagated-inputs '())))
223 (define* (system-test-jobs store system
225 "Return a list of jobs for the system tests."
227 (checkout->channel-instance source #:commit commit))
229 (define (test->thunk test)
232 (run-with-store store
234 (set-current-system system)
236 (set-guile-for-build (default-guile))
237 (system-test-value test))))
239 `((derivation . ,(derivation-file-name drv))
240 (description . ,(format #f "Guix '~a' system test"
241 (system-test-name test)))
242 (long-description . ,(system-test-description test))
243 (license . ,(license-name gpl3+))
244 (max-silent-time . 600)
246 (home-page . ,%guix-home-page-url)
247 (maintainers . ("bug-guix@gnu.org")))))
250 (let ((name (string->symbol
251 (string-append "test." (system-test-name test)
253 (cons name (test->thunk test))))
255 (if (and (member system %guixsd-supported-systems)
257 ;; XXX: Our build farm has too few ARMv7 machines and they are very
258 ;; slow, so skip system tests there.
259 (not (string=? system "armhf-linux")))
260 ;; Override the value of 'current-guix' used by system tests. Using a
261 ;; channel instance makes tests that rely on 'current-guix' less
262 ;; expensive. It also makes sure we get a valid Guix package when this
263 ;; code is not running from a checkout.
264 (parameterize ((current-guix-package
265 (channel-instance->package instance)))
266 (map ->job (all-system-tests)))
269 (define (tarball-jobs store system)
270 "Return Hydra jobs to build the self-contained Guix binary tarball."
271 (define (->alist drv)
272 `((derivation . ,(derivation-file-name drv))
273 (description . "Stand-alone binary Guix tarball")
274 (long-description . "This is a tarball containing binaries of Guix and
275 all its dependencies, and ready to be installed on \"foreign\" distributions.")
276 (license . ,(license-name gpl3+))
277 (home-page . ,%guix-home-page-url)
278 (maintainers . ("bug-guix@gnu.org"))))
280 (define (->job name drv)
281 (let ((name (symbol-append name (string->symbol ".")
282 (string->symbol system))))
283 `(,name . ,(lambda ()
284 (parameterize ((%graft? #f))
287 ;; XXX: Add a job for the stable Guix?
288 (list (->job 'binary-tarball
289 (run-with-store store
291 (set-guile-for-build (default-guile))
292 (>>= (profile-derivation (packages->manifest (list guix)))
294 (self-contained-tarball "guix-binary" profile
297 (lookup-compressor "xz")))))
301 ;; Return the name of a package's job.
302 (compose string->symbol
303 (cut package-full-name <> "-")))
308 (append-map (match-lambda
310 (match (package-transitive-inputs package)
311 (((_ inputs _ ...) ...)
314 (lambda (store package system)
315 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
317 (cond ((member package base-packages)
318 (package-job store (symbol-append 'base. (job-name package))
320 ((supported-package? package system)
321 (let ((drv (package-derivation store package system
323 (and (substitutable-derivation? drv)
324 (package-job store (job-name package)
329 (define (all-packages)
330 "Return the list of packages to build."
331 (define (adjust package result)
332 (cond ((package-replacement package)
333 (cons* package ;build both
334 (package-replacement package)
336 ((package-superseded package)
337 result) ;don't build it
339 (cons package result))))
341 (fold-packages adjust
342 (fold adjust '() ;include base packages
343 (match (%final-inputs)
344 (((labels packages _ ...) ...)
346 #:select? (const #t))) ;include hidden packages
348 (define (arguments->manifests arguments)
349 "Return the list of manifests extracted from ARGUMENTS."
351 ((input-name . relative-path)
352 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
353 (base (assq-ref checkout 'file-name)))
354 (in-vicinity base relative-path))))
355 (assq-ref arguments 'manifests)))
357 (define (manifests->packages store manifests)
358 "Return the list of packages found in MANIFESTS."
359 (define (load-manifest manifest)
360 (save-module-excursion
362 (set-current-module (make-user-module '((guix profiles) (gnu))))
363 (primitive-load manifest))))
366 (map manifest-entry-item
367 (append-map (compose manifest-entries
373 ;;; Hydra entry point.
376 (define (hydra-jobs store arguments)
379 (match (assoc-ref arguments 'subset)
380 ("core" 'core) ; only build core packages
381 ("hello" 'hello) ; only build hello
382 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
383 ("manifests" 'manifests) ; only build packages in the list of manifests
384 (_ 'all))) ; build everything
387 (match (assoc-ref arguments 'systems)
388 (#f %hydra-supported-systems)
390 ((? string? str) (call-with-input-string str read))))
393 ;; Extract metadata about the 'guix' checkout. Its key in ARGUMENTS may
394 ;; vary, so pick up the first one that's neither 'subset' nor 'systems'.
397 (and (not (memq key '(systems subset)))
402 (assq-ref checkout 'revision))
405 (assq-ref checkout 'file-name))
407 (define (cross-jobs system)
408 (define (from-32-to-64? target)
409 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
410 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
411 ;; mips64el-linux-gnuabi64.
412 (and (or (string-prefix? "i686-" system)
413 (string-prefix? "i586-" system)
414 (string-prefix? "armhf-" system))
415 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
417 (define (same? target)
418 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
419 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
421 (or (string-contains target system)
422 (and (string-prefix? "armhf" system) ;armhf-linux
423 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
425 (define (pointless? target)
426 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
428 ((or "x86_64-linux" "i686-linux")
429 (if (string-contains target "mingw")
430 (not (string=? "x86_64-linux" system))
433 ;; Don't try to cross-compile from non-Intel platforms: this isn't
434 ;; very useful and these are often brittle configurations.
437 (define (either proc1 proc2 proc3)
439 (or (proc1 x) (proc2 x) (proc3 x))))
441 (append-map (lambda (target)
442 (map (lambda (package)
443 (package-cross-job store (job-name package)
444 package target system))
445 %packages-to-cross-build))
446 (remove (either from-32-to-64? same? pointless?)
449 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
450 (parameterize ((%graft? #f))
451 ;; Return one job for each package, except bootstrap packages.
452 (append-map (lambda (system)
453 (format (current-error-port)
454 "evaluating for '~a' (heap size: ~a MiB)...~%"
457 (/ (assoc-ref (gc-stats) 'heap-size)
459 (invalidate-derivation-caches!)
462 ;; Build everything, including replacements.
463 (let ((all (all-packages))
464 (job (lambda (package)
465 (package->job store package
467 (append (filter-map job all)
468 (qemu-jobs store system)
469 (system-test-jobs store system
472 (tarball-jobs store system)
473 (cross-jobs system))))
475 ;; Build core packages only.
476 (append (map (lambda (package)
477 (package-job store (job-name package)
480 (cross-jobs system)))
482 ;; Build hello package only.
483 (if (string=? system (%current-system))
484 (let ((hello (specification->package "hello")))
485 (list (package-job store (job-name hello) hello system)))
488 ;; Build selected list of packages only.
489 (if (string=? system (%current-system))
490 (let* ((names (assoc-ref arguments 'subset))
491 (packages (map specification->package names)))
492 (map (lambda (package)
493 (package-job store (job-name package)
498 ;; Build packages in the list of manifests.
499 (let* ((manifests (arguments->manifests arguments))
500 (packages (manifests->packages store manifests)))
501 (map (lambda (package)
502 (package-job store (job-name package)
506 (error "unknown subset" subset))))