guix-build: Gracefully handle `&package-input-error' conditions.

* guix/packages.scm: Export `package-error?' and `package-input-error?'.
* guix-build.in (guix-build): Catch `&package-input-error' conditions,
  print a human-readable message, and exit.
This commit is contained in:
Ludovic Courtès 2012-10-27 14:56:38 +02:00
parent 5e6c90121f
commit 0778385802
2 changed files with 79 additions and 62 deletions

View File

@ -30,11 +30,12 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \
#:use-module (guix store) #:use-module (guix store)
#:use-module (guix derivations) #:use-module (guix derivations)
#:use-module (guix packages) #:use-module (guix packages)
#:use-module ((guix utils) #:select (%current-system)) #:use-module (guix utils)
#:use-module (ice-9 format) #:use-module (ice-9 format)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-37) #:use-module (srfi srfi-37)
#:autoload (distro) (find-packages-by-name) #:autoload (distro) (find-packages-by-name)
#:export (guix-build)) #:export (guix-build))
@ -169,65 +170,79 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
(setvbuf (current-output-port) _IOLBF) (setvbuf (current-output-port) _IOLBF)
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)
(let* ((opts (parse-options)) (guard (c ((package-input-error? c)
(src? (assoc-ref opts 'source?)) (let* ((package (package-error-package c))
(sys (assoc-ref opts 'system)) (input (package-error-invalid-input c))
(drv (filter-map (match-lambda (location (package-location package))
(('expression . exp) (file (location-file location))
(derivations-from-package-expressions exp sys (line (location-line location))
src?)) (column (location-column location)))
(('argument . (? derivation-path? drv)) (leave (_ "~a:~a:~a: error: package `~a' has an invalid input: ~s~%")
drv) file line column
(('argument . (? string? x)) (package-full-name package) input))))
(match (find-packages-by-name x) (let* ((opts (parse-options))
((p _ ...) (src? (assoc-ref opts 'source?))
(if src? (sys (assoc-ref opts 'system))
(let ((s (package-source p))) (drv (filter-map (match-lambda
(package-source-derivation %store s)) (('expression . exp)
(package-derivation %store p sys))) (derivations-from-package-expressions exp sys
(_ src?))
(leave (_ "~A: unknown package~%") x)))) (('argument . (? derivation-path? drv))
(_ #f)) drv)
opts)) (('argument . (? string? x))
(req (append-map (lambda (drv-path) (match (find-packages-by-name x)
(let ((d (call-with-input-file drv-path ((p _ ...)
read-derivation))) (if src?
(derivation-prerequisites-to-build %store d))) (let ((s (package-source p)))
drv)) (package-source-derivation %store s))
(req* (delete-duplicates (package-derivation %store p sys)))
(append (remove (compose (cut valid-path? %store <>) (_
derivation-path->output-path) (leave (_ "~A: unknown package~%") x))))
drv) (_ #f))
(map derivation-input-path req))))) opts))
(if (assoc-ref opts 'dry-run?) (req (append-map (lambda (drv-path)
(format (current-error-port) (let ((d (call-with-input-file drv-path
(N_ "~:[the following derivation would be built:~%~{ ~a~%~}~;~]"
"~:[the following derivations would be built:~%~{ ~a~%~}~;~]"
(length req*))
(null? req*) req*)
(format (current-error-port)
(N_ "~:[the following derivation will be built:~%~{ ~a~%~}~;~]"
"~:[the following derivations will be built:~%~{ ~a~%~}~;~]"
(length req*))
(null? req*) req*))
;; TODO: Add more options.
(set-build-options %store
#:keep-failed? (assoc-ref opts 'keep-failed?)
#:build-cores (or (assoc-ref opts 'cores) 0)
#:use-substitutes? (assoc-ref opts 'substitutes?))
(if (assoc-ref opts 'derivations-only?)
(format #t "~{~a~%~}" drv)
(or (assoc-ref opts 'dry-run?)
(and (build-derivations %store drv)
(for-each (lambda (d)
(let ((drv (call-with-input-file d
read-derivation))) read-derivation)))
(format #t "~{~a~%~}" (derivation-prerequisites-to-build %store d)))
(map (match-lambda drv))
((out-name . out) (req* (delete-duplicates
(derivation-path->output-path (append (remove (compose (cut valid-path? %store <>)
d out-name))) derivation-path->output-path)
(derivation-outputs drv))))) drv)
drv)))))) (map derivation-input-path req)))))
(if (assoc-ref opts 'dry-run?)
(format (current-error-port)
(N_ "~:[the following derivation would be built:~%~{ ~a~%~}~;~]"
"~:[the following derivations would be built:~%~{ ~a~%~}~;~]"
(length req*))
(null? req*) req*)
(format (current-error-port)
(N_ "~:[the following derivation will be built:~%~{ ~a~%~}~;~]"
"~:[the following derivations will be built:~%~{ ~a~%~}~;~]"
(length req*))
(null? req*) req*))
;; TODO: Add more options.
(set-build-options %store
#:keep-failed? (assoc-ref opts 'keep-failed?)
#:build-cores (or (assoc-ref opts 'cores) 0)
#:use-substitutes? (assoc-ref opts 'substitutes?))
(if (assoc-ref opts 'derivations-only?)
(format #t "~{~a~%~}" drv)
(or (assoc-ref opts 'dry-run?)
(and (build-derivations %store drv)
(for-each (lambda (d)
(let ((drv (call-with-input-file d
read-derivation)))
(format #t "~{~a~%~}"
(map (match-lambda
((out-name . out)
(derivation-path->output-path
d out-name)))
(derivation-outputs drv)))))
drv)))))))
;; Local Variables:
;; eval: (put 'guard 'scheme-indent-function 1)
;; End:

View File

@ -61,8 +61,10 @@
package-cross-derivation package-cross-derivation
&package-error &package-error
package-error?
package-error-package package-error-package
&package-input-error &package-input-error
package-input-error?
package-error-invalid-input)) package-error-invalid-input))
;;; Commentary: ;;; Commentary: