summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'eclass/elisp-common.eclass')
-rw-r--r--eclass/elisp-common.eclass364
1 files changed, 308 insertions, 56 deletions
diff --git a/eclass/elisp-common.eclass b/eclass/elisp-common.eclass
index 66a3a325e673..3d99838a0221 100644
--- a/eclass/elisp-common.eclass
+++ b/eclass/elisp-common.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2020 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: elisp-common.eclass
@@ -10,6 +10,8 @@
# Mamoru Komachi <usata@gentoo.org>
# Christian Faulhammer <fauli@gentoo.org>
# Ulrich Müller <ulm@gentoo.org>
+# Maciej Barć <xgqt@gentoo.org>
+# @SUPPORTED_EAPIS: 7 8
# @BLURB: Emacs-related installation utilities
# @DESCRIPTION:
#
@@ -23,7 +25,7 @@
# When relying on the emacs USE flag, you need to add
#
# @CODE
-# emacs? ( >=app-editors/emacs-23.1:* )
+# emacs? ( >=app-editors/emacs-25.3:* )
# @CODE
#
# to your DEPEND/RDEPEND line and use the functions provided here to
@@ -130,6 +132,17 @@
# "50${PN}-gentoo.el". If your subdirectory is not named ${PN}, give
# the differing name as second argument.
#
+# For the simple case that only the package's subdirectory needs to be
+# added to the load-path, function elisp-make-site-file() will create
+# and install a site-init file that does just that:
+#
+# @CODE
+# elisp-make-site-file "${SITEFILE}"
+# @CODE
+#
+# Again, this must be called in src_install(). See the function's
+# documentation for more details on its usage.
+#
# @SUBSECTION pkg_setup() usage:
#
# If your ebuild uses the elisp-compile eclass function to compile
@@ -164,50 +177,49 @@
# Again, with optional Emacs support, you should prepend "use emacs &&"
# to above calls of elisp-site-regen().
-case ${EAPI:-0} in
- 4|5|6) inherit eapi7-ver ;;
- 7) ;;
+case ${EAPI} in
+ 7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-# @ECLASS-VARIABLE: SITELISP
+# @ECLASS_VARIABLE: SITELISP
# @DESCRIPTION:
# Directory where packages install Emacs Lisp files.
SITELISP=/usr/share/emacs/site-lisp
-# @ECLASS-VARIABLE: SITEETC
+# @ECLASS_VARIABLE: SITEETC
# @DESCRIPTION:
# Directory where packages install miscellaneous (not Lisp) files.
SITEETC=/usr/share/emacs/etc
-# @ECLASS-VARIABLE: EMACSMODULES
+# @ECLASS_VARIABLE: EMACSMODULES
# @DESCRIPTION:
# Directory where packages install dynamically loaded modules.
# May contain a @libdir@ token which will be replaced by $(get_libdir).
EMACSMODULES=/usr/@libdir@/emacs/modules
-# @ECLASS-VARIABLE: EMACS
+# @ECLASS_VARIABLE: EMACS
# @DESCRIPTION:
# Path of Emacs executable.
EMACS=${EPREFIX}/usr/bin/emacs
-# @ECLASS-VARIABLE: EMACSFLAGS
+# @ECLASS_VARIABLE: EMACSFLAGS
# @DESCRIPTION:
# Flags for executing Emacs in batch mode.
# These work for Emacs versions 18-24, so don't change them.
EMACSFLAGS="-batch -q --no-site-file"
-# @ECLASS-VARIABLE: BYTECOMPFLAGS
+# @ECLASS_VARIABLE: BYTECOMPFLAGS
# @DESCRIPTION:
# Emacs flags used for byte-compilation in elisp-compile().
BYTECOMPFLAGS="-L ."
-# @ECLASS-VARIABLE: NEED_EMACS
+# @ECLASS_VARIABLE: NEED_EMACS
# @DESCRIPTION:
# The minimum Emacs version required for the package.
-: ${NEED_EMACS:=23.1}
+: "${NEED_EMACS:=25.3}"
-# @ECLASS-VARIABLE: _ELISP_EMACS_VERSION
+# @ECLASS_VARIABLE: _ELISP_EMACS_VERSION
# @INTERNAL
# @DESCRIPTION:
# Cached value of Emacs version detected in elisp-check-emacs-version().
@@ -219,7 +231,9 @@ _ELISP_EMACS_VERSION=""
# Output version of currently active Emacs.
elisp-emacs-version() {
- local version ret
+ local version ret tmout="timeout -k 5 55"
+ # Run without timeout if the command is not available
+ ${tmout} true &>/dev/null || tmout=""
# The following will work for at least versions 18-24.
echo "(princ emacs-version)" >"${T}"/emacs-version.el
version=$(
@@ -228,12 +242,14 @@ elisp-emacs-version() {
# Redirecting stdin and unsetting TERM and DISPLAY will cause
# most of them to exit with an error.
unset TERM DISPLAY
- ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el </dev/null
+ ${tmout} ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el </dev/null
)
ret=$?
rm -f "${T}"/emacs-version.el
if [[ ${ret} -ne 0 ]]; then
eerror "elisp-emacs-version: Failed to run ${EMACS}"
+ [[ $(realpath ${EMACS} 2>/dev/null) == */emacs* ]] \
+ || eerror "This package needs GNU Emacs"
return ${ret}
fi
if [[ -z ${version} ]]; then
@@ -272,27 +288,6 @@ elisp-check-emacs-version() {
fi
}
-# Test if the eselected Emacs version is at least the major version
-# of GNU Emacs specified as argument.
-# Return 0 if true, 1 if false, 2 if trouble.
-# Deprecated, use elisp-check-emacs-version instead.
-
-elisp-need-emacs() {
- local need_emacs=$1 have_emacs
- have_emacs=$(elisp-emacs-version) || return 2
- einfo "Emacs version: ${have_emacs}"
- if [[ ${have_emacs} =~ XEmacs|Lucid ]]; then
- eerror "This package needs GNU Emacs."
- return 1
- fi
- if ! [[ ${have_emacs%%.*} -ge ${need_emacs%%.*} ]]; then
- eerror "This package needs at least Emacs ${need_emacs%%.*}."
- eerror "Use \"eselect emacs\" to select the active version."
- return 1
- fi
- return 0
-}
-
# @FUNCTION: elisp-compile
# @USAGE: <list of elisp files>
# @DESCRIPTION:
@@ -338,6 +333,7 @@ elisp-make-autoload-file() {
;; Local ${null}Variables:
;; version-control: never
;; no-byte-compile: t
+ ;; no-native-compile: t
;; no-update-autoloads: t
;; End:
@@ -345,6 +341,7 @@ elisp-make-autoload-file() {
EOF
${EMACS} ${EMACSFLAGS} \
+ --eval "(require 'autoload)" \
--eval "(setq make-backup-files nil)" \
--eval "(setq generated-autoload-file (expand-file-name \"${f}\"))" \
-f batch-update-autoloads "${@-.}"
@@ -352,6 +349,242 @@ elisp-make-autoload-file() {
eend $? "elisp-make-autoload-file: batch-update-autoloads failed" || die
}
+# @FUNCTION: elisp-org-export-to
+# @USAGE: <export file type> <Org file path>
+# @DESCRIPTION:
+# Use Emacs Org "export-to" functions to convert a given Org file to a
+# picked format.
+#
+# Example:
+# @CODE
+# elisp-org-export-to texinfo README.org
+# mv README.texi ${PN}.texi || die
+# @CODE
+
+elisp-org-export-to() {
+ local export_format="${1}"
+ local org_file_path="${2}"
+
+ local export_group
+ case ${export_format} in
+ info) export_group=texinfo ;; # Straight to ".info".
+ markdown) export_group=md ;;
+ pdf) export_group=latex ;;
+ *) export_group=${export_format} ;;
+ esac
+
+ # export_format = texinfo => org-texinfo-export-to-texinfo
+ # export_format = pdf => org-latex-export-to-pdf
+
+ local export_function=org-${export_group}-export-to-${export_format}
+
+ ${EMACS} ${EMACSFLAGS} "${org_file_path}" -f "${export_function}" \
+ || die "Org export to ${export_format} failed"
+}
+
+# @FUNCTION: elisp-test-buttercup
+# @USAGE: [test-subdirectory] [test-runner-opts] ...
+# @DESCRIPTION:
+# Run ELisp package tests using the "buttercup" test runner.
+#
+# The option "test-subdirectory" may be given any number of times,
+# it should be given as though it was passed to Emacs or the test tool,
+# not as a string.
+#
+# The options "test-subdirectory" and "test-runner-opts" are optional,
+# but if "test-runner-opts" needs to be provided also "test-subdirectory"
+# has to be specified.
+
+elisp-test-buttercup() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ local test_dir="${1:-$(pwd)}"
+ shift
+
+ local -a myopts=(
+ ${BYTECOMPFLAGS}
+ -L "${test_dir}"
+ --traceback full
+ "$@"
+ )
+ ebegin "Running buttercup tests"
+ buttercup "${myopts[@]}" "${test_dir}"
+ eend $? "${FUNCNAME}: tests failed" || die
+}
+
+# @FUNCTION: elisp-test-ert-runner
+# @USAGE: [test-subdirectory] [test-runner-opts] ...
+# @DESCRIPTION:
+# Run ELisp package tests using the "ert-runner" test runner.
+#
+# The option "test-subdirectory" may be given any number of times,
+# it should be given as though it was passed to Emacs or the test tool,
+# not as a string.
+#
+# The options "test-subdirectory" and "test-runner-opts" are optional,
+# but if "test-runner-opts" needs to be provided also "test-subdirectory"
+# has to be specified.
+
+elisp-test-ert-runner() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ local test_dir="${1:-$(pwd)}"
+ shift
+
+ local -a myopts=(
+ ${BYTECOMPFLAGS}
+ --reporter ert+duration
+ --script
+ -L "${test_dir}"
+ "$@"
+ )
+ ebegin "Running ert-runner tests"
+ ert-runner "${myopts[@]}" "${test_dir}"
+ eend $? "${FUNCNAME}: tests failed" || die
+}
+
+# @FUNCTION: elisp-test-ert
+# @USAGE: [test-subdirectory] [test-runner-opts] ...
+# @DESCRIPTION:
+# Run ELisp package tests using "ert", the Emacs's built-in test runner.
+#
+# The option "test-subdirectory" may be given any number of times,
+# it should be given as though it was passed to Emacs or the test tool,
+# not as a string.
+#
+# The options "test-subdirectory" and "test-runner-opts" are optional,
+# but if "test-runner-opts" needs to be provided also "test-subdirectory"
+# has to be specified.
+
+elisp-test-ert() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ local test_dir="${1:-$(pwd)}"
+ shift
+
+ local -a extra_load=()
+ local extra_load_file
+ for extra_load_file in "${test_dir}"/?*-test.el; do
+ if [[ -f "${extra_load_file}" ]]; then
+ extra_load+=( -l "${extra_load_file}" )
+ fi
+ done
+
+ local -a myopts=(
+ ${EMACSFLAGS}
+ ${BYTECOMPFLAGS}
+ -L "${test_dir}"
+ "${extra_load[@]}"
+ "$@"
+ -f ert-run-tests-batch-and-exit
+ )
+ ebegin "Running ert tests"
+ ${EMACS} "${myopts[@]}"
+ eend $? "${FUNCNAME}: tests failed" || die
+}
+
+# @FUNCTION: elisp-enable-tests
+# @USAGE: [--optional] <test-runner> [test-runner-options] ...
+# @DESCRIPTION:
+# Set up IUSE, RESTRICT, BDEPEND and test runner function for running
+# tests with the specified test runner.
+#
+# The test-runner argument must be one of:
+#
+# - buttercup: for "buttercup" provided via "app-emacs/buttercup"
+#
+# - ert-runner: for "ert-runner" provided via "app-emacs/ert-runner"
+#
+# - ert: for built-in GNU Emacs test utility
+#
+# If the "--optional" flag is passed (before specifying the test
+# runner), then it is assumed that the ELisp package is a part of some
+# some project that optionally enables GNU Emacs support. This will
+# correctly set up the test and Emacs dependencies.
+#
+# Notice that the first option passed to the "test-runner" is the
+# directory and the rest are miscellaneous options applicable to that
+# given runner.
+#
+# This function has to be called post inherit, specifically after
+# "IUSE", "RESTRICT" and "BDEPEND" variables are assigned.
+# It is advised to place this call right before (re)defining a given
+# ebuild's phases.
+#
+# Example:
+# @CODE
+# inherit elisp-common
+#
+# ...
+#
+# elisp-enable-tests --optional ert-runner "${S}"/elisp -t "!org"
+#
+# src_test() {
+# emake -C tests test
+# elisp-test
+# }
+# @CODE
+
+elisp-enable-tests() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ local optional
+ if [[ ${1} = "--optional" ]] ; then
+ optional=YES
+ shift
+ fi
+
+ local test_pkg
+ local test_runner=${1}
+ shift
+
+ _ELISP_TEST_OPTS=( "$@" )
+
+ case ${test_runner} in
+ buttercup )
+ test_pkg="app-emacs/buttercup"
+ _ELISP_TEST_FUNCTION=elisp-test-buttercup
+ ;;
+ ert-runner )
+ test_pkg="app-emacs/ert-runner"
+ _ELISP_TEST_FUNCTION=elisp-test-ert-runner
+ ;;
+ ert )
+ _ELISP_TEST_FUNCTION=elisp-test-ert
+ ;;
+ * )
+ die "${FUNCNAME}: unknown test runner, given ${test_runner}"
+ ;;
+ esac
+
+ if [[ ${test_pkg} ]]; then
+ IUSE+=" test "
+ RESTRICT+=" !test? ( test ) "
+ if [[ ${optional} ]]; then
+ IUSE+=" emacs "
+ BDEPEND+=" test? ( emacs? ( ${test_pkg} ) ) "
+ else
+ BDEPEND+=" test? ( ${test_pkg} ) "
+ fi
+ fi
+
+ return 0
+}
+
+# @FUNCTION: elisp-test
+# @DESCRIPTION:
+# Test the package using a ELisp test runner.
+#
+# If called without executing "elisp-enable-tests" beforehand, then
+# does nothing, otherwise a test runner is called with given
+# "test-runner-options".
+
+elisp-test() {
+ if [[ ${_ELISP_TEST_FUNCTION} ]]; then
+ ${_ELISP_TEST_FUNCTION} "${_ELISP_TEST_OPTS[@]}"
+ fi
+}
+
# @FUNCTION: elisp-install
# @USAGE: <subdirectory> <list of files>
# @DESCRIPTION:
@@ -376,10 +609,6 @@ elisp-install() {
elisp-modules-install() {
local subdir="$1"
shift
- # Don't bother inheriting multilib.eclass for get_libdir(), but
- # error out in old EAPIs that don't support it natively.
- [[ ${EAPI} == [45] ]] \
- && die "${ECLASS}: Dynamic modules not supported in EAPI ${EAPI}"
ebegin "Installing dynamic modules for GNU Emacs support"
( # subshell to avoid pollution of calling environment
exeinto "${EMACSMODULES//@libdir@/$(get_libdir)}/${subdir}"
@@ -399,21 +628,22 @@ elisp-modules-install() {
elisp-site-file-install() {
local sf="${1##*/}" my_pn="${2:-${PN}}" modules ret
- local header=";;; ${PN} site-lisp configuration"
+ local add_header="1 {
+ # Find first non-empty line
+ :x; /^\$/ { n; bx; }
+ # Insert a header, unless we already look at one
+ /^;.*${PN}/I! s/^/;;; ${PN} site-lisp configuration\n\n/
+ 1 s/^/\n/
+ }"
[[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \
|| ewarn "elisp-site-file-install: bad name of site-init file"
[[ ${sf%-gentoo*.el} != "${sf}" ]] && sf="${sf%-gentoo*.el}-gentoo.el"
sf="${T}/${sf}"
ebegin "Installing site initialisation file for GNU Emacs"
- [[ $1 = "${sf}" ]] || cp "$1" "${sf}"
- if [[ ${EAPI} == [45] ]]; then
- grep -q "@EMACSMODULES@" "${sf}" \
- && die "${ECLASS}: Dynamic modules not supported in EAPI ${EAPI}"
- else
- modules=${EMACSMODULES//@libdir@/$(get_libdir)}
- fi
- sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \
+ [[ $1 == "${sf}" ]] || cp "$1" "${sf}"
+ modules=${EMACSMODULES//@libdir@/$(get_libdir)}
+ sed -i -e "${add_header}" \
-e "s:@SITELISP@:${EPREFIX}${SITELISP}/${my_pn}:g" \
-e "s:@SITEETC@:${EPREFIX}${SITEETC}/${my_pn}:g" \
-e "s:@EMACSMODULES@:${EPREFIX}${modules}/${my_pn}:g;\$q" "${sf}"
@@ -426,6 +656,30 @@ elisp-site-file-install() {
eend ${ret} "elisp-site-file-install: doins failed" || die
}
+# @FUNCTION: elisp-make-site-file
+# @USAGE: <filename> [subdirectory] [line]...
+# @DESCRIPTION:
+# Create and install a site-init file for the package. By default,
+# this will add the package's SITELISP subdirectory to Emacs' load-path:
+#
+# @CODE
+# (add-to-list 'load-path "@SITELISP@")
+# @CODE
+#
+# Additional arguments are appended as lines to the destination file.
+# Any @SITELISP@, @SITEETC@, and @EMACSMODULES@ tokens in these
+# arguments are replaced, as described for elisp-site-file-install.
+
+elisp-make-site-file() {
+ [[ $1 == [0-9][0-9]*-gentoo.el ]] \
+ || die "elisp-make-site-file: bad name of site-init file"
+
+ local f="${T}/$1" my_pn="${2:-${PN}}"
+ shift; shift
+ printf "%s\n" "(add-to-list 'load-path \"@SITELISP@\")" "$@" >"${f}" || die
+ elisp-site-file-install "${f}" "${my_pn}"
+}
+
# @FUNCTION: elisp-site-regen
# @DESCRIPTION:
# Regenerate the site-gentoo.el file, based on packages' site
@@ -433,11 +687,11 @@ elisp-site-file-install() {
# directory.
elisp-site-regen() {
- local sitelisp=${ROOT%/}${EPREFIX}${SITELISP}
+ local sitelisp=${EROOT}${SITELISP}
local sf i ret=0 null="" page=$'\f'
local -a sflist
- if [[ ${EBUILD_PHASE} = *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then
+ if [[ ${EBUILD_PHASE} == *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then
ewarn "Refusing to create site-gentoo.el in ${EBUILD_PHASE} phase."
return 0
fi
@@ -445,9 +699,6 @@ elisp-site-regen() {
[[ -d ${sitelisp} ]] \
|| die "elisp-site-regen: Directory ${sitelisp} does not exist"
- [[ -d ${T} ]] \
- || die "elisp-site-regen: Temporary directory ${T} does not exist"
-
ebegin "Regenerating site-gentoo.el for GNU Emacs (${EBUILD_PHASE})"
for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el; do
@@ -472,6 +723,7 @@ elisp-site-regen() {
;; Local ${null}Variables:
;; no-byte-compile: t
+ ;; no-native-compile: t
;; buffer-read-only: t
;; End:
@@ -492,7 +744,7 @@ elisp-site-regen() {
mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
eend $? "elisp-site-regen: Replacing site-gentoo.el failed" || die
case ${#sflist[@]} in
- 0) [[ ${PN} = emacs-common-gentoo ]] \
+ 0) [[ ${PN} == emacs-common ]] \
|| ewarn "... Huh? No site initialisation files found." ;;
1) einfo "... ${#sflist[@]} site initialisation file included." ;;
*) einfo "... ${#sflist[@]} site initialisation files included." ;;