gnu: python-tempora: Switch to pyproject-build-system.
[jackhill/guix/guix.git] / guix / deprecation.scm
CommitLineData
787da810 1;;; GNU Guix --- Functional package management for GNU
f8ae824c 2;;; Copyright © 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
f9c62b23 3;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
787da810
LC
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (guix deprecation)
21 #:use-module (guix i18n)
69962ab7
LC
22 #:use-module (guix diagnostics)
23 #:autoload (guix utils) (source-properties->location)
787da810 24 #:export (define-deprecated
f8ae824c
LC
25
26 define-deprecated/public
1b7dd997 27 define-deprecated/alias
9ab158a4 28 define-deprecated/public-alias
f9c62b23
MO
29
30 warn-about-old-daemon
69962ab7 31 warn-about-deprecation))
787da810
LC
32
33;;; Commentary:
34;;;
35;;; Provide a mechanism to mark bindings as deprecated.
36;;;
787da810
LC
37;;; Code:
38
f9c62b23 39(define (warn-about-old-daemon)
96d7535b
MC
40 (warning (G_ "Your Guix daemon is severely outdated, and will soon cease to
41be able to download binary substitutes. To upgrade it, refer to the
42'Upgrading Guix' section in the manual.~%")))
f9c62b23 43
787da810
LC
44(define* (warn-about-deprecation variable properties
45 #:key replacement)
69962ab7
LC
46 (let ((location (and properties (source-properties->location properties))))
47 (if replacement
48 (warning location (G_ "'~a' is deprecated, use '~a' instead~%")
49 variable replacement)
50 (warning location (G_ "'~a' is deprecated~%")
51 variable))))
787da810 52
f8ae824c
LC
53(define-syntax public (syntax-rules ())) ;private syntactic keyword
54
787da810
LC
55(define-syntax define-deprecated
56 (lambda (s)
57 "Define a deprecated variable or procedure, along these lines:
58
59 (define-deprecated foo bar 42)
6e36f1ca 60 (define-deprecated old new)
787da810
LC
61 (define-deprecated (baz x y) qux (qux y x))
62
69962ab7 63This will write a deprecation warning to GUIX-WARNING-PORT."
787da810
LC
64 (syntax-case s ()
65 ((_ (proc formals ...) replacement body ...)
66 #'(define-deprecated proc replacement
67 (lambda* (formals ...) body ...)))
68 ((_ variable replacement exp)
f8ae824c
LC
69 #'(define-deprecated private variable replacement exp))
70 ((_ visibility variable replacement exp)
787da810
LC
71 (identifier? #'variable)
72 (with-syntax ((real (datum->syntax
73 #'variable
74 (symbol-append '%
75 (syntax->datum #'variable)
76 '/deprecated))))
77 #`(begin
78 (define real
79 (begin
80 (lambda () replacement) ;just to ensure it's bound
81 exp))
82
83 (define-syntax variable
84 (lambda (s)
85 (warn-about-deprecation 'variable (syntax-source s)
86 #:replacement 'replacement)
87 (syntax-case s ()
88 ((_ args (... ...))
89 #'(real args (... ...)))
90 (id
91 (identifier? #'id)
f8ae824c
LC
92 #'real))))
93
94 ;; When asking for public visibility, export both REAL and
95 ;; VARIABLE. Exporting REAL is useful when defining deprecated
96 ;; packages: there must be a public variable bound to a package
97 ;; so that the (guix discover) machinery finds it.
98 #,(if (free-identifier=? #'visibility #'public)
99 #'(export real variable)
100 #'(begin)))))
6e36f1ca
LC
101 ((_ variable alias)
102 (identifier? #'alias)
103 #'(define-deprecated variable alias alias)))))
1b7dd997 104
f8ae824c
LC
105(define-syntax-rule (define-deprecated/public body ...)
106 "Like 'define/deprecated', but export all the newly introduced bindings."
107 (define-deprecated public body ...))
108
1b7dd997
LC
109(define-syntax-rule (define-deprecated/alias deprecated replacement)
110 "Define as an alias a deprecated variable, procedure, or macro, along
111these lines:
112
113 (define-deprecated/alias nix-server? store-connection?)
114
115where 'nix-server?' is the deprecated name for 'store-connection?'.
116
69962ab7 117This will write a deprecation warning to GUIX-WARNING-PORT."
1b7dd997
LC
118 (define-syntax deprecated
119 (lambda (s)
120 (warn-about-deprecation 'deprecated (syntax-source s)
121 #:replacement 'replacement)
122 (syntax-case s ()
123 ((_ args (... ...))
124 #'(replacement args (... ...)))
125 (id
126 (identifier? #'id)
127 #'replacement)))))
9ab158a4
LMP
128
129(define-syntax-rule (define-deprecated/public-alias deprecated replacement)
130 "Like define-deprecated/alias, but exporting DEPRECATED.
131It is assumed, that REPLACEMENT is already public."
132 (begin
133 (define-deprecated/alias deprecated replacement)
134 (export deprecated)))