public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Ulrich Müller" <ulm@gentoo.org>
To: <gentoo-dev@lists.gentoo.org>
Subject: [gentoo-dev] [PATCH v2 1/3] elisp-common.eclass: New function elisp-check-emacs-version.
Date: Fri, 20 Dec 2019 14:43:45 +0100	[thread overview]
Message-ID: <w6go8w3nmcu.fsf@kph.uni-mainz.de> (raw)
In-Reply-To: <cover.1576663643.git.ulm@gentoo.org> ("Ulrich \=\?utf-8\?Q\?M\?\= \=\?utf-8\?Q\?\=C3\=BCller\=22's\?\= message of "Wed, 18 Dec 2019 12:08:16 +0100")

[-- Attachment #1: Type: text/plain, Size: 3866 bytes --]

Tests if the Emacs version is at least the (full) version specified
by NEED_EMACS, otherwise dies. Intended as a replacement for function
elisp-need-emacs, which did only a simple numeric comparison of the
major version.

Call the new function before doing any actual work in elisp-compile()
and elisp-make-autoload-file(), so ebuilds inheriting only
elisp-common.eclass (but not elisp.eclass) won't have to add a
pkg_setup phase function.

Drop support for EAPIs 0 to 3.

Signed-off-by: Ulrich Müller <ulm@gentoo.org>
---
v2: Don't change elisp-need-emacs() in place, but add a new function
    for the new functionality, and and deprecate the old function.

 eclass/elisp-common.eclass | 52 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/eclass/elisp-common.eclass b/eclass/elisp-common.eclass
index 05b03f49395..8e5d70046bc 100644
--- a/eclass/elisp-common.eclass
+++ b/eclass/elisp-common.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2015 Gentoo Foundation
+# Copyright 1999-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: elisp-common.eclass
@@ -156,6 +156,12 @@
 # environment, so it is no problem when you unset USE=emacs between
 # merge and unmerge of a package.
 
+case ${EAPI:-0} in
+	4|5|6) inherit eapi7-ver ;;
+	7) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
 # @ECLASS-VARIABLE: SITELISP
 # @DESCRIPTION:
 # Directory where packages install Emacs Lisp files.
@@ -182,6 +188,17 @@ EMACSFLAGS="-batch -q --no-site-file"
 # Emacs flags used for byte-compilation in elisp-compile().
 BYTECOMPFLAGS="-L ."
 
+# @ECLASS-VARIABLE: NEED_EMACS
+# @DESCRIPTION:
+# The minimum Emacs version required for the package.
+: ${NEED_EMACS:=23.1}
+
+# @ECLASS-VARIABLE: _ELISP_EMACS_VERSION
+# @INTERNAL
+# @DESCRIPTION:
+# Cached value of Emacs version detected in elisp-check-emacs-version().
+_ELISP_EMACS_VERSION=""
+
 # @FUNCTION: elisp-emacs-version
 # @RETURN: exit status of Emacs
 # @DESCRIPTION:
@@ -212,6 +229,35 @@ elisp-emacs-version() {
 	echo "${version}"
 }
 
+# @FUNCTION: elisp-check-emacs-version
+# @USAGE: [version]
+# @DESCRIPTION:
+# Test if the eselected Emacs version is at least the version of
+# GNU Emacs specified in the NEED_EMACS variable, or die otherwise.
+
+elisp-check-emacs-version() {
+	if [[ -z ${_ELISP_EMACS_VERSION} ]]; then
+		local have_emacs
+		have_emacs=$(elisp-emacs-version) \
+			|| die "Could not determine Emacs version"
+		elog "Emacs version: ${have_emacs}"
+		if [[ ${have_emacs} =~ XEmacs|Lucid ]]; then
+			die "XEmacs detected. This package needs GNU Emacs."
+		fi
+		# GNU Emacs versions have only numeric components.
+		if ! [[ ${have_emacs} =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
+			die "Malformed version string: ${have_emacs}"
+		fi
+		_ELISP_EMACS_VERSION=${have_emacs}
+	fi
+
+	if ! ver_test "${_ELISP_EMACS_VERSION}" -ge "${NEED_EMACS}"; then
+		eerror "This package needs at least Emacs ${NEED_EMACS}."
+		eerror "Use \"eselect emacs\" to select the active version."
+		die "Emacs version too low"
+	fi
+}
+
 # @FUNCTION: elisp-need-emacs
 # @USAGE: <version>
 # @RETURN: 0 if true, 1 if false, 2 if trouble
@@ -249,6 +295,8 @@ elisp-need-emacs() {
 # in case they require or load one another.
 
 elisp-compile() {
+	elisp-check-emacs-version
+
 	ebegin "Compiling GNU Emacs Elisp files"
 	${EMACS} ${EMACSFLAGS} ${BYTECOMPFLAGS} -f batch-byte-compile "$@"
 	eend $? "elisp-compile: batch-byte-compile failed" || die
@@ -262,6 +310,8 @@ elisp-compile() {
 elisp-make-autoload-file() {
 	local f="${1:-${PN}-autoloads.el}" null="" page=$'\f'
 	shift
+	elisp-check-emacs-version
+
 	ebegin "Generating autoload file for GNU Emacs"
 
 	cat >"${f}" <<-EOF
-- 
2.24.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  parent reply	other threads:[~2019-12-20 13:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 11:08 [gentoo-dev] [PATCH 0/3] elisp{,-common}.eclass update for emacs-vcs consolidation Ulrich Müller
2019-12-18 11:08 ` [gentoo-dev] [PATCH 1/3] elisp-common.eclass: Allow full versions in elisp-need-emacs() Ulrich Müller
2019-12-18 11:08 ` [gentoo-dev] [PATCH 2/3] elisp-common.eclass: Update documentation Ulrich Müller
2019-12-18 11:08 ` [gentoo-dev] [PATCH 3/3] elisp.eclass: Depend on app-editors/emacs directly Ulrich Müller
2019-12-18 11:47 ` [gentoo-dev] [PATCH 0/3] elisp{,-common}.eclass update for emacs-vcs consolidation Michał Górny
2019-12-18 12:01   ` Ulrich Mueller
2019-12-18 12:19 ` Michael Orlitzky
2019-12-18 16:34   ` Ulrich Mueller
2019-12-18 23:28     ` Michael Orlitzky
2019-12-20  1:19       ` Michael Orlitzky
2019-12-21  6:57         ` Ulrich Mueller
2019-12-21 11:27           ` Michael Orlitzky
2019-12-21 11:39             ` Ulrich Mueller
2019-12-21 11:41               ` Michael Orlitzky
2019-12-21 11:50                 ` Ulrich Mueller
2019-12-21 11:49               ` Michael Orlitzky
2019-12-21 11:52                 ` Ulrich Mueller
2019-12-21 13:31                   ` Michael 'veremitz' Everitt
2019-12-20 13:43 ` Ulrich Müller [this message]
2019-12-20 13:43 ` [gentoo-dev] [PATCH v2 2/3] elisp-common.eclass: Update documentation Ulrich Müller
2019-12-20 13:44 ` [gentoo-dev] [PATCH v2 3/3] elisp.eclass: Depend on app-editors/emacs directly Ulrich Müller
2019-12-20 22:10   ` Ulrich Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=w6go8w3nmcu.fsf@kph.uni-mainz.de \
    --to=ulm@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox