deprecation: Use the 'warning' procedure for diagnostics.

Until now, (guix deprecation) had its own warning mechanism, which was
inconsistent (it did not use colors, etc.)

* guix/deprecation.scm (deprecation-warning-port): Remove
(source-properties->location-string): Remove.
(warn-about-deprecation): Use 'warning' instead of 'format'.
(define-deprecated, define-deprecated/alias): Adjust docstring.
* guix/channels.scm (build-from-source): Refer to 'guix-warning-port'
instead of 'deprecation-warning-port'.
This commit is contained in:
Ludovic Courtès 2019-06-03 23:00:42 +02:00
parent 1b5ee3bdaa
commit 69962ab7a8
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 13 additions and 27 deletions

View File

@ -27,7 +27,7 @@
#:use-module (guix profiles) #:use-module (guix profiles)
#:use-module (guix derivations) #:use-module (guix derivations)
#:use-module (guix combinators) #:use-module (guix combinators)
#:use-module (guix deprecation) #:use-module (guix diagnostics)
#:use-module (guix store) #:use-module (guix store)
#:use-module (guix i18n) #:use-module (guix i18n)
#:use-module ((guix utils) #:use-module ((guix utils)
@ -280,7 +280,7 @@ package modules under SOURCE using CORE, an instance of Guix."
;; Disable deprecation warnings; it's OK for SCRIPT to ;; Disable deprecation warnings; it's OK for SCRIPT to
;; use deprecated APIs and the user doesn't have to know ;; use deprecated APIs and the user doesn't have to know
;; about it. ;; about it.
(parameterize ((deprecation-warning-port (parameterize ((guix-warning-port
(%make-void-port "w"))) (%make-void-port "w")))
(primitive-load script)))))) (primitive-load script))))))
;; BUILD must be a monadic procedure of at least one argument: the ;; BUILD must be a monadic procedure of at least one argument: the

View File

@ -18,40 +18,26 @@
(define-module (guix deprecation) (define-module (guix deprecation)
#:use-module (guix i18n) #:use-module (guix i18n)
#:use-module (ice-9 format) #:use-module (guix diagnostics)
#:autoload (guix utils) (source-properties->location)
#:export (define-deprecated #:export (define-deprecated
define-deprecated/alias define-deprecated/alias
warn-about-deprecation warn-about-deprecation))
deprecation-warning-port))
;;; Commentary: ;;; Commentary:
;;; ;;;
;;; Provide a mechanism to mark bindings as deprecated. ;;; Provide a mechanism to mark bindings as deprecated.
;;; ;;;
;;; We don't reuse (guix ui) mostly to avoid pulling in too many things.
;;;
;;; Code: ;;; Code:
(define deprecation-warning-port
;; Port where deprecation warnings go.
(make-parameter (current-error-port)))
(define (source-properties->location-string properties)
"Return a human-friendly, GNU-standard representation of PROPERTIES, a
source property alist."
(let ((file (assq-ref properties 'filename))
(line (assq-ref properties 'line))
(column (assq-ref properties 'column)))
(if (and file line column)
(format #f "~a:~a:~a" file (+ 1 line) column)
(G_ "<unknown location>"))))
(define* (warn-about-deprecation variable properties (define* (warn-about-deprecation variable properties
#:key replacement) #:key replacement)
(format (deprecation-warning-port) (let ((location (and properties (source-properties->location properties))))
(G_ "~a: warning: '~a' is deprecated~@[, use '~a' instead~]~%") (if replacement
(source-properties->location-string properties) (warning location (G_ "'~a' is deprecated, use '~a' instead~%")
variable replacement)) variable replacement)
(warning location (G_ "'~a' is deprecated~%")
variable))))
(define-syntax define-deprecated (define-syntax define-deprecated
(lambda (s) (lambda (s)
@ -60,7 +46,7 @@ source property alist."
(define-deprecated foo bar 42) (define-deprecated foo bar 42)
(define-deprecated (baz x y) qux (qux y x)) (define-deprecated (baz x y) qux (qux y x))
This will write a deprecation warning to DEPRECATION-WARNING-PORT." This will write a deprecation warning to GUIX-WARNING-PORT."
(syntax-case s () (syntax-case s ()
((_ (proc formals ...) replacement body ...) ((_ (proc formals ...) replacement body ...)
#'(define-deprecated proc replacement #'(define-deprecated proc replacement
@ -97,7 +83,7 @@ these lines:
where 'nix-server?' is the deprecated name for 'store-connection?'. where 'nix-server?' is the deprecated name for 'store-connection?'.
This will write a deprecation warning to DEPRECATION-WARNING-PORT." This will write a deprecation warning to GUIX-WARNING-PORT."
(define-syntax deprecated (define-syntax deprecated
(lambda (s) (lambda (s)
(warn-about-deprecation 'deprecated (syntax-source s) (warn-about-deprecation 'deprecated (syntax-source s)