summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-11-05 14:32:04 +0100
committerLudovic Courtès <ludo@gnu.org>2020-11-05 16:13:50 +0100
commit18fc84bce86eedb85d44a8708a9a5ef7c1b23da5 (patch)
treea197fec5851a732439e91476cdc1efef101ed42d
parent61d9c4458eef35a2a3fce94f113031d86b9f4d8d (diff)
gexp: Store the source code location in <gexp>.
* guix/gexp.scm (<gexp>)[location]: New field. (gexp-location): New procedure. (write-gexp): Print the location of GEXP. (gexp->derivation): Adjust call to 'make-gexp'. (gexp): Likewise.
-rw-r--r--guix/gexp.scm20
-rw-r--r--tests/gexp.scm2
2 files changed, 17 insertions, 5 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 9339b226b7f..97a6101868d 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -146,12 +146,17 @@
146 146
147;; "G expressions". 147;; "G expressions".
148(define-record-type <gexp> 148(define-record-type <gexp>
149 (make-gexp references modules extensions proc) 149 (make-gexp references modules extensions proc location)
150 gexp? 150 gexp?
151 (references gexp-references) ;list of <gexp-input> 151 (references gexp-references) ;list of <gexp-input>
152 (modules gexp-self-modules) ;list of module names 152 (modules gexp-self-modules) ;list of module names
153 (extensions gexp-self-extensions) ;list of lowerable things 153 (extensions gexp-self-extensions) ;list of lowerable things
154 (proc gexp-proc)) ;procedure 154 (proc gexp-proc) ;procedure
155 (location %gexp-location)) ;location alist
156
157(define (gexp-location gexp)
158 "Return the source code location of GEXP."
159 (and=> (%gexp-location gexp) source-properties->location))
155 160
156(define (write-gexp gexp port) 161(define (write-gexp gexp port)
157 "Write GEXP on PORT." 162 "Write GEXP on PORT."
@@ -164,6 +169,11 @@
164 (write (apply (gexp-proc gexp) 169 (write (apply (gexp-proc gexp)
165 (gexp-references gexp)) 170 (gexp-references gexp))
166 port)) 171 port))
172
173 (let ((loc (gexp-location gexp)))
174 (when loc
175 (format port " ~a" (location->string loc))))
176
167 (format port " ~a>" 177 (format port " ~a>"
168 (number->string (object-address gexp) 16))) 178 (number->string (object-address gexp) 16)))
169 179
@@ -1084,7 +1094,8 @@ The other arguments are as for 'derivation'."
1084 (make-gexp (gexp-references exp) 1094 (make-gexp (gexp-references exp)
1085 (append modules (gexp-self-modules exp)) 1095 (append modules (gexp-self-modules exp))
1086 (gexp-self-extensions exp) 1096 (gexp-self-extensions exp)
1087 (gexp-proc exp)))) 1097 (gexp-proc exp)
1098 (gexp-location exp))))
1088 1099
1089 (mlet* %store-monad ( ;; The following binding forces '%current-system' and 1100 (mlet* %store-monad ( ;; The following binding forces '%current-system' and
1090 ;; '%current-target-system' to be looked up at >>= 1101 ;; '%current-target-system' to be looked up at >>=
@@ -1414,7 +1425,8 @@ execution environment."
1414 current-imported-modules 1425 current-imported-modules
1415 current-imported-extensions 1426 current-imported-extensions
1416 (lambda #,formals 1427 (lambda #,formals
1417 #,sexp))))))) 1428 #,sexp)
1429 (current-source-location)))))))
1418 1430
1419 1431
1420;;; 1432;;;
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 1beeb67c212..0487f2a96d1 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -1413,7 +1413,7 @@
1413 1413
1414(test-assert "printer" 1414(test-assert "printer"
1415 (string-match "^#<gexp \\(string-append .*#<package coreutils.*\ 1415 (string-match "^#<gexp \\(string-append .*#<package coreutils.*\
1416 \"/bin/uname\"\\) [[:xdigit:]]+>$" 1416 \"/bin/uname\"\\) [[:graph:]]+tests/gexp\\.scm:[0-9]+:[0-9]+ [[:xdigit:]]+>$"
1417 (with-output-to-string 1417 (with-output-to-string
1418 (lambda () 1418 (lambda ()
1419 (write 1419 (write