Skip to content

Commit

Permalink
Merge pull request #254 from purcell/compat-support
Browse files Browse the repository at this point in the history
Add support for functions provided by the compat package
  • Loading branch information
purcell authored Nov 3, 2023
2 parents ee6b670 + 5713222 commit 09ce884
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 22 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
strategy:
matrix:
emacs_version:
- 24.1
- 24.2
- 24.3
- 24.4
- 24.5
- 25.1
Expand All @@ -35,10 +32,6 @@ jobs:
include:
- emacs_version: snapshot
experimental: true
- emacs_version: 24.1
lint_ignore: 1
- emacs_version: 24.2
lint_ignore: 1
env:
EMACS_LINT_IGNORE: ${{ matrix.lint_ignore }}
steps:
Expand Down
40 changes: 36 additions & 4 deletions package-lint-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,12 @@ headers and provide form."
(package-lint-test--run ";; Package-Requires: ((example-nonexistent-package \"1\"))"))))

(ert-deftest package-lint-test-warn-snapshot-dep ()
(package-lint-test-add-package-lint-foobar-to-archive '(0 5 0))
(package-lint-test-add-package-lint-foobar-to-archive '(20180101 0 0))
(should
(equal
'((6 23 warning "Use a non-snapshot version number for dependency on \"package-lint\" if possible."))
(package-lint-test--run ";; Package-Requires: ((package-lint \"20160101.1234\"))"))))
'((6 23 warning "Use a non-snapshot version number for dependency on \"package-lint-foobar\" if possible."))
(package-lint-test--run ";; Package-Requires: ((package-lint-foobar \"20160101.1234\"))"))))

(ert-deftest package-lint-test-warn-unversioned-dep ()
(should
Expand Down Expand Up @@ -370,9 +372,9 @@ Alternatively, depend on (emacs \"24.3\") or greater, in which cl-lib is bundled
(ert-deftest package-lint-test-error-new-functions ()
(should
(equal
'((6 1 error "You should depend on (emacs \"25.1\") if you need `when-let'."))
'((6 1 error "You should depend on (emacs \"24.1\") if you need `window-resize'."))
(package-lint-test--run
"(when-let ((foo (bar))) (message \"ok\"))"))))
"(window-resize foobar)"))))

(ert-deftest package-lint-test-error-new-functions-as-quote ()
(should
Expand Down Expand Up @@ -454,6 +456,36 @@ Alternatively, depend on (emacs \"24.3\") or greater, in which cl-lib is bundled
";; Package-Requires: ((seq \"1\"))
\(seq-length '(foo))"))))

(ert-deftest package-lint-test-error-new-compat-functions ()
(should
(equal
'((6 1 error "You should depend on (emacs \"27.1\") or the compat package if you need `proper-list-p'."))
(package-lint-test--run
"(proper-list-p '(foo))"))))

(ert-deftest package-lint-test-accepts-new-functions-with-compat ()
(should
(equal
'()
(package-lint-test--run
";; Package-Requires: ((compat \"29\"))
\(proper-list-p '(foo))"))))

(ert-deftest package-lint-test-error-new-compat-macros ()
(should
(equal
'((6 1 error "You should depend on (emacs \"27.1\") or the compat package if you need `with-suppressed-warnings'."))
(package-lint-test--run
"(with-suppressed-warnings (foo))"))))

(ert-deftest package-lint-test-accepts-new-macros-with-compat ()
(should
(equal
'()
(package-lint-test--run
";; Package-Requires: ((compat \"29\"))
\(with-suppressed-warnings (foo))"))))

(ert-deftest package-lint-test-error-nonstandard-symbol-separator ()
(should
(equal
Expand Down
49 changes: 39 additions & 10 deletions package-lint.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; URL: https://github.com/purcell/package-lint
;; Keywords: lisp
;; Version: 0.19
;; Package-Requires: ((cl-lib "0.5") (emacs "24.1") (let-alist "1.0.6"))
;; Package-Requires: ((cl-lib "0.5") (emacs "24.4") (let-alist "1.0.6") (compat "29.1"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -172,6 +172,30 @@ symbol such as `variable-added'.")
(let-alist (package-lint-symbol-info sym)
(or .function-added .function-removed)))

(defconst package-lint--supported-symbols
(let (symbols functions)
(dolist (ver '(25 26 27 28 29))
(let ((el-path (locate-library (format "compat-%d.el" ver) t)))
(unless el-path
(error "compat package not installed"))
(with-temp-buffer
(insert-file-contents el-path)
(goto-char (point-min))
;; TODO convert to rx
(while (search-forward-regexp "^(compat-\\(defun\\|defmacro\\|\\defvar\\) +\\_<\\(.*?\\)\\_>" nil t)
(pcase (match-string 1)
("defvar" (push (intern (match-string 2)) symbols))
((or "defun" "defmacro") (push (intern (match-string 2)) functions)))))))
(cons symbols functions))
"A cons cell of (VARS . FUNCTIONS) supported by \"compat\".")

(defun package-lint--supported-by-compat (type sym)
"Return non-nil if SYM is supported by the \"compat\" package.
TYPE is `function' or `variable'."
(memq sym (pcase type
(`function (cdr package-lint--supported-symbols))
(_ nil))))

(defconst package-lint--sane-prefixes
(rx
string-start
Expand Down Expand Up @@ -636,17 +660,21 @@ type of the symbol, either FUNCTION or FEATURE."
(available-backport (car available-backport-with-ver))
(required-backport-version (cadr available-backport-with-ver))
(matching-dep (when available-backport
(assoc available-backport valid-deps))))
(unless (or (and matching-dep
(or (not required-backport-version)
(version-list-<= (version-to-list required-backport-version)
(cadr matching-dep))))
(and (eq type 'function)
(or (package-lint--seen-fboundp-check-for sym)
(package-lint--is-a-let-binding))))
(assoc available-backport valid-deps)))
(compat-support (package-lint--supported-by-compat type (intern sym)))
(compat-in-deps (assoc 'compat valid-deps)))
(unless (or
(and compat-support compat-in-deps)
(and matching-dep
(or (not required-backport-version)
(version-list-<= (version-to-list required-backport-version)
(cadr matching-dep))))
(and (eq type 'function)
(or (package-lint--seen-fboundp-check-for sym)
(package-lint--is-a-let-binding))))
(list
'error
(format "You should depend on (emacs \"%s\")%s if you need `%s'."
(format "You should depend on (emacs \"%s\")%s%s if you need `%s'."
(mapconcat #'number-to-string added-in-version ".")
(if available-backport
(format " or the %s package"
Expand All @@ -656,6 +684,7 @@ type of the symbol, either FUNCTION or FEATURE."
required-backport-version)
available-backport))
"")
(if compat-support " or the compat package" "")
sym)))))))))))

(defun package-lint--check-eval-after-load ()
Expand Down
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

EMACS="${EMACS:=emacs}"

NEEDED_PACKAGES="cl-lib let-alist"
NEEDED_PACKAGES="cl-lib let-alist compat"

INIT_PACKAGE_EL="(progn \
(require 'package) \
Expand Down

0 comments on commit 09ce884

Please sign in to comment.