compile: Report the name of the file that cannot be compiled.

Fixes <https://bugs.gnu.org/36640>.
Reported by Robert Vollmert <rob@vllmrt.net>.

* guix/build/compile.scm (call/exit-on-exception): Add 'file' parameter
and honor it.
(exit-on-exception): Likewise.
(compile-files): Pass FILE to 'exit-on-exception'.
This commit is contained in:
Ludovic Courtès 2019-07-14 17:07:09 +02:00
parent 2f3c0fb39d
commit 38302bd939
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 10 additions and 5 deletions

View File

@ -129,8 +129,9 @@ front."
(lambda () (lambda ()
(set! path initial-value))))) (set! path initial-value)))))
(define (call/exit-on-exception thunk) (define (call/exit-on-exception file thunk)
"Evaluate THUNK and exit right away if an exception is thrown." "Evaluate THUNK and exit right away if an exception is thrown. Report FILE
as the file that was being compiled when the exception was thrown."
(catch #t (catch #t
thunk thunk
(const #f) (const #f)
@ -141,15 +142,18 @@ front."
(stack (make-stack #t)) (stack (make-stack #t))
(depth (stack-length stack)) (depth (stack-length stack))
(frame (and (> depth 1) (stack-ref stack 1)))) (frame (and (> depth 1) (stack-ref stack 1))))
(newline port)
(format port "error: failed to compile '~a':~%~%" file)
(false-if-exception (display-backtrace stack port)) (false-if-exception (display-backtrace stack port))
(print-exception port frame key args))) (print-exception port frame key args)))
;; Don't go any further. ;; Don't go any further.
(primitive-exit 1)))) (primitive-exit 1))))
(define-syntax-rule (exit-on-exception exp ...) (define-syntax-rule (exit-on-exception file exp ...)
"Evaluate EXP and exit if an exception is thrown." "Evaluate EXP and exit if an exception is thrown. Report FILE as the faulty
(call/exit-on-exception (lambda () exp ...))) file when an exception is thrown."
(call/exit-on-exception file (lambda () exp ...)))
(define* (compile-files source-directory build-directory files (define* (compile-files source-directory build-directory files
#:key #:key
@ -173,6 +177,7 @@ files are for HOST, a GNU triplet such as \"x86_64-linux-gnu\"."
;; Exit as soon as something goes wrong. ;; Exit as soon as something goes wrong.
(exit-on-exception (exit-on-exception
file
(with-target host (with-target host
(lambda () (lambda ()
(let ((relative (relative-file source-directory file))) (let ((relative (relative-file source-directory file)))