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
134 "x86_64-w64-mingw32"))
136 (define %guixsd-supported-systems
137 '("x86_64-linux" "i686-linux" "armhf-linux"))
139 (define %u-boot-systems
142 (define (qemu-jobs store system)
143 "Return a list of jobs that build QEMU images for SYSTEM."
144 (define (->alist drv)
145 `((derivation . ,(derivation-file-name drv))
146 (description . "Stand-alone QEMU image of the GNU system")
147 (long-description . "This is a demo stand-alone QEMU image of the GNU
149 (license . ,(license-name gpl3+))
150 (max-silent-time . 600)
152 (home-page . ,%guix-home-page-url)
153 (maintainers . ("bug-guix@gnu.org"))))
155 (define (->job name drv)
156 (let ((name (symbol-append name (string->symbol ".")
157 (string->symbol system))))
158 `(,name . ,(lambda ()
159 (parameterize ((%graft? #f))
165 (if (member system %guixsd-supported-systems)
166 (if (member system %u-boot-systems)
167 (list (->job 'flash-image
168 (run-with-store store
170 (set-guile-for-build (default-guile))
172 (operating-system (inherit installation-os)
173 (bootloader (bootloader-configuration
174 (bootloader u-boot-bootloader)
178 (list (->job 'usb-image
179 (run-with-store store
181 (set-guile-for-build (default-guile))
182 (system-disk-image installation-os
185 (->job 'iso9660-image
186 (run-with-store store
188 (set-guile-for-build (default-guile))
189 (system-disk-image installation-os
194 (define channel-build-system
195 ;; Build system used to "convert" a channel instance to a package.
196 (let* ((build (lambda* (store name inputs
197 #:key instance system
199 (run-with-store store
200 (channel-instances->derivation (list instance))
202 (lower (lambda* (name #:key system instance #:allow-other-keys)
207 (arguments `(#:instance ,instance))))))
208 (build-system (name 'channel)
209 (description "Turn a channel instance into a package.")
212 (define (channel-instance->package instance)
213 "Return a package for the given channel INSTANCE."
216 (version (or (string-take (channel-instance-commit instance) 7)
217 (string-append (package-version guix) "+")))
218 (build-system channel-build-system)
219 (arguments `(#:instance ,instance))
222 (propagated-inputs '())))
224 (define* (system-test-jobs store system
226 "Return a list of jobs for the system tests."
228 (checkout->channel-instance source #:commit commit))
230 (define (test->thunk test)
233 (run-with-store store
235 (set-current-system system)
237 (set-guile-for-build (default-guile))
238 (system-test-value test))))
240 `((derivation . ,(derivation-file-name drv))
241 (description . ,(format #f "Guix '~a' system test"
242 (system-test-name test)))
243 (long-description . ,(system-test-description test))
244 (license . ,(license-name gpl3+))
245 (max-silent-time . 600)
247 (home-page . ,%guix-home-page-url)
248 (maintainers . ("bug-guix@gnu.org")))))
251 (let ((name (string->symbol
252 (string-append "test." (system-test-name test)
254 (cons name (test->thunk test))))
256 (if (and (member system %guixsd-supported-systems)
258 ;; XXX: Our build farm has too few ARMv7 machines and they are very
259 ;; slow, so skip system tests there.
260 (not (string=? system "armhf-linux")))
261 ;; Override the value of 'current-guix' used by system tests. Using a
262 ;; channel instance makes tests that rely on 'current-guix' less
263 ;; expensive. It also makes sure we get a valid Guix package when this
264 ;; code is not running from a checkout.
265 (parameterize ((current-guix-package
266 (channel-instance->package instance)))
267 (map ->job (all-system-tests)))
270 (define (tarball-jobs store system)
271 "Return Hydra jobs to build the self-contained Guix binary tarball."
272 (define (->alist drv)
273 `((derivation . ,(derivation-file-name drv))
274 (description . "Stand-alone binary Guix tarball")
275 (long-description . "This is a tarball containing binaries of Guix and
276 all its dependencies, and ready to be installed on \"foreign\" distributions.")
277 (license . ,(license-name gpl3+))
278 (home-page . ,%guix-home-page-url)
279 (maintainers . ("bug-guix@gnu.org"))))
281 (define (->job name drv)
282 (let ((name (symbol-append name (string->symbol ".")
283 (string->symbol system))))
284 `(,name . ,(lambda ()
285 (parameterize ((%graft? #f))
288 ;; XXX: Add a job for the stable Guix?
289 (list (->job 'binary-tarball
290 (run-with-store store
292 (set-guile-for-build (default-guile))
293 (>>= (profile-derivation (packages->manifest (list guix)))
295 (self-contained-tarball "guix-binary" profile
298 (lookup-compressor "xz")))))
302 ;; Return the name of a package's job.
303 (compose string->symbol
304 (cut package-full-name <> "-")))
309 (append-map (match-lambda
311 (match (package-transitive-inputs package)
312 (((_ inputs _ ...) ...)
315 (lambda (store package system)
316 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
318 (cond ((member package base-packages)
319 (package-job store (symbol-append 'base. (job-name package))
321 ((supported-package? package system)
322 (let ((drv (package-derivation store package system
324 (and (substitutable-derivation? drv)
325 (package-job store (job-name package)
330 (define (all-packages)
331 "Return the list of packages to build."
332 (define (adjust package result)
333 (cond ((package-replacement package)
334 ;; XXX: If PACKAGE and its replacement have the same name/version,
335 ;; then both Cuirass jobs will have the same name, which
336 ;; effectively means that the second one will be ignored. Thus,
337 ;; return the replacement first.
338 (cons* (package-replacement package) ;build both
341 ((package-superseded package)
342 result) ;don't build it
344 (cons package result))))
346 (fold-packages adjust
347 (fold adjust '() ;include base packages
348 (match (%final-inputs)
349 (((labels packages _ ...) ...)
351 #:select? (const #t))) ;include hidden packages
353 (define (arguments->manifests arguments)
354 "Return the list of manifests extracted from ARGUMENTS."
356 ((input-name . relative-path)
357 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
358 (base (assq-ref checkout 'file-name)))
359 (in-vicinity base relative-path))))
360 (assq-ref arguments 'manifests)))
362 (define (manifests->packages store manifests)
363 "Return the list of packages found in MANIFESTS."
364 (define (load-manifest manifest)
365 (save-module-excursion
367 (set-current-module (make-user-module '((guix profiles) (gnu))))
368 (primitive-load manifest))))
371 (map manifest-entry-item
372 (append-map (compose manifest-entries
378 ;;; Hydra entry point.
381 (define (hydra-jobs store arguments)
384 (match (assoc-ref arguments 'subset)
385 ("core" 'core) ; only build core packages
386 ("hello" 'hello) ; only build hello
387 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
388 ("manifests" 'manifests) ; only build packages in the list of manifests
389 (_ 'all))) ; build everything
392 (match (assoc-ref arguments 'systems)
393 (#f %hydra-supported-systems)
395 ((? string? str) (call-with-input-string str read))))
398 ;; Extract metadata about the 'guix' checkout. Its key in ARGUMENTS may
399 ;; vary, so pick up the first one that's neither 'subset' nor 'systems'.
402 (and (not (memq key '(systems subset)))
407 (assq-ref checkout 'revision))
410 (assq-ref checkout 'file-name))
412 (define (cross-jobs system)
413 (define (from-32-to-64? target)
414 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
415 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
416 ;; mips64el-linux-gnuabi64.
417 (and (or (string-prefix? "i686-" system)
418 (string-prefix? "i586-" system)
419 (string-prefix? "armhf-" system))
420 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
422 (define (same? target)
423 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
424 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
426 (or (string-contains target system)
427 (and (string-prefix? "armhf" system) ;armhf-linux
428 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
430 (define (pointless? target)
431 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
433 ((or "x86_64-linux" "i686-linux")
434 (if (string-contains target "mingw")
435 (not (string=? "x86_64-linux" system))
438 ;; Don't try to cross-compile from non-Intel platforms: this isn't
439 ;; very useful and these are often brittle configurations.
442 (define (either proc1 proc2 proc3)
444 (or (proc1 x) (proc2 x) (proc3 x))))
446 (append-map (lambda (target)
447 (map (lambda (package)
448 (package-cross-job store (job-name package)
449 package target system))
450 %packages-to-cross-build))
451 (remove (either from-32-to-64? same? pointless?)
454 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
455 (parameterize ((%graft? #f))
456 ;; Return one job for each package, except bootstrap packages.
457 (append-map (lambda (system)
458 (format (current-error-port)
459 "evaluating for '~a' (heap size: ~a MiB)...~%"
462 (/ (assoc-ref (gc-stats) 'heap-size)
464 (invalidate-derivation-caches!)
467 ;; Build everything, including replacements.
468 (let ((all (all-packages))
469 (job (lambda (package)
470 (package->job store package
472 (append (filter-map job all)
473 (qemu-jobs store system)
474 (system-test-jobs store system
477 (tarball-jobs store system)
478 (cross-jobs system))))
480 ;; Build core packages only.
481 (append (map (lambda (package)
482 (package-job store (job-name package)
485 (cross-jobs system)))
487 ;; Build hello package only.
488 (if (string=? system (%current-system))
489 (let ((hello (specification->package "hello")))
490 (list (package-job store (job-name hello) hello system)))
493 ;; Build selected list of packages only.
494 (if (string=? system (%current-system))
495 (let* ((names (assoc-ref arguments 'subset))
496 (packages (map specification->package names)))
497 (map (lambda (package)
498 (package-job store (job-name package)
503 ;; Build packages in the list of manifests.
504 (let* ((manifests (arguments->manifests arguments))
505 (packages (manifests->packages store manifests)))
506 (map (lambda (package)
507 (package-job store (job-name package)
511 (error "unknown subset" subset))))