1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 ;;; This program replicates the behavior of Hydra's 'hydra-eval-guile-job'.
21 ;;; It evaluates the Hydra job defined by the program passed as its first
22 ;;; arguments and outputs an sexp of the jobs on standard output.
24 (use-modules (guix store)
32 (let ((m (make-module)))
33 (beautify-user-module! m)
38 ;; Guile 2.2.2 has a bug whereby 'time-monotonic' objects have seconds and
39 ;; nanoseconds swapped (fixed in Guile commit 886ac3e). Work around it.
40 (define time-monotonic time-tai))
43 (define (call-with-time thunk kont)
44 "Call THUNK and pass KONT the elapsed time followed by THUNK's return
46 (let* ((start (current-time time-monotonic))
47 (result (call-with-values thunk list))
48 (end (current-time time-monotonic)))
49 (apply kont (time-difference end start) result)))
51 (define (call-with-time-display thunk)
52 "Call THUNK and write to the current output port its duration."
54 (lambda (time . results)
55 (format #t "~,3f seconds~%"
57 (/ (time-nanosecond time) 1e9)))
58 (apply values results))))
60 (define (assert-valid-job job thing)
61 "Raise an error if THING is not an alist with a valid 'derivation' entry.
62 Otherwise return THING."
63 (unless (and (list? thing)
64 (and=> (assoc-ref thing 'derivation)
67 (string-suffix? ".drv" value)))))
68 (error "job did not produce a valid alist" job thing))
72 ;; Without further ado...
74 ((command file cuirass? ...)
75 ;; Load FILE, a Scheme file that defines Hydra jobs.
76 (let ((port (current-output-port)))
77 (save-module-excursion
79 (set-current-module %user-module)
80 (primitive-load file)))
83 ;; Make sure we don't resort to substitutes.
84 (set-build-options store
86 #:substitute-urls '())
88 ;; Grafts can trigger early builds. We do not want that to happen
89 ;; during evaluation, so use a sledgehammer to catch such problems.
91 (lambda (store . args)
92 (format (current-error-port)
93 "error: trying to build things during evaluation!~%")
94 (format (current-error-port)
95 "'build-things' arguments: ~s~%" args)
98 ;; Call the entry point of FILE and print the resulting job sexp.
100 (match ((module-ref %user-module
101 (if (equal? cuirass? "cuirass")
105 (((names . thunks) ...)
106 (map (lambda (job thunk)
107 (format (current-error-port) "evaluating '~a'... " job)
108 (force-output (current-error-port))
110 (assert-valid-job job
111 (call-with-time-display thunk))))
115 (format (current-error-port) "Usage: ~a FILE [cuirass]
116 Evaluate the Hydra or Cuirass jobs defined in FILE.~%"
121 ;;; eval: (put 'call-with-time 'scheme-indent-function 1)