ci.scm 20 KB

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