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)
31 (and=> (assq-ref (current-source-location) 'filename)
34 (string-append (dirname file) "/../..")))))
38 (let ((m (make-module)))
39 (beautify-user-module! m)
44 ;; Guile 2.2.2 has a bug whereby 'time-monotonic' objects have seconds and
45 ;; nanoseconds swapped (fixed in Guile commit 886ac3e). Work around it.
46 (define time-monotonic time-tai))
49 (define (call-with-time thunk kont)
50 "Call THUNK and pass KONT the elapsed time followed by THUNK's return
52 (let* ((start (current-time time-monotonic))
53 (result (call-with-values thunk list))
54 (end (current-time time-monotonic)))
55 (apply kont (time-difference end start) result)))
57 (define (call-with-time-display thunk)
58 "Call THUNK and write to the current output port its duration."
60 (lambda (time . results)
61 (format #t "~,3f seconds~%"
63 (/ (time-nanosecond time) 1e9)))
64 (apply values results))))
66 (define (assert-valid-job job thing)
67 "Raise an error if THING is not an alist with a valid 'derivation' entry.
68 Otherwise return THING."
69 (unless (and (list? thing)
70 (and=> (assoc-ref thing 'derivation)
73 (string-suffix? ".drv" value)))))
74 (error "job did not produce a valid alist" job thing))
78 ;; Without further ado...
80 ((command file cuirass? ...)
81 ;; Load FILE, a Scheme file that defines Hydra jobs.
82 (let ((port (current-output-port)))
83 (save-module-excursion
85 (set-current-module %user-module)
86 (primitive-load file)))
89 ;; Make sure we don't resort to substitutes.
90 (set-build-options store
92 #:substitute-urls '())
94 ;; Grafts can trigger early builds. We do not want that to happen
95 ;; during evaluation, so use a sledgehammer to catch such problems.
97 (lambda (store . args)
98 (format (current-error-port)
99 "error: trying to build things during evaluation!~%")
100 (format (current-error-port)
101 "'build-things' arguments: ~s~%" args)
104 ;; Call the entry point of FILE and print the resulting job sexp.
106 (match ((module-ref %user-module
107 (if (equal? cuirass? "cuirass")
111 . ((file-name . ,%top-srcdir)))))
112 (((names . thunks) ...)
113 (map (lambda (job thunk)
114 (format (current-error-port) "evaluating '~a'... " job)
115 (force-output (current-error-port))
117 (assert-valid-job job
118 (call-with-time-display thunk))))
122 (format (current-error-port) "Usage: ~a FILE [cuirass]
123 Evaluate the Hydra or Cuirass jobs defined in FILE.~%"
128 ;;; eval: (put 'call-with-time 'scheme-indent-function 1)