deprecation.scm 4.7 KB

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