1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;; Copyright © 2018, 2019 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 gexp)
32 #:use-module (guix ui)
33 #:use-module ((guix licenses)
34 #:select (gpl3+ license? license-name))
35 #:use-module ((guix utils) #:select (%current-system))
36 #:use-module ((guix scripts system) #:select (read-operating-system))
37 #:use-module ((guix scripts pack)
38 #:select (lookup-compressor self-contained-tarball))
39 #:use-module (gnu bootloader)
40 #:use-module (gnu bootloader u-boot)
41 #:use-module (gnu image)
42 #:use-module (gnu packages)
43 #:use-module (gnu packages gcc)
44 #:use-module (gnu packages base)
45 #:use-module (gnu packages gawk)
46 #:use-module (gnu packages guile)
47 #:use-module (gnu packages gettext)
48 #:use-module (gnu packages compression)
49 #:use-module (gnu packages multiprecision)
50 #:use-module (gnu packages make-bootstrap)
51 #:use-module (gnu packages package-management)
52 #:use-module (gnu system)
53 #:use-module (gnu system image)
54 #:use-module (gnu system vm)
55 #:use-module (gnu system install)
56 #:use-module (gnu tests)
57 #:use-module (srfi srfi-1)
58 #:use-module (srfi srfi-26)
59 #:use-module (ice-9 match)
60 #:export (%cross-targets
61 channel-source->package
66 ;;; This file defines build jobs for the Hydra and Cuirass continuation
67 ;;; integration tools.
71 (define* (package->alist store package system
72 #:optional (package-derivation package-derivation))
73 "Convert PACKAGE to an alist suitable for Hydra."
74 (parameterize ((%graft? #f))
75 `((derivation . ,(derivation-file-name
76 (package-derivation store package system
78 (description . ,(package-synopsis package))
79 (long-description . ,(package-description package))
81 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
83 (license . ,(let loop ((license (package-license package)))
86 (license-name license))
88 (map loop license)))))
90 (home-page . ,(package-home-page package))
91 (maintainers . ("bug-guix@gnu.org"))
92 (max-silent-time . ,(or (assoc-ref (package-properties package)
94 3600)) ;1 hour by default
95 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
96 72000))))) ;20 hours by default
98 (define (package-job store job-name package system)
99 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
100 (let ((job-name (symbol-append job-name (string->symbol ".")
101 (string->symbol system))))
102 `(,job-name . ,(cut package->alist store package system))))
104 (define (package-cross-job store job-name package target system)
105 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
107 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
108 (string->symbol ".") (string->symbol system)) .
109 ,(cute package->alist store package system
110 (lambda* (store package system #:key graft?)
111 (package-cross-derivation store package target system
114 (define %core-packages
115 ;; Note: Don't put the '-final' package variants because (1) that's
116 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
118 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
119 gmp mpfr mpc coreutils findutils diffutils patch sed grep
120 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
121 %bootstrap-binaries-tarball
122 %binutils-bootstrap-tarball
123 (%glibc-bootstrap-tarball)
124 %gcc-bootstrap-tarball
125 %guile-bootstrap-tarball
126 %bootstrap-tarballs))
128 (define (packages-to-cross-build target)
129 "Return the list of packages to cross-build for TARGET."
130 ;; Don't cross-build the bootstrap tarballs for MinGW.
131 (if (string-contains target "mingw")
132 (drop-right %core-packages 6)
135 (define %cross-targets
136 '("mips64el-linux-gnu"
137 "arm-linux-gnueabihf"
141 "i586-pc-gnu" ;aka. GNU/Hurd
143 "x86_64-w64-mingw32"))
145 (define (cross-jobs store system)
146 "Return a list of cross-compilation jobs for SYSTEM."
147 (define (from-32-to-64? target)
148 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
149 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
150 ;; mips64el-linux-gnuabi64.
151 (and (or (string-prefix? "i686-" system)
152 (string-prefix? "i586-" system)
153 (string-prefix? "armhf-" system))
154 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
156 (define (same? target)
157 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
158 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
160 (or (string-contains target system)
161 (and (string-prefix? "armhf" system) ;armhf-linux
162 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
164 (define (pointless? target)
165 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
167 ((or "x86_64-linux" "i686-linux")
168 (if (string-contains target "mingw")
169 (not (string=? "x86_64-linux" system))
172 ;; Don't try to cross-compile from non-Intel platforms: this isn't
173 ;; very useful and these are often brittle configurations.
176 (define (either proc1 proc2 proc3)
178 (or (proc1 x) (proc2 x) (proc3 x))))
180 (append-map (lambda (target)
181 (map (lambda (package)
182 (package-cross-job store (job-name package)
183 package target system))
184 (packages-to-cross-build target)))
185 (remove (either from-32-to-64? same? pointless?)
188 (define %guixsd-supported-systems
189 '("x86_64-linux" "i686-linux" "armhf-linux"))
191 (define %u-boot-systems
194 (define (qemu-jobs store system)
195 "Return a list of jobs that build QEMU images for SYSTEM."
196 (define (->alist drv)
197 `((derivation . ,(derivation-file-name drv))
198 (description . "Stand-alone QEMU image of the GNU system")
199 (long-description . "This is a demo stand-alone QEMU image of the GNU
201 (license . ,(license-name gpl3+))
202 (max-silent-time . 600)
204 (home-page . ,%guix-home-page-url)
205 (maintainers . ("bug-guix@gnu.org"))))
207 (define (->job name drv)
208 (let ((name (symbol-append name (string->symbol ".")
209 (string->symbol system))))
210 `(,name . ,(lambda ()
211 (parameterize ((%graft? #f))
217 (if (member system %guixsd-supported-systems)
218 (list (->job 'usb-image
219 (run-with-store store
221 (set-guile-for-build (default-guile))
225 (inherit efi-disk-image)
227 (operating-system installation-os)))))))
228 (->job 'iso9660-image
229 (run-with-store store
231 (set-guile-for-build (default-guile))
235 (inherit iso9660-image)
236 (operating-system installation-os))))))))
239 (define channel-build-system
240 ;; Build system used to "convert" a channel instance to a package.
241 (let* ((build (lambda* (store name inputs
242 #:key source commit system
244 (run-with-store store
245 ;; SOURCE can be a lowerable object such as <local-file>
246 ;; or a file name. Adjust accordingly.
247 (mlet* %store-monad ((source (if (string? source)
249 (lower-object source)))
251 -> (checkout->channel-instance
252 source #:commit commit)))
253 (channel-instances->derivation (list instance)))
255 (lower (lambda* (name #:key system source commit
261 (arguments `(#:source ,source
262 #:commit ,commit))))))
263 (build-system (name 'channel)
264 (description "Turn a channel instance into a package.")
267 (define* (channel-source->package source #:key commit)
268 "Return a package for the given channel SOURCE, a lowerable object."
271 (version (string-append (package-version guix) "+"))
272 (build-system channel-build-system)
273 (arguments `(#:source ,source
277 (propagated-inputs '())))
279 (define* (system-test-jobs store system
281 "Return a list of jobs for the system tests."
282 (define (test->thunk test)
285 (run-with-store store
287 (set-current-system system)
289 (set-guile-for-build (default-guile))
290 (system-test-value test))))
292 `((derivation . ,(derivation-file-name drv))
293 (description . ,(format #f "Guix '~a' system test"
294 (system-test-name test)))
295 (long-description . ,(system-test-description test))
296 (license . ,(license-name gpl3+))
297 (max-silent-time . 600)
299 (home-page . ,%guix-home-page-url)
300 (maintainers . ("bug-guix@gnu.org")))))
303 (let ((name (string->symbol
304 (string-append "test." (system-test-name test)
306 (cons name (test->thunk test))))
308 (if (and (member system %guixsd-supported-systems)
310 ;; XXX: Our build farm has too few ARMv7 machines and they are very
311 ;; slow, so skip system tests there.
312 (not (string=? system "armhf-linux")))
313 ;; Override the value of 'current-guix' used by system tests. Using a
314 ;; channel instance makes tests that rely on 'current-guix' less
315 ;; expensive. It also makes sure we get a valid Guix package when this
316 ;; code is not running from a checkout.
317 (parameterize ((current-guix-package
318 (channel-source->package source #:commit commit)))
319 (map ->job (all-system-tests)))
322 (define (tarball-jobs store system)
323 "Return Hydra jobs to build the self-contained Guix binary tarball."
324 (define (->alist drv)
325 `((derivation . ,(derivation-file-name drv))
326 (description . "Stand-alone binary Guix tarball")
327 (long-description . "This is a tarball containing binaries of Guix and
328 all its dependencies, and ready to be installed on \"foreign\" distributions.")
329 (license . ,(license-name gpl3+))
330 (home-page . ,%guix-home-page-url)
331 (maintainers . ("bug-guix@gnu.org"))))
333 (define (->job name drv)
334 (let ((name (symbol-append name (string->symbol ".")
335 (string->symbol system))))
336 `(,name . ,(lambda ()
337 (parameterize ((%graft? #f))
340 ;; XXX: Add a job for the stable Guix?
341 (list (->job 'binary-tarball
342 (run-with-store store
344 (set-guile-for-build (default-guile))
345 (>>= (profile-derivation (packages->manifest (list guix)))
347 (self-contained-tarball "guix-binary" profile
350 (lookup-compressor "xz")))))
354 ;; Return the name of a package's job.
355 (compose string->symbol
356 (cut package-full-name <> "-")))
361 (append-map (match-lambda
363 (match (package-transitive-inputs package)
364 (((_ inputs _ ...) ...)
367 (lambda (store package system)
368 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
370 (cond ((member package base-packages)
371 (package-job store (symbol-append 'base. (job-name package))
373 ((supported-package? package system)
374 (let ((drv (package-derivation store package system
376 (and (substitutable-derivation? drv)
377 (package-job store (job-name package)
382 (define (all-packages)
383 "Return the list of packages to build."
384 (define (adjust package result)
385 (cond ((package-replacement package)
386 ;; XXX: If PACKAGE and its replacement have the same name/version,
387 ;; then both Cuirass jobs will have the same name, which
388 ;; effectively means that the second one will be ignored. Thus,
389 ;; return the replacement first.
390 (cons* (package-replacement package) ;build both
393 ((package-superseded package)
394 result) ;don't build it
396 (cons package result))))
398 (fold-packages adjust
399 (fold adjust '() ;include base packages
400 (match (%final-inputs)
401 (((labels packages _ ...) ...)
403 #:select? (const #t))) ;include hidden packages
405 (define (arguments->manifests arguments)
406 "Return the list of manifests extracted from ARGUMENTS."
408 ((input-name . relative-path)
409 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
410 (base (assq-ref checkout 'file-name)))
411 (in-vicinity base relative-path))))
412 (assq-ref arguments 'manifests)))
414 (define (manifests->packages store manifests)
415 "Return the list of packages found in MANIFESTS."
416 (define (load-manifest manifest)
417 (save-module-excursion
419 (set-current-module (make-user-module '((guix profiles) (gnu))))
420 (primitive-load manifest))))
423 (map manifest-entry-item
424 (append-map (compose manifest-entries
428 (define (find-current-checkout arguments)
429 "Find the first checkout of ARGUMENTS that provided the current file.
430 Return #f if no such checkout is found."
433 (string-append (dirname (current-filename)) "/.."))))
434 (find (lambda (argument)
435 (and=> (assq-ref argument 'file-name)
437 (string=? name current-root)))) arguments)))
441 ;;; Hydra entry point.
444 (define (hydra-jobs store arguments)
447 (match (assoc-ref arguments 'subset)
448 ("core" 'core) ; only build core packages
449 ("hello" 'hello) ; only build hello
450 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
451 ("manifests" 'manifests) ; only build packages in the list of manifests
452 (_ 'all))) ; build everything
455 (match (assoc-ref arguments 'systems)
456 (#f %hydra-supported-systems)
458 ((? string? str) (call-with-input-string str read))))
461 (or (find-current-checkout arguments)
462 (assq-ref arguments 'superior-guix-checkout)))
465 (assq-ref checkout 'revision))
468 (assq-ref checkout 'file-name))
470 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
471 (parameterize ((%graft? #f))
472 ;; Return one job for each package, except bootstrap packages.
473 (append-map (lambda (system)
474 (format (current-error-port)
475 "evaluating for '~a' (heap size: ~a MiB)...~%"
478 (/ (assoc-ref (gc-stats) 'heap-size)
480 (invalidate-derivation-caches!)
483 ;; Build everything, including replacements.
484 (let ((all (all-packages))
485 (job (lambda (package)
486 (package->job store package
488 (append (filter-map job all)
489 (qemu-jobs store system)
490 (system-test-jobs store system
493 (tarball-jobs store system)
494 (cross-jobs store system))))
496 ;; Build core packages only.
497 (append (map (lambda (package)
498 (package-job store (job-name package)
501 (cross-jobs store system)))
503 ;; Build hello package only.
504 (if (string=? system (%current-system))
505 (let ((hello (specification->package "hello")))
506 (list (package-job store (job-name hello) hello system)))
509 ;; Build selected list of packages only.
510 (if (string=? system (%current-system))
511 (let* ((names (assoc-ref arguments 'subset))
512 (packages (map specification->package names)))
513 (map (lambda (package)
514 (package-job store (job-name package)
519 ;; Build packages in the list of manifests.
520 (let* ((manifests (arguments->manifests arguments))
521 (packages (manifests->packages store manifests)))
522 (map (lambda (package)
523 (package-job store (job-name package)
527 (error "unknown subset" subset))))