summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-03-22 15:00:53 +0100
committerLudovic Courtès <ludo@gnu.org>2016-03-23 00:23:12 +0100
commitd26e19671e2a50a25d37357aba301bef5df1818e (patch)
tree4b3c6fd70004e12d7ffb2acc5c137cf72dbe4bf5
parent6985335faaa23965887b62ce8123f8f12e352bd5 (diff)
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.
-rw-r--r--guix/derivations.scm18
-rw-r--r--guix/gexp.scm5
-rw-r--r--guix/ui.scm5
-rw-r--r--tests/derivations.scm9
4 files changed, 31 insertions, 6 deletions
diff --git a/guix/derivations.scm b/guix/derivations.scm
index 2af65b1dc03..2d8584e72d3 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -90,7 +90,11 @@
90 build-derivations 90 build-derivations
91 built-derivations 91 built-derivations
92 92
93 file-search-error?
94 file-search-error-file-name
95 file-search-error-search-path
93 96
97 search-path*
94 module->source-file-name 98 module->source-file-name
95 build-expression->derivation) 99 build-expression->derivation)
96 100
@@ -1036,10 +1040,22 @@ system, imported, and appears under FINAL-PATH in the resulting store path."
1036 #:guile-for-build guile 1040 #:guile-for-build guile
1037 #:local-build? #t))) 1041 #:local-build? #t)))
1038 1042
1043;; The "file not found" error condition.
1044(define-condition-type &file-search-error &error
1045 file-search-error?
1046 (file file-search-error-file-name)
1047 (path file-search-error-search-path))
1048
1039(define search-path* 1049(define search-path*
1040 ;; A memoizing version of 'search-path' so 'imported-modules' does not end 1050 ;; A memoizing version of 'search-path' so 'imported-modules' does not end
1041 ;; up looking for the same files over and over again. 1051 ;; up looking for the same files over and over again.
1042 (memoize search-path)) 1052 (memoize (lambda (path file)
1053 "Search for FILE in PATH and memoize the result. Raise a
1054'&file-search-error' condition if it could not be found."
1055 (or (search-path path file)
1056 (raise (condition
1057 (&file-search-error (file file)
1058 (path path))))))))
1043 1059
1044(define (module->source-file-name module) 1060(define (module->source-file-name module)
1045 "Return the file name corresponding to MODULE, a Guile module name (a list 1061 "Return the file name corresponding to MODULE, a Guile module name (a list
diff --git a/guix/gexp.scm b/guix/gexp.scm
index c408c94c439..b4d737ecaee 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -902,11 +902,6 @@ system, imported, and appears under FINAL-PATH in the resulting store path."
902 #:guile-for-build guile 902 #:guile-for-build guile
903 #:local-build? #t))) 903 #:local-build? #t)))
904 904
905(define search-path*
906 ;; A memoizing version of 'search-path' so 'imported-modules' does not end
907 ;; up looking for the same files over and over again.
908 (memoize search-path))
909
910(define* (imported-modules modules 905(define* (imported-modules modules
911 #:key (name "module-import") 906 #:key (name "module-import")
912 (system (%current-system)) 907 (system (%current-system))
diff --git a/guix/ui.scm b/guix/ui.scm
index 7b7bee0ac81..3b1887ccbf1 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -461,6 +461,11 @@ interpreted."
461 (leave (_ "reference to invalid output '~a' of derivation '~a'~%") 461 (leave (_ "reference to invalid output '~a' of derivation '~a'~%")
462 (derivation-missing-output c) 462 (derivation-missing-output c)
463 (derivation-file-name (derivation-error-derivation c)))) 463 (derivation-file-name (derivation-error-derivation c))))
464 ((file-search-error? c)
465 (leave (_ "file '~a' could not be found in these \
466directories:~{ ~a~}~%")
467 (file-search-error-file-name c)
468 (file-search-error-search-path c)))
464 ((message-condition? c) 469 ((message-condition? c)
465 ;; Normally '&message' error conditions have an i18n'd message. 470 ;; Normally '&message' error conditions have an i18n'd message.
466 (leave (_ "~a~%") 471 (leave (_ "~a~%")
diff --git a/tests/derivations.scm b/tests/derivations.scm
index 4d3b82fe1a6..a52142e0f1d 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -570,6 +570,15 @@
570 570
571(test-skip (if (%guile-for-build) 0 8)) 571(test-skip (if (%guile-for-build) 0 8))
572 572
573(test-equal "build-expression->derivation and invalid module name"
574 '(file-search-error "guix/module/that/does/not/exist.scm")
575 (guard (c ((file-search-error? c)
576 (list 'file-search-error
577 (file-search-error-file-name c))))
578 (build-expression->derivation %store "foo" #t
579 #:modules '((guix module that
580 does not exist)))))
581
573(test-assert "build-expression->derivation and derivation-prerequisites" 582(test-assert "build-expression->derivation and derivation-prerequisites"
574 (let ((drv (build-expression->derivation %store "fail" #f))) 583 (let ((drv (build-expression->derivation %store "fail" #f)))
575 (any (match-lambda 584 (any (match-lambda