Commit | Line | Data |
---|---|---|
59fb5c1c | 1 | ;;; GNU Guix --- Functional package management for GNU |
7e6d8d36 | 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
59fb5c1c | 3 | ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org> |
f71b0a00 | 4 | ;;; Copyright © 2018, 2019 Clément Lassieur <clement@lassieur.org> |
59fb5c1c LC |
5 | ;;; |
6 | ;;; This file is part of GNU Guix. | |
7 | ;;; | |
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. | |
12 | ;;; | |
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. | |
17 | ;;; | |
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/>. | |
20 | ||
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) | |
7e6d8d36 | 27 | #:use-module (guix channels) |
59fb5c1c | 28 | #:use-module (guix derivations) |
7e6d8d36 | 29 | #:use-module (guix build-system) |
59fb5c1c LC |
30 | #:use-module (guix monads) |
31 | #:use-module (guix ui) | |
b5f8c2c8 LC |
32 | #:use-module ((guix licenses) |
33 | #:select (gpl3+ license? license-name)) | |
59fb5c1c LC |
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) | |
887fd835 LC |
57 | #:export (channel-instance->package |
58 | hydra-jobs)) | |
59fb5c1c LC |
59 | |
60 | ;;; Commentary: | |
61 | ;;; | |
62 | ;;; This file defines build jobs for the Hydra and Cuirass continuation | |
63 | ;;; integration tools. | |
64 | ;;; | |
65 | ;;; Code: | |
66 | ||
67 | (define* (package->alist store package system | |
68 | #:optional (package-derivation package-derivation)) | |
69 | "Convert PACKAGE to an alist suitable for Hydra." | |
70 | (parameterize ((%graft? #f)) | |
71 | `((derivation . ,(derivation-file-name | |
72 | (package-derivation store package system | |
73 | #:graft? #f))) | |
74 | (description . ,(package-synopsis package)) | |
75 | (long-description . ,(package-description package)) | |
b5f8c2c8 LC |
76 | |
77 | ;; XXX: Hydra ignores licenses that are not a <license> structure or a | |
78 | ;; list thereof. | |
79 | (license . ,(let loop ((license (package-license package))) | |
80 | (match license | |
81 | ((? license?) | |
82 | (license-name license)) | |
83 | ((lst ...) | |
84 | (map loop license))))) | |
85 | ||
59fb5c1c LC |
86 | (home-page . ,(package-home-page package)) |
87 | (maintainers . ("bug-guix@gnu.org")) | |
88 | (max-silent-time . ,(or (assoc-ref (package-properties package) | |
89 | 'max-silent-time) | |
90 | 3600)) ;1 hour by default | |
91 | (timeout . ,(or (assoc-ref (package-properties package) 'timeout) | |
92 | 72000))))) ;20 hours by default | |
93 | ||
94 | (define (package-job store job-name package system) | |
95 | "Return a job called JOB-NAME that builds PACKAGE on SYSTEM." | |
96 | (let ((job-name (symbol-append job-name (string->symbol ".") | |
97 | (string->symbol system)))) | |
98 | `(,job-name . ,(cut package->alist store package system)))) | |
99 | ||
100 | (define (package-cross-job store job-name package target system) | |
101 | "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on | |
102 | SYSTEM." | |
103 | `(,(symbol-append (string->symbol target) (string->symbol ".") job-name | |
104 | (string->symbol ".") (string->symbol system)) . | |
105 | ,(cute package->alist store package system | |
106 | (lambda* (store package system #:key graft?) | |
107 | (package-cross-derivation store package target system | |
108 | #:graft? graft?))))) | |
109 | ||
110 | (define %core-packages | |
111 | ;; Note: Don't put the '-final' package variants because (1) that's | |
112 | ;; implicit, and (2) they cannot be cross-built (due to the explicit input | |
113 | ;; chain.) | |
114 | (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils | |
115 | gmp mpfr mpc coreutils findutils diffutils patch sed grep | |
116 | gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz | |
117 | %bootstrap-binaries-tarball | |
118 | %binutils-bootstrap-tarball | |
119 | (%glibc-bootstrap-tarball) | |
120 | %gcc-bootstrap-tarball | |
121 | %guile-bootstrap-tarball | |
122 | %bootstrap-tarballs)) | |
123 | ||
124 | (define %packages-to-cross-build | |
125 | %core-packages) | |
126 | ||
127 | (define %cross-targets | |
128 | '("mips64el-linux-gnu" | |
129 | "mips64el-linux-gnuabi64" | |
130 | "arm-linux-gnueabihf" | |
131 | "aarch64-linux-gnu" | |
132 | "powerpc-linux-gnu" | |
133 | "i586-pc-gnu" ;aka. GNU/Hurd | |
67dac6b8 CD |
134 | "i686-w64-mingw32" |
135 | "x86_64-w64-mingw32")) | |
59fb5c1c LC |
136 | |
137 | (define %guixsd-supported-systems | |
138 | '("x86_64-linux" "i686-linux" "armhf-linux")) | |
139 | ||
140 | (define %u-boot-systems | |
141 | '("armhf-linux")) | |
142 | ||
143 | (define (qemu-jobs store system) | |
144 | "Return a list of jobs that build QEMU images for SYSTEM." | |
145 | (define (->alist drv) | |
146 | `((derivation . ,(derivation-file-name drv)) | |
147 | (description . "Stand-alone QEMU image of the GNU system") | |
148 | (long-description . "This is a demo stand-alone QEMU image of the GNU | |
149 | system.") | |
b5f8c2c8 | 150 | (license . ,(license-name gpl3+)) |
59fb5c1c LC |
151 | (max-silent-time . 600) |
152 | (timeout . 3600) | |
153 | (home-page . ,%guix-home-page-url) | |
154 | (maintainers . ("bug-guix@gnu.org")))) | |
155 | ||
156 | (define (->job name drv) | |
157 | (let ((name (symbol-append name (string->symbol ".") | |
158 | (string->symbol system)))) | |
159 | `(,name . ,(lambda () | |
160 | (parameterize ((%graft? #f)) | |
161 | (->alist drv)))))) | |
162 | ||
163 | (define MiB | |
164 | (expt 2 20)) | |
165 | ||
166 | (if (member system %guixsd-supported-systems) | |
167 | (if (member system %u-boot-systems) | |
168 | (list (->job 'flash-image | |
169 | (run-with-store store | |
170 | (mbegin %store-monad | |
171 | (set-guile-for-build (default-guile)) | |
172 | (system-disk-image | |
173 | (operating-system (inherit installation-os) | |
174 | (bootloader (bootloader-configuration | |
175 | (bootloader u-boot-bootloader) | |
176 | (target #f)))) | |
177 | #:disk-image-size | |
178 | (* 1500 MiB)))))) | |
179 | (list (->job 'usb-image | |
180 | (run-with-store store | |
181 | (mbegin %store-monad | |
182 | (set-guile-for-build (default-guile)) | |
183 | (system-disk-image installation-os | |
184 | #:disk-image-size | |
185 | (* 1500 MiB))))) | |
186 | (->job 'iso9660-image | |
187 | (run-with-store store | |
188 | (mbegin %store-monad | |
189 | (set-guile-for-build (default-guile)) | |
190 | (system-disk-image installation-os | |
191 | #:file-system-type | |
192 | "iso9660")))))) | |
193 | '())) | |
194 | ||
7e6d8d36 LC |
195 | (define channel-build-system |
196 | ;; Build system used to "convert" a channel instance to a package. | |
197 | (let* ((build (lambda* (store name inputs | |
c3ab921e LC |
198 | #:key instance system |
199 | #:allow-other-keys) | |
7e6d8d36 | 200 | (run-with-store store |
c3ab921e LC |
201 | (channel-instances->derivation (list instance)) |
202 | #:system system))) | |
7e6d8d36 LC |
203 | (lower (lambda* (name #:key system instance #:allow-other-keys) |
204 | (bag | |
205 | (name name) | |
206 | (system system) | |
207 | (build build) | |
208 | (arguments `(#:instance ,instance)))))) | |
209 | (build-system (name 'channel) | |
210 | (description "Turn a channel instance into a package.") | |
211 | (lower lower)))) | |
212 | ||
213 | (define (channel-instance->package instance) | |
214 | "Return a package for the given channel INSTANCE." | |
215 | (package | |
216 | (inherit guix) | |
217 | (version (or (string-take (channel-instance-commit instance) 7) | |
218 | (string-append (package-version guix) "+"))) | |
219 | (build-system channel-build-system) | |
220 | (arguments `(#:instance ,instance)) | |
221 | (inputs '()) | |
222 | (native-inputs '()) | |
223 | (propagated-inputs '()))) | |
224 | ||
225 | (define* (system-test-jobs store system | |
226 | #:key source commit) | |
59fb5c1c | 227 | "Return a list of jobs for the system tests." |
7e6d8d36 LC |
228 | (define instance |
229 | (checkout->channel-instance source #:commit commit)) | |
230 | ||
59fb5c1c LC |
231 | (define (test->thunk test) |
232 | (lambda () | |
233 | (define drv | |
234 | (run-with-store store | |
235 | (mbegin %store-monad | |
236 | (set-current-system system) | |
237 | (set-grafting #f) | |
238 | (set-guile-for-build (default-guile)) | |
239 | (system-test-value test)))) | |
240 | ||
241 | `((derivation . ,(derivation-file-name drv)) | |
59e80445 | 242 | (description . ,(format #f "Guix '~a' system test" |
59fb5c1c LC |
243 | (system-test-name test))) |
244 | (long-description . ,(system-test-description test)) | |
b5f8c2c8 | 245 | (license . ,(license-name gpl3+)) |
59fb5c1c LC |
246 | (max-silent-time . 600) |
247 | (timeout . 3600) | |
248 | (home-page . ,%guix-home-page-url) | |
249 | (maintainers . ("bug-guix@gnu.org"))))) | |
250 | ||
251 | (define (->job test) | |
252 | (let ((name (string->symbol | |
253 | (string-append "test." (system-test-name test) | |
254 | "." system)))) | |
255 | (cons name (test->thunk test)))) | |
256 | ||
c680a7da LC |
257 | (if (and (member system %guixsd-supported-systems) |
258 | ||
259 | ;; XXX: Our build farm has too few ARMv7 machines and they are very | |
260 | ;; slow, so skip system tests there. | |
261 | (not (string=? system "armhf-linux"))) | |
7e6d8d36 LC |
262 | ;; Override the value of 'current-guix' used by system tests. Using a |
263 | ;; channel instance makes tests that rely on 'current-guix' less | |
264 | ;; expensive. It also makes sure we get a valid Guix package when this | |
265 | ;; code is not running from a checkout. | |
266 | (parameterize ((current-guix-package | |
267 | (channel-instance->package instance))) | |
268 | (map ->job (all-system-tests))) | |
59fb5c1c LC |
269 | '())) |
270 | ||
271 | (define (tarball-jobs store system) | |
272 | "Return Hydra jobs to build the self-contained Guix binary tarball." | |
273 | (define (->alist drv) | |
274 | `((derivation . ,(derivation-file-name drv)) | |
275 | (description . "Stand-alone binary Guix tarball") | |
276 | (long-description . "This is a tarball containing binaries of Guix and | |
59e80445 | 277 | all its dependencies, and ready to be installed on \"foreign\" distributions.") |
b5f8c2c8 | 278 | (license . ,(license-name gpl3+)) |
59fb5c1c LC |
279 | (home-page . ,%guix-home-page-url) |
280 | (maintainers . ("bug-guix@gnu.org")))) | |
281 | ||
282 | (define (->job name drv) | |
283 | (let ((name (symbol-append name (string->symbol ".") | |
284 | (string->symbol system)))) | |
285 | `(,name . ,(lambda () | |
286 | (parameterize ((%graft? #f)) | |
287 | (->alist drv)))))) | |
288 | ||
289 | ;; XXX: Add a job for the stable Guix? | |
290 | (list (->job 'binary-tarball | |
291 | (run-with-store store | |
292 | (mbegin %store-monad | |
293 | (set-guile-for-build (default-guile)) | |
294 | (>>= (profile-derivation (packages->manifest (list guix))) | |
295 | (lambda (profile) | |
296 | (self-contained-tarball "guix-binary" profile | |
297 | #:localstatedir? #t | |
298 | #:compressor | |
299 | (lookup-compressor "xz"))))) | |
300 | #:system system)))) | |
301 | ||
302 | (define job-name | |
303 | ;; Return the name of a package's job. | |
304 | (compose string->symbol | |
305 | (cut package-full-name <> "-"))) | |
306 | ||
307 | (define package->job | |
308 | (let ((base-packages | |
309 | (delete-duplicates | |
310 | (append-map (match-lambda | |
311 | ((_ package _ ...) | |
312 | (match (package-transitive-inputs package) | |
313 | (((_ inputs _ ...) ...) | |
314 | inputs)))) | |
315 | (%final-inputs))))) | |
316 | (lambda (store package system) | |
317 | "Return a job for PACKAGE on SYSTEM, or #f if this combination is not | |
318 | valid." | |
319 | (cond ((member package base-packages) | |
320 | (package-job store (symbol-append 'base. (job-name package)) | |
321 | package system)) | |
322 | ((supported-package? package system) | |
323 | (let ((drv (package-derivation store package system | |
324 | #:graft? #f))) | |
325 | (and (substitutable-derivation? drv) | |
326 | (package-job store (job-name package) | |
327 | package system)))) | |
328 | (else | |
329 | #f))))) | |
330 | ||
331 | (define (all-packages) | |
332 | "Return the list of packages to build." | |
333 | (define (adjust package result) | |
334 | (cond ((package-replacement package) | |
f00ff8db LC |
335 | ;; XXX: If PACKAGE and its replacement have the same name/version, |
336 | ;; then both Cuirass jobs will have the same name, which | |
337 | ;; effectively means that the second one will be ignored. Thus, | |
338 | ;; return the replacement first. | |
339 | (cons* (package-replacement package) ;build both | |
340 | package | |
59fb5c1c LC |
341 | result)) |
342 | ((package-superseded package) | |
343 | result) ;don't build it | |
344 | (else | |
345 | (cons package result)))) | |
346 | ||
347 | (fold-packages adjust | |
348 | (fold adjust '() ;include base packages | |
349 | (match (%final-inputs) | |
350 | (((labels packages _ ...) ...) | |
351 | packages))) | |
352 | #:select? (const #t))) ;include hidden packages | |
353 | ||
354 | (define (arguments->manifests arguments) | |
355 | "Return the list of manifests extracted from ARGUMENTS." | |
356 | (map (match-lambda | |
357 | ((input-name . relative-path) | |
358 | (let* ((checkout (assq-ref arguments (string->symbol input-name))) | |
359 | (base (assq-ref checkout 'file-name))) | |
360 | (in-vicinity base relative-path)))) | |
361 | (assq-ref arguments 'manifests))) | |
362 | ||
363 | (define (manifests->packages store manifests) | |
364 | "Return the list of packages found in MANIFESTS." | |
365 | (define (load-manifest manifest) | |
366 | (save-module-excursion | |
367 | (lambda () | |
368 | (set-current-module (make-user-module '((guix profiles) (gnu)))) | |
369 | (primitive-load manifest)))) | |
370 | ||
371 | (delete-duplicates! | |
372 | (map manifest-entry-item | |
373 | (append-map (compose manifest-entries | |
374 | load-manifest) | |
375 | manifests)))) | |
376 | ||
f71b0a00 CL |
377 | (define (find-current-checkout arguments) |
378 | "Find the first checkout of ARGUMENTS that provided the current file. | |
379 | Return #f if no such checkout is found." | |
380 | (let ((current-root | |
381 | (canonicalize-path | |
382 | (string-append (dirname (current-filename)) "/..")))) | |
383 | (find (lambda (argument) | |
384 | (and=> (assq-ref argument 'file-name) | |
385 | (lambda (name) | |
386 | (string=? name current-root)))) arguments))) | |
387 | ||
59fb5c1c LC |
388 | \f |
389 | ;;; | |
390 | ;;; Hydra entry point. | |
391 | ;;; | |
392 | ||
393 | (define (hydra-jobs store arguments) | |
394 | "Return Hydra jobs." | |
395 | (define subset | |
396 | (match (assoc-ref arguments 'subset) | |
397 | ("core" 'core) ; only build core packages | |
398 | ("hello" 'hello) ; only build hello | |
399 | (((? string?) (? string?) ...) 'list) ; only build selected list of packages | |
400 | ("manifests" 'manifests) ; only build packages in the list of manifests | |
401 | (_ 'all))) ; build everything | |
402 | ||
403 | (define systems | |
404 | (match (assoc-ref arguments 'systems) | |
405 | (#f %hydra-supported-systems) | |
406 | ((lst ...) lst) | |
407 | ((? string? str) (call-with-input-string str read)))) | |
408 | ||
7e6d8d36 | 409 | (define checkout |
f71b0a00 CL |
410 | (or (find-current-checkout arguments) |
411 | (assq-ref arguments 'superior-guix-checkout))) | |
7e6d8d36 LC |
412 | |
413 | (define commit | |
414 | (assq-ref checkout 'revision)) | |
415 | ||
416 | (define source | |
417 | (assq-ref checkout 'file-name)) | |
418 | ||
59fb5c1c LC |
419 | (define (cross-jobs system) |
420 | (define (from-32-to-64? target) | |
421 | ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack | |
422 | ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to | |
423 | ;; mips64el-linux-gnuabi64. | |
424 | (and (or (string-prefix? "i686-" system) | |
425 | (string-prefix? "i586-" system) | |
426 | (string-prefix? "armhf-" system)) | |
427 | (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc. | |
428 | ||
429 | (define (same? target) | |
430 | ;; Return true if SYSTEM and TARGET are the same thing. This is so we | |
431 | ;; don't try to cross-compile to 'mips64el-linux-gnu' from | |
432 | ;; 'mips64el-linux'. | |
433 | (or (string-contains target system) | |
434 | (and (string-prefix? "armhf" system) ;armhf-linux | |
435 | (string-prefix? "arm" target)))) ;arm-linux-gnueabihf | |
436 | ||
437 | (define (pointless? target) | |
438 | ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM. | |
439 | (match system | |
440 | ((or "x86_64-linux" "i686-linux") | |
441 | (if (string-contains target "mingw") | |
442 | (not (string=? "x86_64-linux" system)) | |
443 | #f)) | |
444 | (_ | |
445 | ;; Don't try to cross-compile from non-Intel platforms: this isn't | |
446 | ;; very useful and these are often brittle configurations. | |
447 | #t))) | |
448 | ||
449 | (define (either proc1 proc2 proc3) | |
450 | (lambda (x) | |
451 | (or (proc1 x) (proc2 x) (proc3 x)))) | |
452 | ||
453 | (append-map (lambda (target) | |
454 | (map (lambda (package) | |
455 | (package-cross-job store (job-name package) | |
456 | package target system)) | |
457 | %packages-to-cross-build)) | |
458 | (remove (either from-32-to-64? same? pointless?) | |
459 | %cross-targets))) | |
460 | ||
461 | ;; Turn off grafts. Grafting is meant to happen on the user's machines. | |
462 | (parameterize ((%graft? #f)) | |
463 | ;; Return one job for each package, except bootstrap packages. | |
464 | (append-map (lambda (system) | |
465 | (format (current-error-port) | |
466 | "evaluating for '~a' (heap size: ~a MiB)...~%" | |
467 | system | |
468 | (round | |
469 | (/ (assoc-ref (gc-stats) 'heap-size) | |
470 | (expt 2. 20)))) | |
471 | (invalidate-derivation-caches!) | |
472 | (case subset | |
473 | ((all) | |
474 | ;; Build everything, including replacements. | |
475 | (let ((all (all-packages)) | |
476 | (job (lambda (package) | |
477 | (package->job store package | |
478 | system)))) | |
479 | (append (filter-map job all) | |
480 | (qemu-jobs store system) | |
7e6d8d36 LC |
481 | (system-test-jobs store system |
482 | #:source source | |
483 | #:commit commit) | |
59fb5c1c LC |
484 | (tarball-jobs store system) |
485 | (cross-jobs system)))) | |
486 | ((core) | |
487 | ;; Build core packages only. | |
488 | (append (map (lambda (package) | |
489 | (package-job store (job-name package) | |
490 | package system)) | |
491 | %core-packages) | |
492 | (cross-jobs system))) | |
493 | ((hello) | |
494 | ;; Build hello package only. | |
495 | (if (string=? system (%current-system)) | |
496 | (let ((hello (specification->package "hello"))) | |
497 | (list (package-job store (job-name hello) hello system))) | |
498 | '())) | |
499 | ((list) | |
500 | ;; Build selected list of packages only. | |
501 | (if (string=? system (%current-system)) | |
502 | (let* ((names (assoc-ref arguments 'subset)) | |
503 | (packages (map specification->package names))) | |
504 | (map (lambda (package) | |
505 | (package-job store (job-name package) | |
506 | package system)) | |
507 | packages)) | |
508 | '())) | |
509 | ((manifests) | |
510 | ;; Build packages in the list of manifests. | |
511 | (let* ((manifests (arguments->manifests arguments)) | |
512 | (packages (manifests->packages store manifests))) | |
513 | (map (lambda (package) | |
514 | (package-job store (job-name package) | |
515 | package system)) | |
516 | packages))) | |
517 | (else | |
518 | (error "unknown subset" subset)))) | |
519 | systems))) |