derivations: Raise an error when a module file is not found.
Suggested by Jookia. * guix/derivations.scm (&file-search-error): New error condition. (search-path*): Raise it when 'search-path' returns #f. * guix/gexp.scm (search-path*): Remove. * guix/ui.scm (call-with-error-handling): Add case for 'file-search-error?'. * tests/derivations.scm ("build-expression->derivation and invalid module name"): New test.
This commit is contained in:
parent
6985335faa
commit
d26e19671e
|
@ -90,7 +90,11 @@
|
||||||
build-derivations
|
build-derivations
|
||||||
built-derivations
|
built-derivations
|
||||||
|
|
||||||
|
file-search-error?
|
||||||
|
file-search-error-file-name
|
||||||
|
file-search-error-search-path
|
||||||
|
|
||||||
|
search-path*
|
||||||
module->source-file-name
|
module->source-file-name
|
||||||
build-expression->derivation)
|
build-expression->derivation)
|
||||||
|
|
||||||
|
@ -1036,10 +1040,22 @@ system, imported, and appears under FINAL-PATH in the resulting store path."
|
||||||
#:guile-for-build guile
|
#:guile-for-build guile
|
||||||
#:local-build? #t)))
|
#:local-build? #t)))
|
||||||
|
|
||||||
|
;; The "file not found" error condition.
|
||||||
|
(define-condition-type &file-search-error &error
|
||||||
|
file-search-error?
|
||||||
|
(file file-search-error-file-name)
|
||||||
|
(path file-search-error-search-path))
|
||||||
|
|
||||||
(define search-path*
|
(define search-path*
|
||||||
;; A memoizing version of 'search-path' so 'imported-modules' does not end
|
;; A memoizing version of 'search-path' so 'imported-modules' does not end
|
||||||
;; up looking for the same files over and over again.
|
;; up looking for the same files over and over again.
|
||||||
(memoize search-path))
|
(memoize (lambda (path file)
|
||||||
|
"Search for FILE in PATH and memoize the result. Raise a
|
||||||
|
'&file-search-error' condition if it could not be found."
|
||||||
|
(or (search-path path file)
|
||||||
|
(raise (condition
|
||||||
|
(&file-search-error (file file)
|
||||||
|
(path path))))))))
|
||||||
|
|
||||||
(define (module->source-file-name module)
|
(define (module->source-file-name module)
|
||||||
"Return the file name corresponding to MODULE, a Guile module name (a list
|
"Return the file name corresponding to MODULE, a Guile module name (a list
|
||||||
|
|
|
@ -902,11 +902,6 @@ system, imported, and appears under FINAL-PATH in the resulting store path."
|
||||||
#:guile-for-build guile
|
#:guile-for-build guile
|
||||||
#:local-build? #t)))
|
#:local-build? #t)))
|
||||||
|
|
||||||
(define search-path*
|
|
||||||
;; A memoizing version of 'search-path' so 'imported-modules' does not end
|
|
||||||
;; up looking for the same files over and over again.
|
|
||||||
(memoize search-path))
|
|
||||||
|
|
||||||
(define* (imported-modules modules
|
(define* (imported-modules modules
|
||||||
#:key (name "module-import")
|
#:key (name "module-import")
|
||||||
(system (%current-system))
|
(system (%current-system))
|
||||||
|
|
|
@ -461,6 +461,11 @@ interpreted."
|
||||||
(leave (_ "reference to invalid output '~a' of derivation '~a'~%")
|
(leave (_ "reference to invalid output '~a' of derivation '~a'~%")
|
||||||
(derivation-missing-output c)
|
(derivation-missing-output c)
|
||||||
(derivation-file-name (derivation-error-derivation c))))
|
(derivation-file-name (derivation-error-derivation c))))
|
||||||
|
((file-search-error? c)
|
||||||
|
(leave (_ "file '~a' could not be found in these \
|
||||||
|
directories:~{ ~a~}~%")
|
||||||
|
(file-search-error-file-name c)
|
||||||
|
(file-search-error-search-path c)))
|
||||||
((message-condition? c)
|
((message-condition? c)
|
||||||
;; Normally '&message' error conditions have an i18n'd message.
|
;; Normally '&message' error conditions have an i18n'd message.
|
||||||
(leave (_ "~a~%")
|
(leave (_ "~a~%")
|
||||||
|
|
|
@ -570,6 +570,15 @@
|
||||||
|
|
||||||
(test-skip (if (%guile-for-build) 0 8))
|
(test-skip (if (%guile-for-build) 0 8))
|
||||||
|
|
||||||
|
(test-equal "build-expression->derivation and invalid module name"
|
||||||
|
'(file-search-error "guix/module/that/does/not/exist.scm")
|
||||||
|
(guard (c ((file-search-error? c)
|
||||||
|
(list 'file-search-error
|
||||||
|
(file-search-error-file-name c))))
|
||||||
|
(build-expression->derivation %store "foo" #t
|
||||||
|
#:modules '((guix module that
|
||||||
|
does not exist)))))
|
||||||
|
|
||||||
(test-assert "build-expression->derivation and derivation-prerequisites"
|
(test-assert "build-expression->derivation and derivation-prerequisites"
|
||||||
(let ((drv (build-expression->derivation %store "fail" #f)))
|
(let ((drv (build-expression->derivation %store "fail" #f)))
|
||||||
(any (match-lambda
|
(any (match-lambda
|
||||||
|
|
Loading…
Reference in New Issue