summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix/packages.scm38
1 files changed, 34 insertions, 4 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index c825f427d88..01de50ebd73 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -360,6 +360,30 @@ name of its URI."
360 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-03/msg00790.html>. 360 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-03/msg00790.html>.
361 (fold delete %supported-systems '("mips64el-linux"))) 361 (fold delete %supported-systems '("mips64el-linux")))
362 362
363(define-syntax current-location-vector
364 (lambda (s)
365 "Like 'current-source-location' but expand to a literal vector with
366one-indexed line numbers."
367 ;; Storing a literal vector in .go files is more efficient than storing an
368 ;; alist: less initialization code, fewer relocations, etc.
369 (syntax-case s ()
370 ((_)
371 (match (syntax-source s)
372 (#f #f)
373 (properties
374 (let ((file (assq-ref properties 'filename))
375 (line (assq-ref properties 'line))
376 (column (assq-ref properties 'column)))
377 (and file line column
378 #`#(#,file #,(+ 1 line) #,column)))))))))
379
380(define-inlinable (sanitize-location loc)
381 ;; Convert LOC to a vector or to #f.
382 (cond ((vector? loc) loc)
383 ((not loc) loc)
384 (else (vector (location-file loc)
385 (location-line loc)
386 (location-column loc)))))
363 387
364;; A package. 388;; A package.
365(define-record-type* <package> 389(define-record-type* <package>
@@ -404,10 +428,9 @@ name of its URI."
404 428
405 (properties package-properties (default '())) ; alist for anything else 429 (properties package-properties (default '())) ; alist for anything else
406 430
407 (location package-location 431 (location package-location-vector
408 (default (and=> (current-source-location) 432 (default (current-location-vector))
409 source-properties->location)) 433 (innate) (sanitize sanitize-location)))
410 (innate)))
411 434
412(set-record-type-printer! <package> 435(set-record-type-printer! <package>
413 (lambda (package port) 436 (lambda (package port)
@@ -425,6 +448,13 @@ name of its URI."
425 package) 448 package)
426 16))))) 449 16)))))
427 450
451(define (package-location package)
452 "Return the source code location of PACKAGE as a <location> record, or #f if
453it is not known."
454 (match (package-location-vector package)
455 (#f #f)
456 (#(file line column) (location file line column))))
457
428(define-syntax-rule (package/inherit p overrides ...) 458(define-syntax-rule (package/inherit p overrides ...)
429 "Like (package (inherit P) OVERRIDES ...), except that the same 459 "Like (package (inherit P) OVERRIDES ...), except that the same
430transformation is done to the package P's replacement, if any. P must be a bare 460transformation is done to the package P's replacement, if any. P must be a bare