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 packages)
42 #:use-module (gnu packages gcc)
43 #:use-module (gnu packages base)
44 #:use-module (gnu packages gawk)
45 #:use-module (gnu packages guile)
46 #:use-module (gnu packages gettext)
47 #:use-module (gnu packages compression)
48 #:use-module (gnu packages multiprecision)
49 #:use-module (gnu packages make-bootstrap)
50 #:use-module (gnu packages package-management)
51 #:use-module (gnu system)
52 #:use-module (gnu system vm)
53 #:use-module (gnu system install)
54 #:use-module (gnu tests)
55 #:use-module (srfi srfi-1)
56 #:use-module (srfi srfi-26)
57 #:use-module (ice-9 match)
58 #:export (%cross-targets
59 channel-source->package
64 ;;; This file defines build jobs for the Hydra and Cuirass continuation
65 ;;; integration tools.
69 (define* (package->alist store package system
70 #:optional (package-derivation package-derivation))
71 "Convert PACKAGE to an alist suitable for Hydra."
72 (parameterize ((%graft? #f))
73 `((derivation . ,(derivation-file-name
74 (package-derivation store package system
76 (description . ,(package-synopsis package))
77 (long-description . ,(package-description package))
79 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
81 (license . ,(let loop ((license (package-license package)))
84 (license-name license))
86 (map loop license)))))
88 (home-page . ,(package-home-page package))
89 (maintainers . ("bug-guix@gnu.org"))
90 (max-silent-time . ,(or (assoc-ref (package-properties package)
92 3600)) ;1 hour by default
93 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
94 72000))))) ;20 hours by default
96 (define (package-job store job-name package system)
97 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
98 (let ((job-name (symbol-append job-name (string->symbol ".")
99 (string->symbol system))))
100 `(,job-name . ,(cut package->alist store package system))))
102 (define (package-cross-job store job-name package target system)
103 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
105 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
106 (string->symbol ".") (string->symbol system)) .
107 ,(cute package->alist store package system
108 (lambda* (store package system #:key graft?)
109 (package-cross-derivation store package target system
112 (define %core-packages
113 ;; Note: Don't put the '-final' package variants because (1) that's
114 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
116 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
117 gmp mpfr mpc coreutils findutils diffutils patch sed grep
118 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
119 %bootstrap-binaries-tarball
120 %binutils-bootstrap-tarball
121 (%glibc-bootstrap-tarball)
122 %gcc-bootstrap-tarball
123 %guile-bootstrap-tarball
124 %bootstrap-tarballs))
126 (define (packages-to-cross-build target)
127 "Return the list of packages to cross-build for TARGET."
128 ;; Don't cross-build the bootstrap tarballs for MinGW.
129 (if (string-contains target "mingw")
130 (drop-right %core-packages 6)
133 (define %cross-targets
134 '("mips64el-linux-gnu"
135 "mips64el-linux-gnuabi64"
136 "arm-linux-gnueabihf"
140 "i586-pc-gnu" ;aka. GNU/Hurd
142 "x86_64-w64-mingw32"))
144 (define (cross-jobs store system)
145 "Return a list of cross-compilation jobs for SYSTEM."
146 (define (from-32-to-64? target)
147 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
148 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
149 ;; mips64el-linux-gnuabi64.
150 (and (or (string-prefix? "i686-" system)
151 (string-prefix? "i586-" system)
152 (string-prefix? "armhf-" system))
153 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
155 (define (same? target)
156 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
157 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
159 (or (string-contains target system)
160 (and (string-prefix? "armhf" system) ;armhf-linux
161 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
163 (define (pointless? target)
164 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
166 ((or "x86_64-linux" "i686-linux")
167 (if (string-contains target "mingw")
168 (not (string=? "x86_64-linux" system))
171 ;; Don't try to cross-compile from non-Intel platforms: this isn't
172 ;; very useful and these are often brittle configurations.
175 (define (either proc1 proc2 proc3)
177 (or (proc1 x) (proc2 x) (proc3 x))))
179 (append-map (lambda (target)
180 (map (lambda (package)
181 (package-cross-job store (job-name package)
182 package target system))
183 (packages-to-cross-build target)))
184 (remove (either from-32-to-64? same? pointless?)
187 (define %guixsd-supported-systems
188 '("x86_64-linux" "i686-linux" "armhf-linux"))
190 (define %u-boot-systems
193 (define (qemu-jobs store system)
194 "Return a list of jobs that build QEMU images for SYSTEM."
195 (define (->alist drv)
196 `((derivation . ,(derivation-file-name drv))
197 (description . "Stand-alone QEMU image of the GNU system")
198 (long-description . "This is a demo stand-alone QEMU image of the GNU
200 (license . ,(license-name gpl3+))
201 (max-silent-time . 600)
203 (home-page . ,%guix-home-page-url)
204 (maintainers . ("bug-guix@gnu.org"))))
206 (define (->job name drv)
207 (let ((name (symbol-append name (string->symbol ".")
208 (string->symbol system))))
209 `(,name . ,(lambda ()
210 (parameterize ((%graft? #f))
216 (if (member system %guixsd-supported-systems)
217 (if (member system %u-boot-systems)
218 (list (->job 'flash-image
219 (run-with-store store
221 (set-guile-for-build (default-guile))
223 (operating-system (inherit installation-os)
224 (bootloader (bootloader-configuration
225 (bootloader u-boot-bootloader)
229 (list (->job 'usb-image
230 (run-with-store store
232 (set-guile-for-build (default-guile))
233 (system-disk-image installation-os
236 (->job 'iso9660-image
237 (run-with-store store
239 (set-guile-for-build (default-guile))
240 (system-disk-image installation-os
245 (define channel-build-system
246 ;; Build system used to "convert" a channel instance to a package.
247 (let* ((build (lambda* (store name inputs
248 #:key source commit system
250 (run-with-store store
251 ;; SOURCE can be a lowerable object such as <local-file>
252 ;; or a file name. Adjust accordingly.
253 (mlet* %store-monad ((source (if (string? source)
255 (lower-object source)))
257 -> (checkout->channel-instance
258 source #:commit commit)))
259 (channel-instances->derivation (list instance)))
261 (lower (lambda* (name #:key system source commit
267 (arguments `(#:source ,source
268 #:commit ,commit))))))
269 (build-system (name 'channel)
270 (description "Turn a channel instance into a package.")
273 (define* (channel-source->package source #:key commit)
274 "Return a package for the given channel SOURCE, a lowerable object."
277 (version (string-append (package-version guix) "+"))
278 (build-system channel-build-system)
279 (arguments `(#:source ,source
283 (propagated-inputs '())))
285 (define* (system-test-jobs store system
287 "Return a list of jobs for the system tests."
288 (define (test->thunk test)
291 (run-with-store store
293 (set-current-system system)
295 (set-guile-for-build (default-guile))
296 (system-test-value test))))
298 `((derivation . ,(derivation-file-name drv))
299 (description . ,(format #f "Guix '~a' system test"
300 (system-test-name test)))
301 (long-description . ,(system-test-description test))
302 (license . ,(license-name gpl3+))
303 (max-silent-time . 600)
305 (home-page . ,%guix-home-page-url)
306 (maintainers . ("bug-guix@gnu.org")))))
309 (let ((name (string->symbol
310 (string-append "test." (system-test-name test)
312 (cons name (test->thunk test))))
314 (if (and (member system %guixsd-supported-systems)
316 ;; XXX: Our build farm has too few ARMv7 machines and they are very
317 ;; slow, so skip system tests there.
318 (not (string=? system "armhf-linux")))
319 ;; Override the value of 'current-guix' used by system tests. Using a
320 ;; channel instance makes tests that rely on 'current-guix' less
321 ;; expensive. It also makes sure we get a valid Guix package when this
322 ;; code is not running from a checkout.
323 (parameterize ((current-guix-package
324 (channel-source->package source #:commit commit)))
325 (map ->job (all-system-tests)))
328 (define (tarball-jobs store system)
329 "Return Hydra jobs to build the self-contained Guix binary tarball."
330 (define (->alist drv)
331 `((derivation . ,(derivation-file-name drv))
332 (description . "Stand-alone binary Guix tarball")
333 (long-description . "This is a tarball containing binaries of Guix and
334 all its dependencies, and ready to be installed on \"foreign\" distributions.")
335 (license . ,(license-name gpl3+))
336 (home-page . ,%guix-home-page-url)
337 (maintainers . ("bug-guix@gnu.org"))))
339 (define (->job name drv)
340 (let ((name (symbol-append name (string->symbol ".")
341 (string->symbol system))))
342 `(,name . ,(lambda ()
343 (parameterize ((%graft? #f))
346 ;; XXX: Add a job for the stable Guix?
347 (list (->job 'binary-tarball
348 (run-with-store store
350 (set-guile-for-build (default-guile))
351 (>>= (profile-derivation (packages->manifest (list guix)))
353 (self-contained-tarball "guix-binary" profile
356 (lookup-compressor "xz")))))
360 ;; Return the name of a package's job.
361 (compose string->symbol
362 (cut package-full-name <> "-")))
367 (append-map (match-lambda
369 (match (package-transitive-inputs package)
370 (((_ inputs _ ...) ...)
373 (lambda (store package system)
374 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
376 (cond ((member package base-packages)
377 (package-job store (symbol-append 'base. (job-name package))
379 ((supported-package? package system)
380 (let ((drv (package-derivation store package system
382 (and (substitutable-derivation? drv)
383 (package-job store (job-name package)
388 (define (all-packages)
389 "Return the list of packages to build."
390 (define (adjust package result)
391 (cond ((package-replacement package)
392 ;; XXX: If PACKAGE and its replacement have the same name/version,
393 ;; then both Cuirass jobs will have the same name, which
394 ;; effectively means that the second one will be ignored. Thus,
395 ;; return the replacement first.
396 (cons* (package-replacement package) ;build both
399 ((package-superseded package)
400 result) ;don't build it
402 (cons package result))))
404 (fold-packages adjust
405 (fold adjust '() ;include base packages
406 (match (%final-inputs)
407 (((labels packages _ ...) ...)
409 #:select? (const #t))) ;include hidden packages
411 (define (arguments->manifests arguments)
412 "Return the list of manifests extracted from ARGUMENTS."
414 ((input-name . relative-path)
415 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
416 (base (assq-ref checkout 'file-name)))
417 (in-vicinity base relative-path))))
418 (assq-ref arguments 'manifests)))
420 (define (manifests->packages store manifests)
421 "Return the list of packages found in MANIFESTS."
422 (define (load-manifest manifest)
423 (save-module-excursion
425 (set-current-module (make-user-module '((guix profiles) (gnu))))
426 (primitive-load manifest))))
429 (map manifest-entry-item
430 (append-map (compose manifest-entries
434 (define (find-current-checkout arguments)
435 "Find the first checkout of ARGUMENTS that provided the current file.
436 Return #f if no such checkout is found."
439 (string-append (dirname (current-filename)) "/.."))))
440 (find (lambda (argument)
441 (and=> (assq-ref argument 'file-name)
443 (string=? name current-root)))) arguments)))
447 ;;; Hydra entry point.
450 (define (hydra-jobs store arguments)
453 (match (assoc-ref arguments 'subset)
454 ("core" 'core) ; only build core packages
455 ("hello" 'hello) ; only build hello
456 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
457 ("manifests" 'manifests) ; only build packages in the list of manifests
458 (_ 'all))) ; build everything
461 (match (assoc-ref arguments 'systems)
462 (#f %hydra-supported-systems)
464 ((? string? str) (call-with-input-string str read))))
467 (or (find-current-checkout arguments)
468 (assq-ref arguments 'superior-guix-checkout)))
471 (assq-ref checkout 'revision))
474 (assq-ref checkout 'file-name))
476 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
477 (parameterize ((%graft? #f))
478 ;; Return one job for each package, except bootstrap packages.
479 (append-map (lambda (system)
480 (format (current-error-port)
481 "evaluating for '~a' (heap size: ~a MiB)...~%"
484 (/ (assoc-ref (gc-stats) 'heap-size)
486 (invalidate-derivation-caches!)
489 ;; Build everything, including replacements.
490 (let ((all (all-packages))
491 (job (lambda (package)
492 (package->job store package
494 (append (filter-map job all)
495 (qemu-jobs store system)
496 (system-test-jobs store system
499 (tarball-jobs store system)
500 (cross-jobs store system))))
502 ;; Build core packages only.
503 (append (map (lambda (package)
504 (package-job store (job-name package)
507 (cross-jobs store system)))
509 ;; Build hello package only.
510 (if (string=? system (%current-system))
511 (let ((hello (specification->package "hello")))
512 (list (package-job store (job-name hello) hello system)))
515 ;; Build selected list of packages only.
516 (if (string=? system (%current-system))
517 (let* ((names (assoc-ref arguments 'subset))
518 (packages (map specification->package names)))
519 (map (lambda (package)
520 (package-job store (job-name package)
525 ;; Build packages in the list of manifests.
526 (let* ((manifests (arguments->manifests arguments))
527 (packages (manifests->packages store manifests)))
528 (map (lambda (package)
529 (package-job store (job-name package)
533 (error "unknown subset" subset))))