1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 ;;; This program replicates the behavior of Hydra's 'hydra-eval-guile-job'.
20 ;;; It evaluates the Hydra job defined by the program passed as its first
21 ;;; arguments and outputs an sexp of the jobs on standard output.
23 (use-modules (guix store)
31 (let ((m (make-module)))
32 (beautify-user-module! m)
35 (define (call-with-time thunk kont)
36 "Call THUNK and pass KONT the elapsed time followed by THUNK's return
38 (let* ((start (current-time time-monotonic))
39 (result (call-with-values thunk list))
40 (end (current-time time-monotonic)))
41 (apply kont (time-difference end start) result)))
43 (define (call-with-time-display thunk)
44 "Call THUNK and write to the current output port its duration."
46 (lambda (time . results)
47 (format #t "~,3f seconds~%"
49 (/ (time-nanosecond time) 1e9)))
50 (apply values results))))
52 (define (assert-valid-job job thing)
53 "Raise an error if THING is not an alist with a valid 'derivation' entry.
54 Otherwise return THING."
55 (unless (and (list? thing)
56 (and=> (assoc-ref thing 'derivation)
59 (string-suffix? ".drv" value)))))
60 (error "job did not produce a valid alist" job thing))
64 ;; Without further ado...
67 ;; Load FILE, a Scheme file that defines Hydra jobs.
68 (let ((port (current-output-port)))
69 (save-module-excursion
71 (set-current-module %user-module)
72 (primitive-load file)))
75 ;; Make sure we don't resort to substitutes.
76 (set-build-options store
78 #:substitute-urls '())
80 ;; Grafts can trigger early builds. We do not want that to happen
81 ;; during evaluation, so use a sledgehammer to catch such problems.
83 (lambda (store . args)
84 (format (current-error-port)
85 "error: trying to build things during evaluation!~%")
86 (format (current-error-port)
87 "'build-things' arguments: ~s~%" args)
90 ;; Call the entry point of FILE and print the resulting job sexp.
92 (match ((module-ref %user-module 'hydra-jobs) store '())
93 (((names . thunks) ...)
94 (map (lambda (job thunk)
95 (format (current-error-port) "evaluating '~a'... " job)
96 (force-output (current-error-port))
99 (call-with-time-display thunk))))
103 (format (current-error-port) "Usage: ~a FILE
104 Evaluate the Hydra jobs defined in FILE.~%"
109 ;;; eval: (put 'call-with-time 'scheme-indent-function 1)