1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2018, 2020 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)
26 ((guix build utils) #:select (with-directory-excursion))
27 ((guix ui) #:select (build-notifier))
34 (and=> (assq-ref (current-source-location) 'filename)
37 (string-append (dirname file) "/../..")))))
41 (let ((m (make-module)))
42 (beautify-user-module! m)
45 (define (call-with-time thunk kont)
46 "Call THUNK and pass KONT the elapsed time followed by THUNK's return
48 (let* ((start (current-time time-monotonic))
49 (result (call-with-values thunk list))
50 (end (current-time time-monotonic)))
51 (apply kont (time-difference end start) result)))
53 (define (call-with-time-display thunk)
54 "Call THUNK and write to the current output port its duration."
56 (lambda (time . results)
57 (format #t "~,3f seconds~%"
59 (/ (time-nanosecond time) 1e9)))
60 (apply values results))))
62 (define (assert-valid-job job thing)
63 "Raise an error if THING is not an alist with a valid 'derivation' entry.
64 Otherwise return THING."
65 (unless (and (list? thing)
66 (and=> (assoc-ref thing 'derivation)
69 (string-suffix? ".drv" value)))))
70 (error "job did not produce a valid alist" job thing))
74 ;; Without further ado...
76 ((command file cuirass? ...)
77 ;; Load FILE, a Scheme file that defines Hydra jobs.
78 (let ((port (current-output-port))
79 (real-build-things build-things))
81 ;; Make sure we don't resort to substitutes.
82 (set-build-options store
84 #:substitute-urls '())
86 ;; The evaluation of Guix itself requires building a "trampoline"
87 ;; program, and possibly everything it depends on. Thus, allow builds
88 ;; but print a notification.
89 (with-build-handler (build-notifier #:use-substitutes? #f)
91 ;; Add %TOP-SRCDIR to the store with a proper Git predicate so we work
92 ;; from a clean checkout
93 (let ((source (add-to-store store "guix-source" #t
95 #:select? (git-predicate %top-srcdir))))
96 (with-directory-excursion source
97 (save-module-excursion
99 (set-current-module %user-module)
100 (format (current-error-port)
101 "loading '~a' relative to '~a'...~%"
103 (primitive-load file))))
105 ;; Call the entry point of FILE and print the resulting job sexp.
107 (match ((module-ref %user-module
108 (if (equal? cuirass? "cuirass")
112 . ((file-name . ,source)))))
113 (((names . thunks) ...)
114 (map (lambda (job thunk)
115 (format (current-error-port) "evaluating '~a'... " job)
116 (force-output (current-error-port))
118 (assert-valid-job job
119 (call-with-time-display thunk))))
123 (format (current-error-port) "Usage: ~a FILE [cuirass]
124 Evaluate the Hydra or Cuirass jobs defined in FILE.~%"
129 ;;; eval: (put 'call-with-time 'scheme-indent-function 1)