aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-06-19 22:15:15 +0200
committerLudovic Courtès <ludo@gnu.org>2016-06-20 00:52:53 +0200
commitcbbbb7be0fbaa11ff75bce92f2d82131ff8db104 (patch)
tree624a1f1ea19932bcc61641a4ea20870efc765afc
parent95fa173ed12b832315d119d635b85813bb5317bd (diff)
downloadpatches-cbbbb7be0fbaa11ff75bce92f2d82131ff8db104.tar
patches-cbbbb7be0fbaa11ff75bce92f2d82131ff8db104.tar.gz
utils: 'current-source-directory' resolves relative file names at run time.
* guix/utils.scm (absolute-dirname): New procedure. (current-source-directory): Emit code to use it instead of calling 'search-path'.
-rw-r--r--guix/utils.scm20
1 files changed, 17 insertions, 3 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index a642bd3d62..0e20be3c18 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -702,6 +702,18 @@ output port, and PROC's result is returned."
;;; Source location.
;;;
+(define (absolute-dirname file)
+ "Return the absolute name of the directory containing FILE, or #f upon
+failure."
+ (match (search-path %load-path file)
+ (#f #f)
+ ((? string? file)
+ ;; If there are relative names in %LOAD-PATH, FILE can be relative and
+ ;; needs to be canonicalized.
+ (if (string-prefix? "/" file)
+ (dirname file)
+ (canonicalize-path (dirname file))))))
+
(define-syntax current-source-directory
(lambda (s)
"Return the absolute name of the current directory, or #f if it could not
@@ -711,11 +723,13 @@ be determined."
(match (assq 'filename (syntax-source s))
(('filename . (? string? file-name))
;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
- ;; can be relative. In that case, we try to find out the absolute
- ;; file name by looking at %LOAD-PATH.
+ ;; can be relative. In that case, we try to find out at run time
+ ;; the absolute file name by looking at %LOAD-PATH; doing this at
+ ;; run time rather than expansion time is necessary to allow files
+ ;; to be moved on the file system.
(if (string-prefix? "/" file-name)
(dirname file-name)
- (and=> (search-path %load-path file-name) dirname)))
+ #`(absolute-dirname #,file-name)))
(_
#f))))))