1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix deprecation)
20 #:use-module (guix i18n)
21 #:use-module (ice-9 format)
22 #:export (define-deprecated
23 define-deprecated/alias
24 deprecation-warning-port))
28 ;;; Provide a mechanism to mark bindings as deprecated.
30 ;;; We don't reuse (guix ui) mostly to avoid pulling in too many things.
34 (define deprecation-warning-port
35 ;; Port where deprecation warnings go.
36 (make-parameter (current-error-port)))
38 (define (source-properties->location-string properties)
39 "Return a human-friendly, GNU-standard representation of PROPERTIES, a
40 source property alist."
41 (let ((file (assq-ref properties 'filename))
42 (line (assq-ref properties 'line))
43 (column (assq-ref properties 'column)))
44 (if (and file line column)
45 (format #f "~a:~a:~a" file (+ 1 line) column)
46 (G_ "<unknown location>"))))
48 (define* (warn-about-deprecation variable properties
50 (format (deprecation-warning-port)
51 (G_ "~a: warning: '~a' is deprecated~@[, use '~a' instead~]~%")
52 (source-properties->location-string properties)
53 variable replacement))
55 (define-syntax define-deprecated
57 "Define a deprecated variable or procedure, along these lines:
59 (define-deprecated foo bar 42)
60 (define-deprecated (baz x y) qux (qux y x))
62 This will write a deprecation warning to DEPRECATION-WARNING-PORT."
64 ((_ (proc formals ...) replacement body ...)
65 #'(define-deprecated proc replacement
66 (lambda* (formals ...) body ...)))
67 ((_ variable replacement exp)
68 (identifier? #'variable)
69 (with-syntax ((real (datum->syntax
72 (syntax->datum #'variable)
77 (lambda () replacement) ;just to ensure it's bound
80 (define-syntax variable
82 (warn-about-deprecation 'variable (syntax-source s)
83 #:replacement 'replacement)
86 #'(real args (... ...)))
91 (define-syntax-rule (define-deprecated/alias deprecated replacement)
92 "Define as an alias a deprecated variable, procedure, or macro, along
95 (define-deprecated/alias nix-server? store-connection?)
97 where 'nix-server?' is the deprecated name for 'store-connection?'.
99 This will write a deprecation warning to DEPRECATION-WARNING-PORT."
100 (define-syntax deprecated
102 (warn-about-deprecation 'deprecated (syntax-source s)
103 #:replacement 'replacement)
106 #'(replacement args (... ...)))