guix-track-git.scm 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. ;;; guix-track-git.scm -- job specification tracking a guix packages's git
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
  4. ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
  5. ;;;
  6. ;;; This file is part of Cuirass.
  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. ;;; This file defines build jobs for the Hydra continuation integration
  22. ;;; tool.
  23. ;;;
  24. (define local-guix (string-append (getenv "HOME") "/src/guix"))
  25. (define local-cuirass (string-append (getenv "HOME") "/src/cuirass/src"))
  26. ;; Attempt to use our very own Guix modules.
  27. (eval-when (compile load eval)
  28. (set! %load-path (cons* local-guix local-cuirass %load-path))
  29. (set! %load-path (cons (string-append local-cuirass "/gnu/packages/patches") %load-path))
  30. (set! %load-compiled-path (cons local-guix %load-compiled-path))
  31. (set! %load-compiled-path (cons local-cuirass %load-compiled-path))
  32. ;; Ignore any available .go, and force recompilation. This is because our
  33. ;; checkout in the store has mtime set to the epoch, and thus .go files look
  34. ;; newer, even though they may not correspond.
  35. (set! %fresh-auto-compile #t))
  36. (use-modules (guix config)
  37. (guix store)
  38. (guix grafts)
  39. (guix packages)
  40. (guix derivations)
  41. (guix monads)
  42. ((guix licenses)
  43. #:select (gpl3+ license-name license-uri license-comment))
  44. ((guix utils) #:select (%current-system))
  45. ((guix scripts system) #:select (read-operating-system))
  46. (gnu packages)
  47. (gnu packages gcc)
  48. (gnu packages base)
  49. (gnu packages gawk)
  50. (gnu packages guile)
  51. (gnu packages gettext)
  52. (gnu packages compression)
  53. (gnu packages multiprecision)
  54. (gnu packages make-bootstrap)
  55. (gnu packages commencement)
  56. (gnu packages package-management)
  57. (gnu system)
  58. (gnu system vm)
  59. (gnu system install)
  60. (gnu tests)
  61. (srfi srfi-1)
  62. (srfi srfi-26)
  63. (ice-9 optargs)
  64. (ice-9 match))
  65. ;; XXX: Debugging hack: since `hydra-eval-guile-jobs' redirects the output
  66. ;; port to the bit bucket, let us write to the error port instead.
  67. (setvbuf (current-error-port) _IOLBF)
  68. (set-current-output-port (current-error-port))
  69. (define (license->alist lcs)
  70. "Return LCS <license> object as an alist."
  71. ;; Sometimes 'license' field is a list of licenses.
  72. (if (list? lcs)
  73. (map license->alist lcs)
  74. `((name . ,(license-name lcs))
  75. (uri . ,(license-uri lcs))
  76. (comment . ,(license-comment lcs)))))
  77. (define (package-metadata package)
  78. "Convert PACKAGE to an alist suitable for Hydra."
  79. `((#:description . ,(package-synopsis package))
  80. (#:long-description . ,(package-description package))
  81. (#:license . ,(license->alist (package-license package)))
  82. (#:home-page . ,(package-home-page package))
  83. (#:maintainers . ("bug-guix@gnu.org"))
  84. (#:max-silent-time . ,(or (assoc-ref (package-properties package)
  85. 'max-silent-time)
  86. 3600)) ;1 hour by default
  87. (#:timeout . ,(or (assoc-ref (package-properties package) 'timeout)
  88. 72000)))) ;20 hours by default
  89. (define (package-job store job-name package system)
  90. "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
  91. (λ ()
  92. `((#:job-name . ,(string-append (symbol->string job-name) "." system))
  93. (#:derivation . ,(derivation-file-name
  94. (parameterize ((%graft? #f))
  95. (package-derivation store package system
  96. #:graft? #f))))
  97. ,@(package-metadata package))))
  98. (define job-name
  99. ;; Return the name of a package's job.
  100. (compose string->symbol package-full-name))
  101. (define package->job
  102. (let ((base-packages
  103. (delete-duplicates
  104. (append-map (match-lambda
  105. ((_ package _ ...)
  106. (match (package-transitive-inputs package)
  107. (((_ inputs _ ...) ...)
  108. inputs))))
  109. %final-inputs))))
  110. (lambda (store package system)
  111. "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
  112. valid."
  113. (cond ((member package base-packages)
  114. #f)
  115. ((supported-package? package system)
  116. (package-job store (job-name package) package system))
  117. (else
  118. #f)))))
  119. ;;; END hydra/gnu-system.scm
  120. ;;;
  121. ;;; Cuirass CI tracking packages' git
  122. ;;;
  123. (use-modules (srfi srfi-11)
  124. (srfi srfi-9 gnu)
  125. (rnrs io ports)
  126. (gnu packages)
  127. (guix base32)
  128. (guix git-download)
  129. (guix hash)
  130. (guix packages)
  131. (guix serialization)
  132. (guix utils)
  133. (guix ui)
  134. (cuirass base))
  135. (define (url->file-name url)
  136. (string-trim
  137. (string-map (lambda (c) (if (memq c (string->list ":/")) #\- c)) url)
  138. #\-))
  139. (define* (package->spec pkg #:key (branch "master") commit url)
  140. (let ((url (or url ((compose git-reference-url origin-uri package-source) pkg))))
  141. `((#:name . ,(url->file-name url))
  142. (#:url . ,url)
  143. (#:branch . ,branch)
  144. (#:commit . ,commit))))
  145. (define (vcs-file? file stat)
  146. (case (stat:type stat)
  147. ((directory)
  148. (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS")))
  149. (else
  150. #f)))
  151. (define select? (negate vcs-file?))
  152. (define (file-hash file)
  153. ;; Compute the hash of FILE.
  154. ;; Catch and gracefully report possible '&nar-error' conditions.
  155. (with-error-handling
  156. (let-values (((port get-hash) (open-sha256-port)))
  157. (write-file file port #:select? select?)
  158. (flush-output-port port)
  159. (get-hash))))
  160. (define (commit? string)
  161. (string-every (string->char-set "0123456789abcdef") string))
  162. (define (call-with-output-fdes fdes new-file thunk)
  163. (let ((outport (fdes->outport fdes))
  164. (port (open-file new-file "w")))
  165. (move->fdes port fdes)
  166. (let ((result (thunk)))
  167. (move->fdes port fdes)
  168. result)))
  169. (define* (package->git-tracked pkg #:key (branch "master") commit url)
  170. (let* ((source (package-source pkg))
  171. (uri (origin-uri source)))
  172. (if (not branch) pkg
  173. (let* ((spec (package->spec pkg #:branch branch #:commit commit #:url url))
  174. (commit (call-with-output-fdes 1 "/dev/null"
  175. (lambda () (fetch-repository spec))))
  176. (url (or url (git-reference-url uri)))
  177. (git-dir (string-append (%package-cachedir) "/" (url->file-name url)))
  178. (hash (bytevector->nix-base32-string (file-hash git-dir)))
  179. (source (origin (uri (git-reference (url url) (commit commit)))
  180. (method git-fetch)
  181. (sha256 (base32 hash)))))
  182. (set-fields pkg ((package-source) source))))))
  183. ;;;
  184. ;;; Guix entry point.
  185. ;;;
  186. (define (guix-jobs store arguments)
  187. (let* ((name (or (assoc-ref arguments 'name) "hello"))
  188. (pkg (specification->package name))
  189. (branch (or (assoc-ref arguments 'branch) "master"))
  190. (url (assoc-ref arguments 'url))
  191. (pkg.git (package->git-tracked pkg #:branch branch #:url url))
  192. (system (or (assoc-ref arguments 'system) "x86_64-linux")))
  193. (parameterize ((%graft? #f))
  194. (list (package-job store (job-name pkg) pkg.git system)))))