deprecation.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
  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. (define-module (guix deprecation)
  20. #:use-module (guix i18n)
  21. #:use-module (guix diagnostics)
  22. #:autoload (guix utils) (source-properties->location)
  23. #:export (define-deprecated
  24. define-deprecated/public
  25. define-deprecated/alias
  26. define-deprecated/public-alias
  27. warn-about-old-daemon
  28. warn-about-deprecation))
  29. ;;; Commentary:
  30. ;;;
  31. ;;; Provide a mechanism to mark bindings as deprecated.
  32. ;;;
  33. ;;; Code:
  34. (define (warn-about-old-daemon)
  35. (warning (G_ "Your Guix daemon is severely outdated, and will soon cease to
  36. be able to download binary substitutes. To upgrade it, refer to the
  37. 'Upgrading Guix' section in the manual.~%")))
  38. (define* (warn-about-deprecation variable properties
  39. #:key replacement)
  40. (let ((location (and properties (source-properties->location properties))))
  41. (if replacement
  42. (warning location (G_ "'~a' is deprecated, use '~a' instead~%")
  43. variable replacement)
  44. (warning location (G_ "'~a' is deprecated~%")
  45. variable))))
  46. (define-syntax public (syntax-rules ())) ;private syntactic keyword
  47. (define-syntax define-deprecated
  48. (lambda (s)
  49. "Define a deprecated variable or procedure, along these lines:
  50. (define-deprecated foo bar 42)
  51. (define-deprecated old new)
  52. (define-deprecated (baz x y) qux (qux y x))
  53. This will write a deprecation warning to GUIX-WARNING-PORT."
  54. (syntax-case s ()
  55. ((_ (proc formals ...) replacement body ...)
  56. #'(define-deprecated proc replacement
  57. (lambda* (formals ...) body ...)))
  58. ((_ variable replacement exp)
  59. #'(define-deprecated private variable replacement exp))
  60. ((_ visibility variable replacement exp)
  61. (identifier? #'variable)
  62. (with-syntax ((real (datum->syntax
  63. #'variable
  64. (symbol-append '%
  65. (syntax->datum #'variable)
  66. '/deprecated))))
  67. #`(begin
  68. (define real
  69. (begin
  70. (lambda () replacement) ;just to ensure it's bound
  71. exp))
  72. (define-syntax variable
  73. (lambda (s)
  74. (warn-about-deprecation 'variable (syntax-source s)
  75. #:replacement 'replacement)
  76. (syntax-case s ()
  77. ((_ args (... ...))
  78. #'(real args (... ...)))
  79. (id
  80. (identifier? #'id)
  81. #'real))))
  82. ;; When asking for public visibility, export both REAL and
  83. ;; VARIABLE. Exporting REAL is useful when defining deprecated
  84. ;; packages: there must be a public variable bound to a package
  85. ;; so that the (guix discover) machinery finds it.
  86. #,(if (free-identifier=? #'visibility #'public)
  87. #'(export real variable)
  88. #'(begin)))))
  89. ((_ variable alias)
  90. (identifier? #'alias)
  91. #'(define-deprecated variable alias alias)))))
  92. (define-syntax-rule (define-deprecated/public body ...)
  93. "Like 'define/deprecated', but export all the newly introduced bindings."
  94. (define-deprecated public body ...))
  95. (define-syntax-rule (define-deprecated/alias deprecated replacement)
  96. "Define as an alias a deprecated variable, procedure, or macro, along
  97. these lines:
  98. (define-deprecated/alias nix-server? store-connection?)
  99. where 'nix-server?' is the deprecated name for 'store-connection?'.
  100. This will write a deprecation warning to GUIX-WARNING-PORT."
  101. (define-syntax deprecated
  102. (lambda (s)
  103. (warn-about-deprecation 'deprecated (syntax-source s)
  104. #:replacement 'replacement)
  105. (syntax-case s ()
  106. ((_ args (... ...))
  107. #'(replacement args (... ...)))
  108. (id
  109. (identifier? #'id)
  110. #'replacement)))))
  111. (define-syntax-rule (define-deprecated/public-alias deprecated replacement)
  112. "Like define-deprecated/alias, but exporting DEPRECATED.
  113. It is assumed, that REPLACEMENT is already public."
  114. (begin
  115. (define-deprecated/alias deprecated replacement)
  116. (export deprecated)))