summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 2d8bfd84b0..19fd0b0844 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -53,6 +53,8 @@
substitute-keyword-arguments
ensure-keyword-arguments
+ current-source-directory
+
<location>
location
location?
@@ -700,6 +702,19 @@ output port, and PROC's result is returned."
;;; Source location.
;;;
+(define (extract-directory properties)
+ "Extract the directory name from source location PROPERTIES."
+ (match (assq 'filename properties)
+ (('filename . (? string? file-name))
+ (dirname file-name))
+ (_
+ #f)))
+
+(define-syntax-rule (current-source-directory)
+ "Expand to the directory of the current source file or #f if it could not
+be determined."
+ (extract-directory (current-source-location)))
+
;; A source location.
(define-record-type <location>
(make-location file line column)