1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 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 derivations)
28 #:use-module (guix monads)
29 #:use-module (guix ui)
30 #:use-module ((guix licenses)
31 #:select (gpl3+ license? license-name))
32 #:use-module ((guix utils) #:select (%current-system))
33 #:use-module ((guix scripts system) #:select (read-operating-system))
34 #:use-module ((guix scripts pack)
35 #:select (lookup-compressor self-contained-tarball))
36 #:use-module (gnu bootloader)
37 #:use-module (gnu bootloader u-boot)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages gcc)
40 #:use-module (gnu packages base)
41 #:use-module (gnu packages gawk)
42 #:use-module (gnu packages guile)
43 #:use-module (gnu packages gettext)
44 #:use-module (gnu packages compression)
45 #:use-module (gnu packages multiprecision)
46 #:use-module (gnu packages make-bootstrap)
47 #:use-module (gnu packages package-management)
48 #:use-module (gnu system)
49 #:use-module (gnu system vm)
50 #:use-module (gnu system install)
51 #:use-module (gnu tests)
52 #:use-module (srfi srfi-1)
53 #:use-module (srfi srfi-26)
54 #:use-module (ice-9 match)
55 #:export (hydra-jobs))
59 ;;; This file defines build jobs for the Hydra and Cuirass continuation
60 ;;; integration tools.
64 (define* (package->alist store package system
65 #:optional (package-derivation package-derivation))
66 "Convert PACKAGE to an alist suitable for Hydra."
67 (parameterize ((%graft? #f))
68 `((derivation . ,(derivation-file-name
69 (package-derivation store package system
71 (description . ,(package-synopsis package))
72 (long-description . ,(package-description package))
74 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
76 (license . ,(let loop ((license (package-license package)))
79 (license-name license))
81 (map loop license)))))
83 (home-page . ,(package-home-page package))
84 (maintainers . ("bug-guix@gnu.org"))
85 (max-silent-time . ,(or (assoc-ref (package-properties package)
87 3600)) ;1 hour by default
88 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
89 72000))))) ;20 hours by default
91 (define (package-job store job-name package system)
92 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
93 (let ((job-name (symbol-append job-name (string->symbol ".")
94 (string->symbol system))))
95 `(,job-name . ,(cut package->alist store package system))))
97 (define (package-cross-job store job-name package target system)
98 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
100 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
101 (string->symbol ".") (string->symbol system)) .
102 ,(cute package->alist store package system
103 (lambda* (store package system #:key graft?)
104 (package-cross-derivation store package target system
107 (define %core-packages
108 ;; Note: Don't put the '-final' package variants because (1) that's
109 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
111 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
112 gmp mpfr mpc coreutils findutils diffutils patch sed grep
113 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
114 %bootstrap-binaries-tarball
115 %binutils-bootstrap-tarball
116 (%glibc-bootstrap-tarball)
117 %gcc-bootstrap-tarball
118 %guile-bootstrap-tarball
119 %bootstrap-tarballs))
121 (define %packages-to-cross-build
124 (define %cross-targets
125 '("mips64el-linux-gnu"
126 "mips64el-linux-gnuabi64"
127 "arm-linux-gnueabihf"
130 "i586-pc-gnu" ;aka. GNU/Hurd
133 (define %guixsd-supported-systems
134 '("x86_64-linux" "i686-linux" "armhf-linux"))
136 (define %u-boot-systems
139 (define (qemu-jobs store system)
140 "Return a list of jobs that build QEMU images for SYSTEM."
141 (define (->alist drv)
142 `((derivation . ,(derivation-file-name drv))
143 (description . "Stand-alone QEMU image of the GNU system")
144 (long-description . "This is a demo stand-alone QEMU image of the GNU
146 (license . ,(license-name gpl3+))
147 (max-silent-time . 600)
149 (home-page . ,%guix-home-page-url)
150 (maintainers . ("bug-guix@gnu.org"))))
152 (define (->job name drv)
153 (let ((name (symbol-append name (string->symbol ".")
154 (string->symbol system))))
155 `(,name . ,(lambda ()
156 (parameterize ((%graft? #f))
162 (if (member system %guixsd-supported-systems)
163 (if (member system %u-boot-systems)
164 (list (->job 'flash-image
165 (run-with-store store
167 (set-guile-for-build (default-guile))
169 (operating-system (inherit installation-os)
170 (bootloader (bootloader-configuration
171 (bootloader u-boot-bootloader)
175 (list (->job 'usb-image
176 (run-with-store store
178 (set-guile-for-build (default-guile))
179 (system-disk-image installation-os
182 (->job 'iso9660-image
183 (run-with-store store
185 (set-guile-for-build (default-guile))
186 (system-disk-image installation-os
191 (define (system-test-jobs store system)
192 "Return a list of jobs for the system tests."
193 (define (test->thunk test)
196 (run-with-store store
198 (set-current-system system)
200 (set-guile-for-build (default-guile))
201 (system-test-value test))))
203 `((derivation . ,(derivation-file-name drv))
204 (description . ,(format #f "GuixSD '~a' system test"
205 (system-test-name test)))
206 (long-description . ,(system-test-description test))
207 (license . ,(license-name gpl3+))
208 (max-silent-time . 600)
210 (home-page . ,%guix-home-page-url)
211 (maintainers . ("bug-guix@gnu.org")))))
214 (let ((name (string->symbol
215 (string-append "test." (system-test-name test)
217 (cons name (test->thunk test))))
219 (if (member system %guixsd-supported-systems)
220 (map ->job (all-system-tests))
223 (define (tarball-jobs store system)
224 "Return Hydra jobs to build the self-contained Guix binary tarball."
225 (define (->alist drv)
226 `((derivation . ,(derivation-file-name drv))
227 (description . "Stand-alone binary Guix tarball")
228 (long-description . "This is a tarball containing binaries of Guix and
229 all its dependencies, and ready to be installed on non-GuixSD distributions.")
230 (license . ,(license-name gpl3+))
231 (home-page . ,%guix-home-page-url)
232 (maintainers . ("bug-guix@gnu.org"))))
234 (define (->job name drv)
235 (let ((name (symbol-append name (string->symbol ".")
236 (string->symbol system))))
237 `(,name . ,(lambda ()
238 (parameterize ((%graft? #f))
241 ;; XXX: Add a job for the stable Guix?
242 (list (->job 'binary-tarball
243 (run-with-store store
245 (set-guile-for-build (default-guile))
246 (>>= (profile-derivation (packages->manifest (list guix)))
248 (self-contained-tarball "guix-binary" profile
251 (lookup-compressor "xz")))))
255 ;; Return the name of a package's job.
256 (compose string->symbol
257 (cut package-full-name <> "-")))
262 (append-map (match-lambda
264 (match (package-transitive-inputs package)
265 (((_ inputs _ ...) ...)
268 (lambda (store package system)
269 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
271 (cond ((member package base-packages)
272 (package-job store (symbol-append 'base. (job-name package))
274 ((supported-package? package system)
275 (let ((drv (package-derivation store package system
277 (and (substitutable-derivation? drv)
278 (package-job store (job-name package)
283 (define (all-packages)
284 "Return the list of packages to build."
285 (define (adjust package result)
286 (cond ((package-replacement package)
287 (cons* package ;build both
288 (package-replacement package)
290 ((package-superseded package)
291 result) ;don't build it
293 (cons package result))))
295 (fold-packages adjust
296 (fold adjust '() ;include base packages
297 (match (%final-inputs)
298 (((labels packages _ ...) ...)
300 #:select? (const #t))) ;include hidden packages
302 (define (arguments->manifests arguments)
303 "Return the list of manifests extracted from ARGUMENTS."
305 ((input-name . relative-path)
306 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
307 (base (assq-ref checkout 'file-name)))
308 (in-vicinity base relative-path))))
309 (assq-ref arguments 'manifests)))
311 (define (manifests->packages store manifests)
312 "Return the list of packages found in MANIFESTS."
313 (define (load-manifest manifest)
314 (save-module-excursion
316 (set-current-module (make-user-module '((guix profiles) (gnu))))
317 (primitive-load manifest))))
320 (map manifest-entry-item
321 (append-map (compose manifest-entries
327 ;;; Hydra entry point.
330 (define (hydra-jobs store arguments)
333 (match (assoc-ref arguments 'subset)
334 ("core" 'core) ; only build core packages
335 ("hello" 'hello) ; only build hello
336 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
337 ("manifests" 'manifests) ; only build packages in the list of manifests
338 (_ 'all))) ; build everything
341 (match (assoc-ref arguments 'systems)
342 (#f %hydra-supported-systems)
344 ((? string? str) (call-with-input-string str read))))
346 (define (cross-jobs system)
347 (define (from-32-to-64? target)
348 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
349 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
350 ;; mips64el-linux-gnuabi64.
351 (and (or (string-prefix? "i686-" system)
352 (string-prefix? "i586-" system)
353 (string-prefix? "armhf-" system))
354 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
356 (define (same? target)
357 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
358 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
360 (or (string-contains target system)
361 (and (string-prefix? "armhf" system) ;armhf-linux
362 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
364 (define (pointless? target)
365 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
367 ((or "x86_64-linux" "i686-linux")
368 (if (string-contains target "mingw")
369 (not (string=? "x86_64-linux" system))
372 ;; Don't try to cross-compile from non-Intel platforms: this isn't
373 ;; very useful and these are often brittle configurations.
376 (define (either proc1 proc2 proc3)
378 (or (proc1 x) (proc2 x) (proc3 x))))
380 (append-map (lambda (target)
381 (map (lambda (package)
382 (package-cross-job store (job-name package)
383 package target system))
384 %packages-to-cross-build))
385 (remove (either from-32-to-64? same? pointless?)
388 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
389 (parameterize ((%graft? #f))
390 ;; Return one job for each package, except bootstrap packages.
391 (append-map (lambda (system)
392 (format (current-error-port)
393 "evaluating for '~a' (heap size: ~a MiB)...~%"
396 (/ (assoc-ref (gc-stats) 'heap-size)
398 (invalidate-derivation-caches!)
401 ;; Build everything, including replacements.
402 (let ((all (all-packages))
403 (job (lambda (package)
404 (package->job store package
406 (append (filter-map job all)
407 (qemu-jobs store system)
408 (system-test-jobs store system)
409 (tarball-jobs store system)
410 (cross-jobs system))))
412 ;; Build core packages only.
413 (append (map (lambda (package)
414 (package-job store (job-name package)
417 (cross-jobs system)))
419 ;; Build hello package only.
420 (if (string=? system (%current-system))
421 (let ((hello (specification->package "hello")))
422 (list (package-job store (job-name hello) hello system)))
425 ;; Build selected list of packages only.
426 (if (string=? system (%current-system))
427 (let* ((names (assoc-ref arguments 'subset))
428 (packages (map specification->package names)))
429 (map (lambda (package)
430 (package-job store (job-name package)
435 ;; Build packages in the list of manifests.
436 (let* ((manifests (arguments->manifests arguments))
437 (packages (manifests->packages store manifests)))
438 (map (lambda (package)
439 (package-job store (job-name package)
443 (error "unknown subset" subset))))